From fac51df2abec19e57932e0fbe4492d372d7daac2 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Wed, 4 Nov 2026 21:23:04 -0300 Subject: pty/run: a run waiting for a new terminal's first prompt is the only line typed there: the Term's greeting ls is dropped when the run's line goes (pty.zig noteMarks), as on the window (resized, so it greets) both were typed at that prompt and ls's C, read with true's in one chunk, left the run waiting for ever (4 runs of 6); the window's process sessions run on a 160x50 pty (Child.Pty's cols and rows), as a test window follows its terminal's size and the 80x24 one made the canary's Newcol find no room; terminals' pty/run case and the canary run on both backends (10 of 10 each on the window), their next-tests Open bullets gone; a pty.zig unit test that fails without the fix (truels) Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge --- src/ninep/pty.zig | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'src/ninep') diff --git a/src/ninep/pty.zig b/src/ninep/pty.zig index 5c9a6289..5a974adf 100644 --- a/src/ninep/pty.zig +++ b/src/ninep/pty.zig @@ -324,6 +324,9 @@ pub fn noteMarks(p: *Pardes, id: usize, pane: *Pane) void { p.emitWrite(id, slot.line); p.emitWrite(id, "\r"); pardes.panes.terminal.noteCommand(pane, slot.line); + // The run is the shell's first command: a greeting `ls` typed at the + // same prompt would run after it, and its C would be taken for ours. + pane.greet = false; slot.phase = .sent; return; } @@ -768,6 +771,27 @@ test "pty/data writes at the shell and reads the raw stream" { try testing.expectEqualStrings("still", rd(p, data, 0, 64).bytes); } +test "a run waiting for a new terminal's first prompt is the only line typed there, no greeting after it" { + const gpa = testing.allocator; + const p = try withTerm(gpa); + defer p.deinit(); + p.panes[0].?.greet = true; // a Term's, in a window (resized) + p.update(.{ .resize = .{ .cols = 80, .rows = 24 } }); + while (p.nextEffect()) |_| {} + const node = Node.of(serialOf(p), .pty_run); + const h = call(p, .{ .tag = 1, .op = .open, .node = node }).reply.handle; + _ = call(p, .{ .tag = 2, .op = .write, .node = node, .handle = h, .data = "true\n" }); + p.update(.{ .output = .{ .pane = 0, .bytes = "\x1b]133;A;cl=line;aid=pardes\x07$ \x1b]133;B;aid=pardes\x07" } }); + var sent: [32]u8 = undefined; + var len: usize = 0; + while (p.nextEffect()) |e| if (e == .write) { + const b = e.write.bytes.slice(); + @memcpy(sent[len..][0..b.len], b); + len += b.len; + }; + try testing.expectEqualStrings("true\r", sent[0..len]); +} + test "run answers how its command ended once the shell is back at a prompt" { const gpa = testing.allocator; const p = try withTerm(gpa); -- cgit v1.3