diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-22 14:14:39 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-22 15:36:59 -0300 |
| commit | b0e96978b619e1111ee2fb30e3c4a48f9fac38b3 (patch) | |
| tree | da0c3c266b52c84ab6d96f1652f17b80effab342 /test/process | |
| parent | 85e793ae92683808d14433cb7c99ccdab4c967dc (diff) | |
| download | pardes-b0e96978b619e1111ee2fb30e3c4a48f9fac38b3.tar.gz pardes-b0e96978b619e1111ee2fb30e3c4a48f9fac38b3.zip | |
pty: a shell forks at its pane's grid, and the core hands its host every pty's size, pixels too (pardes-term-join-9, item 2 (B), points (a) and (c)): the spawn host call took no size and both hosts forked at the session's live screen (dev/Ptys.zig `spawn`, runtime/macos.zig `spawnShell`: `core.view().screen_h/w`), so a shell started again into a pane already sized (pty/ctl's exec, a finished command pane run again by exec.zig `runCommand`, a Restore's `revivePane`) ran at the screen's size and nothing resized it, the grid unchanged and `sync` emitting nothing (`stty size` said 50 160 in a 44x158 pane); and a pty's pixels were the live view's (host_io.zig `ptyWinsize` read `core.view().cell_pixels`) whichever view sized it; now `Effect.PtySize` (cells and pixels) is what the core gives its host for `spawn` and `pty_resize`, made by `Core.ptySize` from the pane's grid (or 9P's numbers) at the cell of the view that sizes it, a spawn performed after its step's `sync` reading the laid-out grid, and the hosts fork and size from it alone (`Ptys.take` sizes an adopted shell from it too: 1x1 then the size, once, its forced redraw kept, an ioctl to the size a pty has already sending no SIGWINCH); test (test/process/terminals.zig, a new case): a Term pane's shell, the same shell started again by pty/ctl's exec and a finished command pane run again each say the grid their pty/ctl reads back (fails on the base: 50 160 against 44 158); not covered: a new command pane made over 9P is placed a step after its fork, so its first size can still be the screen's
Co-Authored-By: Claude Opus <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
Diffstat (limited to 'test/process')
| -rw-r--r-- | test/process/terminals.zig | 93 |
1 files changed, 93 insertions, 0 deletions
diff --git a/test/process/terminals.zig b/test/process/terminals.zig index d9c3bcca..151b221b 100644 --- a/test/process/terminals.zig +++ b/test/process/terminals.zig @@ -16,6 +16,7 @@ pub const cases = .{ .{ "terminals: a program's prompt shows and holds still, input sent unsubmitted shows, and ^U takes the screen back to what it was", prompt }, .{ "terminals: what a program prints past a screenful stays in the terminal's body, and its prompt after it shows", history }, .{ "terminals: a control byte through pty/data reaches a program in raw mode, which then carries on", rawKey }, + .{ "terminals: a shell started into a pane runs at the pane's grid, not the screen's: a new terminal, its shell started again by pty/ctl's exec, a finished command pane run again", sizedFork }, }; fn has(hay: []const u8, needle: []const u8) bool { @@ -78,6 +79,98 @@ const Other = struct { } }; +/// What `stty size` in terminal `term` says, beside the grid its pty/ctl +/// reads back, each as "rows cols". +fn sttySize(a: std.mem.Allocator, c: *process.Conn, term: u32) ![2][]const u8 { + var lines = std.mem.splitScalar(u8, try run(a, c, term, "stty size\n"), '\n'); + _ = lines.next(); + return .{ lines.next() orelse "", try grid(a, c, term) }; +} + +/// Pane `n`'s grid, as pty/ctl reads it back ("winsize C R"): "rows cols". +fn grid(a: std.mem.Allocator, c: *process.Conn, n: u32) ![]const u8 { + var w = std.mem.tokenizeAny(u8, try c.read(a, try std.fmt.allocPrint(a, "/pane/{d}/pty/ctl", .{n})), " \n"); + _ = w.next(); + const cols = w.next() orelse ""; + return std.fmt.allocPrint(a, "{s} {s}", .{ w.next() orelse "", cols }); +} + +/// The lines of pane `n`'s body that are two numbers (`stty size`'s). +fn sizeLines(a: std.mem.Allocator, c: *process.Conn, n: u32) ![]const []const u8 { + var out: std.ArrayList([]const u8) = .empty; + var rows = std.mem.tokenizeScalar(u8, try c.read(a, try std.fmt.allocPrint(a, "/pane/{d}/body", .{n})), '\n'); + while (rows.next()) |row| { + var w = std.mem.tokenizeScalar(u8, std.mem.trim(u8, row, " \r"), ' '); + const r = w.next() orelse continue; + const k = w.next() orelse continue; + if (w.next() != null) continue; + _ = std.fmt.parseInt(u16, r, 10) catch continue; + _ = std.fmt.parseInt(u16, k, 10) catch continue; + try out.append(a, try std.fmt.allocPrint(a, "{s} {s}", .{ r, k })); + } + return out.items; +} + +/// A shell takes runs: its first prompt, or the one started again. +fn prompted(a: std.mem.Allocator, c: *process.Conn, term: u32) !void { + const deadline = eh.nowMs() + 10_000; + while (!std.mem.eql(u8, try run(a, c, term, "true\n"), "exit 0\n")) { + if (eh.nowMs() > deadline) return error.NoPrompt; + process.sleep(50); + } +} + +fn sizedFork(gpa: std.mem.Allocator, exe: [:0]const u8) !void { + var d = try process.Detached.start(gpa, exe, "sized", .{}); + defer d.deinit(); + const f = &d.files; + var arena = std.heap.ArenaAllocator.init(gpa); + defer arena.deinit(); + const a = arena.allocator(); + const c = try process.Conn.dial(gpa, d.socket()); + defer c.deinit(gpa); + const text = (try serials(a, c))[0]; + try c.write("/exec", "Shell bash\n"); + // A terminal beside the text: its grid is its rect less the tag, never + // the screen's 160x50. + try c.write("/exec", "Term\n"); + const term = try c.newest(gpa); + try prompted(a, c, term); + var got = try sttySize(a, c, term); + try expect(!std.mem.eql(u8, got[1], "50 160")); + try expectEqualStrings(got[1], got[0]); + // Its shell started again: the pane is sized already, and nothing + // resizes it after. + const pid = try run(a, c, term, "echo $$\n"); + try c.write(f.at("/pane/{d}/pty/ctl", .{term}), "exec\n"); + const again_by = eh.nowMs() + 10_000; + while (true) { + const now = run(a, c, term, "echo $$\n") catch ""; + if (std.mem.startsWith(u8, now, "exit 0\n") and !std.mem.eql(u8, now, pid)) break; + if (eh.nowMs() > again_by) return error.NeverStartedAgain; + process.sleep(50); + } + got = try sttySize(a, c, term); + try expectEqualStrings(got[1], got[0]); + // A command pane, then the same line again: the finished pane is run + // again (exec.zig `runCommand`), a pane sized already. (The new one is + // placed a step after its fork: its first size can be the screen's.) + try c.exec(text, "stty size"); + var words = std.mem.tokenizeAny(u8, try c.pane(a, text, "exec"), " \n"); + var last: []const u8 = ""; + while (words.next()) |w| last = w; + const cmd = try std.fmt.parseInt(u32, last, 10); + for (1..3) |k| { + if (k == 2) try c.exec(text, "stty size"); + const by = eh.nowMs() + 10_000; + while ((try sizeLines(a, c, cmd)).len < k) { + if (eh.nowMs() > by) return error.NoSize; + process.sleep(50); + } + if (k == 2) try expectEqualStrings(try grid(a, c, cmd), (try sizeLines(a, c, cmd))[1]); + } +} + fn runFile(gpa: std.mem.Allocator, exe: [:0]const u8) !void { var d = try process.Detached.start(gpa, exe, "run", .{}); defer d.deinit(); |
