diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-26 04:01:58 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-26 04:43:49 -0300 |
| commit | 5dab435d7262b87d2cf40d6a27cea9c2d981c2e8 (patch) | |
| tree | aad30de3d26892ff919e7d0bcc7421e10f21c426 | |
| parent | 89f51118eb241fdb5673e91eb09e5abe5c6a0bcb (diff) | |
| download | pardes-5dab435d7262b87d2cf40d6a27cea9c2d981c2e8.tar.gz pardes-5dab435d7262b87d2cf40d6a27cea9c2d981c2e8.zip | |
Core, Term: a terminal's emulator and pty are resized once a step and its burst of inputs, at the size the layout settles on, never once a key: a level that borrows a shell's rows and gives them back in one burst resizes neither, and the shell keeps its prompt line (agent M1's find, ymkwwwnn 94f00e966c90: ttyhelp's row 3, the shell's `$`, blank after `SPC ? tutor`); THE CAUSE: Pardes.sync, at the end of every `update` (a key), resized each terminal whose rect changed (Pane.resizeGrid, Term.resize) and queued its pty's resize; `?`'s level takes 3 of the shell's rows (layout.floorRows), `tutor` in the same read gives them back, so the emulator was reflowed twice, and each reflow cleared the prompt line under its cursor for the shell to draw again (ghostty's Screen.resize, clearPromptForRedraw under Terminal.flags.shell_redraws_prompt); bash, told twice with no gap, reads its size once, finds the one it had and draws nothing (the pty probe, .scratch/walkui/T123/bashprobe.py, bash 5.3.20 with pardes's mark: resized 17 -> 14 -> 17 with no gap it writes no byte; 0.3 s apart it writes `\r\e[K\r` and its prompt twice); THE FIX: `sync` is `layOut` (the geometry, every pane's cols and rows, the bands, the greetings) and `sizeTerminals`, which gives each terminal its pane's size when its emulator has another (Term.grid's cols and len: no new state, nothing in the dump), resizes the grid and queues the pty's resize; `update` lays out only, and `settle` (a pump's, a replica's step) sizes the terminals after its queued inputs and before the effects; a 9P request's step (serveFs, a kbdin write of many keys among them), a view's open and close and a watched file's reload keep the whole `sync`; `toView` sizes them before the live view parks (a terminal is sized by one view, `sizes`); a step's own layouts in its middle (a picker's first preview, Pick's showText, showKind and putBack, Query.displayPreview, Store.reopen, jj.open, layout.givePaneRows) call `layOut`; RUN (TEST FIRST): Core.zig "a level that borrows a shell's rows and gives them back in one burst of keys resizes neither its emulator nor its pty ..." boots ttyhelp's layout in the core (100x31, a shell over the +New), gives the shell pardes's bash prompt, focuses the +New and types SPC ? t u t o r with one settle after: fails on the base (two resize_pty effects queued, the shell's first row blank after the settle), passes now; three tests that fed a new shell before any step's end sized it get a `sync` (two in Core.zig) or a `settle` (ninep/pty.zig, pty/ctl's winsize read back after a resize), Term.zig's S1 table counts Core.zig's third Term.grid; the ttyhelp golden re-recorded: row 3 is the shell's `$` again (its leaderworks snap lists 6 rows, not 7); THE MARK (the ruling's second part): ghostty's own bash integration (the genizah's, and the pinned 1.4.0's) marks bash's prompt `133;A;redraw=last;cl=line`: `last` clears only the cursor's line on a resize (bash redraws only a prompt's last line), so it would not have kept M1's one-line `$` either, and ghostty never says `redraw=0` for bash (a narrower reflow would leave the old wrapped rows under bash's redraw): the mark is unchanged (`redraw=last` would keep a multi-line PS1's first lines through a real resize: a separate change, not made); a user hit it whenever a pane beside a shell at its prompt borrowed its rows and gave them back faster than the shell read its size; NEW HOT PATHS: settle and toView walk the panes once (a terminal: Term.grid, its two sizes compared), where sync did per step before; GATES: core-test 1129/1303 (174 skipped: +1, the new test needs a terminal), shell-test 1351/1354 (3 skipped: +1), pane-test 183/184, behaviour-test 285/285 and --replay 20 seeds of 70 steps, 0 failures, process-test 1 of 147 failed (3 skipped): ttyhelp, the golden re-recorded, then 5 of 5 runs alone pass, term-test 17/17, kitty-test 45/45, the gui unit-test 1959/1963 (4 skipped: +1; its perf check's BaselineHarnessMismatch, every base's); no dump change (no new state; effects are local); no frame or perf gate (the user's rule of 2026-11-26); the shots (S kit, 26 px, .scratch/walkui/T123/png): after-0..3, this change's Debug gui: ttyhelp's bare boot, the +New clicked, `SPC ? tutor` in one pty write: the prompt stays on row 3 and the level ends on the +New's tag row as in the golden; before-0..3, the installed stage's (install74): that build's level keeps 7 of the shell's rows after `tutor` (it predates W1's floor), one shrink that bash redraws, so it does not show the fault; load 4.5 to 9.0
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNBFhdevVu48bvL9kCE
| -rw-r--r-- | core/Core.zig | 82 | ||||
| -rw-r--r-- | core/Pick.zig | 8 | ||||
| -rw-r--r-- | core/Query.zig | 2 | ||||
| -rw-r--r-- | core/Store.zig | 2 | ||||
| -rw-r--r-- | core/Term.zig | 2 | ||||
| -rw-r--r-- | core/jj.zig | 2 | ||||
| -rw-r--r-- | core/layout.zig | 2 | ||||
| -rw-r--r-- | core/ninep/pty.zig | 1 | ||||
| -rw-r--r-- | test/snapshots/ttyhelp.golden | 1 |
9 files changed, 82 insertions, 20 deletions
diff --git a/core/Core.zig b/core/Core.zig index cbcf4324..4c98977a 100644 --- a/core/Core.zig +++ b/core/Core.zig @@ -1349,6 +1349,8 @@ pub fn toView(p: *Pardes, k: View.Id) void { if (k.index() == p.live) return; const taped = pardes.tape.enter(p, .{ .to_view = k }); defer pardes.tape.leave(p, taped); + // A terminal the going view sizes takes the size its inputs left it. + p.sizeTerminals(); Views.to(p, k.index()); } @@ -1667,6 +1669,7 @@ pub fn settle(p: *Pardes) void { // ...and the last line of an open closed with no newline after it. ctlfs.runClosedLines(p); while (p.nextQueued()) |ev| p.update(ev); + p.sizeTerminals(); while (p.nextEffect()) |e| p.perform(e); turn.bump(&turn.epoch); } @@ -1847,7 +1850,9 @@ fn updateInner(p: *Pardes, ev: Event) void { pardes.panes.Query.produceAll(p, ev == .tick, ev == .key); pardes.Pick.produceAll(p, ev == .tick); _ = p.scratch.reset(.{ .retain_with_limit = memory.limits.scratch_kept }); - p.sync(); + // Laid out; its terminals are sized when the burst it came in is + // (`settle`, `sizeTerminals`). + p.layOut(); p.fsReport(); ctlfs.events.announce(p); } @@ -1969,8 +1974,41 @@ pub fn saveRecent(p: *Pardes) void { } /// Recompute geometry, push grid-size changes to each emulator and pty, -/// fire deferred greetings. +/// fire deferred greetings: a step of its own (a 9P request's, a view's). pub fn sync(p: *Pardes) void { + p.layOut(); + p.sizeTerminals(); +} + +/// Each terminal's emulator and pty at the size its pane is laid out to, +/// once a step and its burst of inputs (`settle`), never once a key: a +/// size the keys of one burst give and take back (a level borrowing a +/// shell's rows, the next key giving them back) reaches neither. Every +/// reflow clears the prompt line under the cursor for the shell to draw +/// again (ghostty's Screen.resize, `shell_redraws_prompt`), and the shell, +/// told twice, reads its size once, finds the one it had and draws +/// nothing: the prompt was gone until it next printed one. The emulator's +/// own size says what it was given; the view that sizes a terminal +/// (`sizes`) has its size. +pub fn sizeTerminals(p: *Pardes) void { + for (p.panes, 0..) |slot, id| { + const pane = slot orelse continue; + const state = pane.terminal orelse continue; + if (!p.sizes(pane)) continue; + const grid = pardes.Term.grid(state); + if (grid.cols == pane.cols and grid.len == pane.rows) continue; + pane.resizeGrid(p, pane.cols, pane.rows); + p.shell_rows.markStale(pane); // reflow moved every row + p.emit(.{ .resize_pty = .{ .pane = .at(id), .cols = pane.cols, .rows = pane.rows } }); + pane.fs.winsize = null; + } +} + +/// The step's geometry: each pane's rect, tag rows and size (a terminal's +/// emulator and pty follow once a burst: `sizeTerminals`), its bands, and +/// the deferred greetings. What a step lays out in its middle, to read the +/// geometry after (a picker's first preview), is laid out with this. +pub fn layOut(p: *Pardes) void { const v = p.view(); while (p.unplaced.findFirstSet()) |id| { p.unplaced.unset(id); @@ -2085,14 +2123,6 @@ pub fn sync(p: *Pardes) void { if ((cols != pane.cols or rows != pane.rows) and (r.h > pane.tag_rows or (pane.isTerminal() and !pane.collapsed and r.h > 0)) and (!pane.isTerminal() or p.sizes(pane))) { - // doc panes have no pty/emulator grid to reflow; just record - // the size so bodyText renders the right number of rows - if (pane.isTerminal()) { - pane.resizeGrid(p, cols, rows); - p.shell_rows.markStale(pane); // reflow moved every row - p.emit(.{ .resize_pty = .{ .pane = .at(id), .cols = cols, .rows = rows } }); - pane.fs.winsize = null; - } pane.cols = cols; pane.rows = rows; if (pane.file) |*file| file.syntax_dirty = true; @@ -4197,6 +4227,7 @@ test "leaving tty hides the prompt and keeps the command typed at it" { defer p.deinit(); p.update(.{ .resize = .{ .cols = 80, .rows = 24 } }); p.update(.{ .key = .{ .cp = 'n', .alt = true } }); // a shell under the doc + p.sync(); // its emulator sized as its step's end sizes it, before its shell speaks const shell = p.view().active; const sp = p.panes[shell].?; try std.testing.expect(sp.isTerminal()); @@ -4263,6 +4294,7 @@ test "entering tty walks the shell cursor to the column clicked past the prompt" defer p.deinit(); p.update(.{ .resize = .{ .cols = 80, .rows = 24 } }); p.update(.{ .key = .{ .cp = 'n', .alt = true } }); + p.sync(); // its emulator sized as its step's end sizes it, before its shell speaks const shell = p.view().active; const sp = p.panes[shell].?; p.update(.{ .output = .{ @@ -4308,3 +4340,33 @@ test "entering tty walks the shell cursor to the column clicked past the prompt" test "every allocation failure during boot is a clean OutOfMemory" { try std.testing.checkAllAllocationFailures(std.testing.allocator, bootAndTearDown, .{}); } + +test "a level that borrows a shell's rows and gives them back in one burst of keys resizes neither its emulator nor its pty: its prompt line stays (M1's ttyhelp row 3)" { + if (pardes.Term.ops == null) return error.SkipZigTest; // a shell's emulator + const p = try Pardes.init(std.testing.allocator, .{ .cols = 100, .rows = 31, .boot = .tty }); + defer p.deinit(); + const shell = p.panes[0].?; + // bash's prompt as pardes's marks draw it (dev/Shell.zig bash_rc), + // the cursor at its input. + p.update(.{ .output = .{ .pane = .at(0), .bytes = "\x1b]133;A;cl=line;aid=pardes\x07$ \x1b]133;B;aid=pardes\x07" } }); + const below = p.view().cols[0].panes[1]; + p.view().active = below; + p.settle(); + const rows = shell.rows; + var arena = std.heap.ArenaAllocator.init(std.testing.allocator); + defer arena.deinit(); + const body_layer = @import("body_layer.zig"); + try std.testing.expect(std.mem.startsWith(u8, try body_layer.bodyText(p.settings.tab, arena.allocator(), shell), "$ ")); + // `?`'s level takes rows of the shell's (layout.floorRows), `tutor` + // narrows it to one leaf and gives them back: keys of one burst, one + // settle after them, as a frontend takes a read of them. + p.update(.{ .key = .{ .cp = ' ', .text = " " } }); + p.update(.{ .key = .{ .cp = '?', .text = "?" } }); + try std.testing.expect(shell.rows < rows); + for ("tutor") |c| p.update(.{ .key = .{ .cp = c, .text = &.{c} } }); + try std.testing.expectEqual(rows, shell.rows); + // Its pty told nothing: no SIGWINCH for a size it had. + while (p.nextEffect()) |e| try std.testing.expect(e != .resize_pty); + p.settle(); + try std.testing.expect(std.mem.startsWith(u8, try body_layer.bodyText(p.settings.tab, arena.allocator(), shell), "$ ")); +} diff --git a/core/Pick.zig b/core/Pick.zig index cfef2baf..9a9d0cde 100644 --- a/core/Pick.zig +++ b/core/Pick.zig @@ -1009,7 +1009,7 @@ fn preview(p: *Pardes, pk: *Pick) void { // laid out again before the place is put in its rows. if (!pk.previewed) { pk.previewed = true; - p.sync(); + p.layOut(); } const keyboard = p.view().active; defer p.view().active = keyboard; @@ -1060,7 +1060,7 @@ fn showText(p: *Pardes, pk: *Pick, id: usize, path_: []const u8, bytes: []u8) vo } pane.hscroll = 0; pk.previewed = true; - p.sync(); + p.layOut(); } /// Landing pane `id` showing the file at `path` through kind `k`, as a @@ -1083,7 +1083,7 @@ fn showKind(p: *Pardes, pk: *Pick, id: usize, k: u8, path: []const u8, bytes: [] Kind.close(p, pane); return showText(p, pk, id, path, line); } - p.sync(); + p.layOut(); } /// The one line a file shows while a picker previews it and none of its @@ -1154,7 +1154,7 @@ fn putBack(p: *Pardes, pk: *Pick) void { pane.body.cur_row = pk.aside_row; pane.body.cur_col = pk.aside_col; pane.body.vsel.active = false; - p.sync(); + p.layOut(); } /// The live picker rolled up (Esc, or the tag put to rest by anything): diff --git a/core/Query.zig b/core/Query.zig index fff6065c..1a420a68 100644 --- a/core/Query.zig +++ b/core/Query.zig @@ -1704,7 +1704,7 @@ fn displayPreview(p: *Pardes, qid: usize, path: []const u8, at: look.Spot) void pane.hscroll = 0; // another file: its own places, found below pane.places.clear(p.gpa); - p.sync(); + p.layOut(); } look.clearNavigationSelection(p, pane); if (at.line == 0 or at.line > File.nlines(p.gpa, f)) { diff --git a/core/Store.zig b/core/Store.zig index 1328af38..8a1c3987 100644 --- a/core/Store.zig +++ b/core/Store.zig @@ -223,7 +223,7 @@ pub fn reopen(s: *Store, p: *Pardes, serial: u32, from: usize) bool { }; p.view().active = free; if (layout.findPane(p, free)) |f| p.setActiveColumn(f.col); - p.sync(); + p.layOut(); return true; } diff --git a/core/Term.zig b/core/Term.zig index d4baf4e8..509da6d9 100644 --- a/core/Term.zig +++ b/core/Term.zig @@ -422,7 +422,7 @@ pub const calls = [_]struct { []const u8, []const u8, []const u8 }{ .{ "endOutputHere", "ninep/pty.zig:1", "WRITE: a 9P pty/run's step ends a command's output at the cursor: the session's step, replayed as such" }, .{ "replies", "Core.zig:1", "WRITE: a step drains the reply buffer (in the digest), counted when it held any (the feed's own unit, which filled it); only the session writes it to the pty (pty_write is off the tape)" }, // ---- reads by a step: in the digest ---- - .{ "grid", "Core.zig:2 ansi.zig:3 body_layer.zig:3 draw.zig:2 dump.zig:4 echo.zig:8 exec.zig:2 layout.zig:2 panes.zig:6 replica.zig:2", "READ: the size, the history's length, the cursor: in the digest (a view's place is its pane's; ansi.zig, body_layer.zig, draw.zig, echo.zig: a draw's)" }, + .{ "grid", "Core.zig:3 ansi.zig:3 body_layer.zig:3 draw.zig:2 dump.zig:4 echo.zig:8 exec.zig:2 layout.zig:2 panes.zig:6 replica.zig:2", "READ: the size, the history's length, the cursor: in the digest (a view's place is its pane's; ansi.zig, body_layer.zig, draw.zig, echo.zig: a draw's)" }, .{ "modes", "Core.zig:5 draw.zig:1 dump.zig:2 echo.zig:3 exec.zig:3 mouse.zig:4 ninep/pty.zig:3 panes.zig:2 replica.zig:1", "READ: the program's modes (mouse, focus, bracketed paste, the alternate screen): in the digest (draw.zig, echo.zig: a draw's; panes.zig: a view scrolls no history on the alternate screen)" }, .{ "prompt", "Core.zig:1 builtins.zig:1 echo.zig:1 exec.zig:3 ninep/pty.zig:1 panes.zig:1", "READ: the OSC 133 cycle: in the digest (`marksOf`); Core.zig's and ninep/pty.zig's also taped (`.prompt`, each side's compared)" }, .{ "promptPrefix", "body_layer.zig:1 edit.zig:1 exec.zig:1", "READ: a row's prompt cells (`promptCut`): the active area's in the digest; a history row's text is not (below)" }, diff --git a/core/jj.zig b/core/jj.zig index 63488b8c..bc2cea32 100644 --- a/core/jj.zig +++ b/core/jj.zig @@ -157,7 +157,7 @@ pub fn open(p: *Pardes, near: usize, path: []const u8, rev: []const u8, at: look if (replace) p.removePane(near, free) catch |err| p.reportError(.at(free), "At", err); layout.compute(p); // Sized for its place before it is centred there. - p.sync(); + p.layOut(); look.focusPaneLine(p, free, at, .center); return free; } diff --git a/core/layout.zig b/core/layout.zig index 3f6bea51..a6e6419b 100644 --- a/core/layout.zig +++ b/core/layout.zig @@ -402,7 +402,7 @@ pub fn givePaneRows(p: *Pardes, id: usize, wanted: u16, context: usize) void { if (missing == 0) break; } setColumnWeights(p, at.col, &heights); - p.sync(); + p.layOut(); } pub fn applyRowSplit(p: *Pardes, cc: usize, k: usize, cur_y: u16) void { diff --git a/core/ninep/pty.zig b/core/ninep/pty.zig index 2dd7f7f3..2671467f 100644 --- a/core/ninep/pty.zig +++ b/core/ninep/pty.zig @@ -597,6 +597,7 @@ test "every pty/ctl verb, and every refusal" { try testing.expectEqual(@as(u64, "winsize 132 44\n".len), call(p, .{ .tag = 1, .op = .getattr, .node = ctl }).reply.attr.size); try testing.expect(std.mem.startsWith(u8, rd(p, Node.of(serialOf(p), .pty_status), 0, 64).bytes, " 132 44 ")); p.update(.{ .resize = .{ .cols = 76, .rows = 24 } }); + p.settle(); // the step's end: the pty takes its pane's size (Pardes.sizeTerminals) try testing.expect(pane.cols != 132); try testing.expectEqualStrings(try std.fmt.bufPrint(&said, "winsize {d} {d}\n", .{ pane.cols, pane.rows }), rd(p, ctl, 0, 64).bytes); diff --git a/test/snapshots/ttyhelp.golden b/test/snapshots/ttyhelp.golden index 92bb4675..5ab2e6f6 100644 --- a/test/snapshots/ttyhelp.golden +++ b/test/snapshots/ttyhelp.golden @@ -42,7 +42,6 @@ |29: 5 In the tag of the pane its Enter lands in from this one: this pane if it reads, else its rea |30: ✓ @p1 Help 1 message · SPC h m == snap leaderworks grid=100x31 cursor=12,21 -|3: |21: ^ Help tutor 1/1 |22: ▶ SPC h t Tutor help │ t Tutor |23: │ Open the tutor, a document to work through. |
