diff options
Diffstat (limited to 'core')
| -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 |
8 files changed, 82 insertions, 19 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); |
