diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-23 05:59:04 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-23 10:58:26 -0300 |
| commit | 9a648ef09bb32f42fb6b09bebbe8c851be360c6e (patch) | |
| tree | efd97aa0549add3d06f598f67483dd5d98155b31 /core | |
| parent | 4faf94b72b60ecb0656e7e90ca693b63b1fde71c (diff) | |
| download | pardes-9a648ef09bb32f42fb6b09bebbe8c851be360c6e.tar.gz pardes-9a648ef09bb32f42fb6b09bebbe8c851be360c6e.zip | |
pty/run at a terminal's start answers the line it ran: a window session's first run (test/daemon.py `gui_upgrades`' `echo $$`, twice this week a ValueError on its second line, `b''`) answered `error not run` while its command ran, and a run written just after a new terminal's greeting is typed answered `exit 0` with the greeting's `ls` output; (a) every window session's first terminal is sized twice, its shell forked at 78x14 and sized 78x13 by the window's first frame about 20 ms later, at its first prompt, where readline draws the prompt again (`\r\e[K\r` and PS1, marks and all): a run's line sent into the first prompt shows on the redrawn one, `noteMarks` takes that newer prompt with no C for the line fish refuses and keeps (Ctrl-U, `.kept_line`), and the read after it, the line's newline before PS0's C (bash writes them apart), leaves the cursor on a fresh row in the input which `prompt()` called an empty prompt: `error not run`, the command's C a read later (the ponytail at pty.zig's refused branch named it; the same under an adoption's two sizes, which test/daemon.py `adopted_pid` waited around since ymvuluxr, then ruled a run "told plainly that it did not run": it had run); now a row begun by a newline in the input, with no prompt on it, under a typed line, is not an empty prompt (core/term/terminal.zig `prompt()`, abi/term.zig's `input_empty`): the line was taken and the run waits for its C; (b) the greeting `ls\r` is typed at a new terminal's first prompt (Core.zig's layout), and until its echo the prompt looks empty: a run sent then is typed behind it and its want (started+1) is the `ls`'s C; now the pane keeps that its greeting was typed (`Pane.greeted`, cleared at a shell's start) and until the prompt after it a run waits for that prompt (pty.zig `greeting`: writeRun, noteMarks, pty/status's busy), as for the first, bounded since `ls` always starts (the reference says so); the failing tests first (core/ninep/pty.zig, shell-test): "a prompt redrawn under a run's line, the line taken, is the line run: never `error not run`" (the bytes pty/data read off a failing ReleaseSafe window start; on the base `error not run`) and "a run written just after a new terminal's greeting is typed is not answered with the greeting's output" (on the base `exit 0\nnotes.txt\n`); a user could hit both: a script that starts pardes-gui and runs at once in its shell (a retry on `error not run` runs its command twice), and one that opens a Term and runs in it at once (another command's output for its own, exit 0); the rates (.scratch/sketch/reorg/pardes-first-run, 200 runs a row pinned to CPU 6 and to CPUs 6,7, no made load, loads 1.5-10): every one of 24 rows 200/200, the base and this, Debug and ReleaseSafe, a window session and a terminal's, plain and with a WINCH trap in the shell's .bashrc: the fault is rare on its own (2 of 108 diagnostic ReleaseSafe window starts with that trap; the coordinator's checks twice under load), Debug never reaches it (its first frame comes before bash's first prompt), and its adopted twin comes more often: test/daemon.py `--relink` with adopted_pid's wait taken out, the installed build 18 of 20 (two `error not run` on the adopted shell), this tree's ReleaseSafe 20 of 20; the gates (with the harness change after it): tui Debug core-test 924/1090 (166 skipped: the two new tests need a terminal), shell-test 1132/1135 (3 skipped), process-test 0 of 146 (loads 3.0-6.2); test/daemon.py on ReleaseSafe: plain 1/1, `--upgrade` from the installed build (wire 31) 1/1, `--upgrade --gui` from the installed build 5/5 (loads 1.1-5.8); left: the Ctrl-U a redraw that shows the line still sends (it reaches bash after the line's Enter: a bell at the next prompt), `busy` for a run written into a prompt being drawn (its A read, its B not yet), and a line a user types, or `Term CMD`'s queued line, in the instant before its echo
Co-Authored-By: Claude Opus <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
Diffstat (limited to 'core')
| -rw-r--r-- | core/Core.zig | 2 | ||||
| -rw-r--r-- | core/ninep/pty.zig | 81 | ||||
| -rw-r--r-- | core/panes.zig | 4 | ||||
| -rw-r--r-- | core/term/terminal.zig | 12 |
4 files changed, 91 insertions, 8 deletions
diff --git a/core/Core.zig b/core/Core.zig index 2c6567ed..f5ed28bd 100644 --- a/core/Core.zig +++ b/core/Core.zig @@ -1070,6 +1070,7 @@ fn acknowledgeShellInner(p: *Pardes, id: Pane.Id, executable: []const u8, prompt if (id.index() < MAX_PANES) if (p.panes[id.index()]) |pane| { ctlfs.pty.shellGone(p, pane, true); // a respawn replaced whatever ran pane.shell_failed = false; + pane.greeted = false; pane.had_shell = true; pane.fs.unmarked = !prompt_marks; // The tag's Term word names the shell the host ran, and a click @@ -2010,6 +2011,7 @@ pub fn sync(p: *Pardes) void { p.emit(.{ .resize_pty = .{ .pane = .at(id), .cols = pane.cols, .rows = pane.rows } }); p.emitWrite(id, "ls\r"); pane.greet = false; + pane.greeted = true; }, }; } diff --git a/core/ninep/pty.zig b/core/ninep/pty.zig index 43973491..2dd7f7f3 100644 --- a/core/ninep/pty.zig +++ b/core/ninep/pty.zig @@ -135,11 +135,12 @@ pub const status_len: u64 = 36; pub fn readStatus(p: *Pardes, req: Req, id: usize, pane: *Pane) Reply { // Busy is what a run written now would be told: a command is running - // or a line is typed at the prompt. Before the shell's first prompt a - // run waits for it rather than answer busy, so that is not busy. + // or a line is typed at the prompt. Before the shell's first prompt, or + // the one after its greeting, a run waits for it rather than answer + // busy, so that is not busy. const marks = pardes.Term.prompt(pane.terminal); const busy = p.hostTtyTaken(id) or (!pane.fs.unmarked and (waitingRun(p, pane) != null or - (marks.prompts > 0 and (marks.phase != .input or !marks.input_empty)))); + (marks.prompts > 0 and !greeting(pane, marks) and (marks.phase != .input or !marks.input_empty)))); const out = p.fs.stage(p.gpa); const size = winsize(pane); out.print(p.gpa, "{d:>11} {d:>11} {d:>11}\n", .{ size[0], size[1], @intFromBool(busy) }) catch return Reply.fail(req.tag, E.NOMEM); @@ -230,8 +231,8 @@ pub fn writeRun(p: *Pardes, req: Req, id: usize, pane: *Pane) Reply { answer(p, slot, "error {s}", .{if (pane.command_done) "command done; not a shell" else "a command runs here, not a shell"}); } else if (pf.unmarked) { answer(p, slot, "error no prompt marks", .{}); - } else if (waitingRun(p, pane) != null or (marks.prompts > 0 and (marks.phase != .input or - !marks.input_empty or p.hostTtyTaken(id)))) + } else if (waitingRun(p, pane) != null or (marks.prompts > 0 and !greeting(pane, marks) and + (marks.phase != .input or !marks.input_empty or p.hostTtyTaken(id)))) { // Something is running or someone has typed at the prompt: sending // now would type into the middle of it. The phase is pardes's own @@ -248,7 +249,8 @@ pub fn writeRun(p: *Pardes, req: Req, id: usize, pane: *Pane) Reply { answer(p, slot, "busy", .{}); } else { // Sent now if the shell is at its prompt, or at its first prompt - // when it has not drawn one yet (noteMarks). + // when it has not drawn one yet, or the one after its greeting + // (noteMarks). slot.line = p.gpa.dupe(u8, line) catch return Reply.fail(req.tag, E.NOMEM); slot.phase = .waiting; pf.run = req.handle; @@ -296,7 +298,7 @@ pub fn noteMarks(p: *Pardes, id: usize, pane: *Pane) void { pf.run = null; return; } - if (marks.phase != .input or !marks.input_empty or p.hostTtyTaken(id)) return; + if (greeting(pane, marks) or marks.phase != .input or !marks.input_empty or p.hostTtyTaken(id)) return; slot.want = marks.started +% 1; slot.prompts = marks.prompts; slot.declined = marks.declined; @@ -361,6 +363,15 @@ pub fn noteMarks(p: *Pardes, id: usize, pane: *Pane) void { finish(p, slot, pane, done.status); } +/// The greeting typed at a new terminal's first prompt (Pane.greeted) is +/// its shell's first command until the prompt after it: its echo not back +/// yet, the prompt looks empty, and a line sent then would be typed behind +/// the `ls`, its start taken for the run's (the run answered with what ls +/// printed). `ls` always starts, so the wait ends. +fn greeting(pane: *const Pane, marks: pardes.Term.Prompt) bool { + return pane.greeted and (marks.started == 0 or (marks.started == 1 and marks.phase != .input)); +} + /// The shell's marks as the session's emulator has them (taped), as a /// run's step reads them: a screen-state replica's emulator is the last /// delta's, which comes at a frame and can be a unit behind the one it @@ -785,6 +796,62 @@ test "a run waiting for a new terminal's first prompt is the only line typed the try testing.expectEqualStrings("true\r", sent[0..len]); } +test "a prompt redrawn under a run's line, the line taken, is the line run: never `error not run`" { + const gpa = testing.allocator; + const p = try withTerm(gpa); + defer p.deinit(); + const node = Node.of(serialOf(p), .pty_run); + const out = struct { + fn put(pp: *Pardes, bytes: []const u8) void { + pp.update(.{ .output = .{ .pane = .at(0), .bytes = bytes } }); + while (pp.nextEffect()) |_| {} + } + }; + const prompt = "\x1b]133;A;cl=line;aid=pardes\x07$ \x1b]133;B;aid=pardes\x07"; + // A window's first terminal: bash's first prompt, then the window's + // first size (its rows a row shorter), which readline answers by + // drawing its prompt again: with the run's line on it when it had read + // it, its Enter not yet. Then the line taken: its newline, and in the + // next read PS0's C (bash writes them apart): bytes as pty/data read + // them off a ReleaseSafe window session's start. + out.put(p, "\x1b]133;D;0;aid=pardes\x07" ++ prompt); + const h = call(p, .{ .tag = 1, .op = .open, .node = node }).reply.handle; + try testing.expectEqualStrings("echo $$\r", call(p, .{ .tag = 2, .op = .write, .node = node, .handle = h, .data = "echo $$\n" }).pty()); + out.put(p, "\r\x1b[K\r" ++ prompt ++ "echo $$"); + out.put(p, "\r\n\x1b[?2004l\r"); + try testing.expectEqual(Status.again, call(p, .{ .tag = 3, .op = .read, .node = node, .handle = h, .size = 64 }).reply.status); + out.put(p, "\x1b]133;C;aid=pardes\x074242\r\n\x1b]133;D;0;aid=pardes\x07" ++ prompt); + try testing.expectEqualStrings("exit 0\n4242\n", call(p, .{ .tag = 4, .op = .read, .node = node, .handle = h, .size = 64 }).bytes); +} + +test "a run written just after a new terminal's greeting is typed is not answered with the greeting's output" { + 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 prompt = "\x1b]133;A;cl=line;aid=pardes\x07$ \x1b]133;B;aid=pardes\x07"; + // The first prompt: the greeting typed at it, its echo not back yet. + p.update(.{ .output = .{ .pane = .at(0), .bytes = prompt } }); + var greeted: [16]u8 = undefined; + var len: usize = 0; + while (p.nextEffect()) |e| if (e == .write) { + const b = e.write.bytes.slice(); + @memcpy(greeted[len..][0..b.len], b); + len += b.len; + }; + try testing.expectEqualStrings("ls\r", greeted[0..len]); + 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" }); + for ([_][]const u8{ "ls\r\n\x1b]133;C;aid=pardes\x07notes.txt\r\n\x1b]133;D;0;aid=pardes\x07" ++ prompt, "true\r\n\x1b]133;C;aid=pardes\x07\x1b]133;D;0;aid=pardes\x07" ++ prompt }) |bytes| { + p.update(.{ .output = .{ .pane = .at(0), .bytes = bytes } }); + while (p.nextEffect()) |_| {} + } + try testing.expectEqualStrings("exit 0\n", call(p, .{ .tag = 3, .op = .read, .node = node, .handle = h, .size = 64 }).bytes); +} + test "run answers how its command ended once the shell is back at a prompt" { const gpa = testing.allocator; const p = try withTerm(gpa); diff --git a/core/panes.zig b/core/panes.zig index 5bf6992a..4116c3e8 100644 --- a/core/panes.zig +++ b/core/panes.zig @@ -160,6 +160,10 @@ pub const Pane = struct { cols: u16, rows: u16, greet: bool = false, + /// Its greeting was typed (Pardes.layout): that `ls` is its shell's + /// first command, and a run written until the prompt after it waits for + /// that prompt (ninep/pty.zig `greeting`), as for the first. + greeted: bool = false, /// Its shell could not be started (Pardes.shellFailed): a run hears /// `error shell gone` at once. shell_failed: bool = false, diff --git a/core/term/terminal.zig b/core/term/terminal.zig index 45c01841..88eb1443 100644 --- a/core/term/terminal.zig +++ b/core/term/terminal.zig @@ -927,9 +927,19 @@ pub fn prompt(state: ?*State) Term.Prompt { // Nothing further right counts: that is where fish draws a right // prompt, and fish suggests nothing on an empty line. const empty = ready and empty: { + var prompted = false; const row = cursor.page_pin.cells(.all); - for (row[0..@min(cursor.x + 1, row.len)]) |cell| + for (row[0..@min(cursor.x + 1, row.len)]) |cell| { if (cell.semantic_content == .input and !cell.isEmpty()) break :empty false; + prompted = prompted or cell.semantic_content == .prompt; + } + // A row with no prompt on it, begun by a newline in the input: the + // line above was taken, its Enter echoed and the command's C still + // to come (bash writes them apart), so it is typed still. + if (!prompted and cursor.page_row.semantic_prompt == .prompt_continuation) if (cursor.page_pin.up(1)) |above| { + for (above.cells(.all)) |cell| + if (cell.semantic_content == .input and !cell.isEmpty()) break :empty false; + }; break :empty true; }; return .{ |
