summaryrefslogtreecommitdiff
path: root/core/Core.zig
diff options
context:
space:
mode:
Diffstat (limited to 'core/Core.zig')
-rw-r--r--core/Core.zig112
1 files changed, 84 insertions, 28 deletions
diff --git a/core/Core.zig b/core/Core.zig
index ccdc8d6f..3a2e1f51 100644
--- a/core/Core.zig
+++ b/core/Core.zig
@@ -351,8 +351,6 @@ custom_theme: ?LegacyTheme = null,
/// session's own theme untouched under it.
theme_preview: ?u16 = null,
preview_chrome: ChromeTheme = undefined,
-/// bodyChrome's: the theme it was worked out for, and it.
-body_chrome: ?struct { theme: LegacyTheme, chrome: ChromeTheme } = null,
theme_file_path: config.Settings.Text(limits.host_path_cap) = .{},
/// The ThemeFile last loaded whole: what /ctl and DumpConfig name, and
/// what a failed ThemeFile goes back to (colors.revertThemeFile).
@@ -411,8 +409,13 @@ pipe: Pipe = .{},
/// A query pane's Grep, and its Find's listing, on a worker (Stream.zig).
stream: Stream = .{},
/// The pickers: the one live in a view's tag, and the last ones rolled
-/// up, which their list words and Resume reopen (Pick.zig).
-picks: [pardes.Pick.max_lists]?*pardes.Pick = @splat(null),
+/// up, which their list words, Resume and Lists reopen (Pick.zig); Lists
+/// itself in the one more, never kept.
+picks: [pardes.Pick.max_lists + 1]?*pardes.Pick = @splat(null),
+/// The kept picker Resume shows, the newest 1 (Pick.nth), 0 for none:
+/// `SPC '` again after an Esc from it, nothing typed between, opens the
+/// one before it, and Ctrl-o and Ctrl-i in it step through them (UX L'2).
+resume_at: u8 = 0,
/// The panes' `Changes` (jj.zig): what was asked of jj, and what it
/// answered for each pane, by its serial: the session's, not a field of
/// every pane (a digest and a rollback copy walk every pane's fields at
@@ -542,7 +545,7 @@ pub const replica = .{
"opts", "dump_out", "dump_export",
"tape",
},
- .derived = .{ "shell_rows", "diff_output", "locations_cache", "retired_panes", "tty_filter_palette", "body_chrome", "theme_preview", "preview_chrome" },
+ .derived = .{ "shell_rows", "diff_output", "locations_cache", "retired_panes", "tty_filter_palette", "theme_preview", "preview_chrome" },
// The host's handles, the state file every session of the user
// shares (and Recent read from it), this session's closed panes, and
// the files of a host with no file system of its own. (The 9P
@@ -1330,6 +1333,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());
}
@@ -1648,6 +1653,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);
}
@@ -1828,7 +1834,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);
}
@@ -1950,8 +1958,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);
@@ -2068,14 +2109,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;
@@ -2140,10 +2173,11 @@ fn sizes(p: *const Pardes, pane: *const Pane) bool {
return pane.sized_by == p.live;
}
+/// The theme in the old names, for what still reads a theme's own
+/// fields (colors.ChromeTheme.view).
pub fn theme(p: *const Pardes) *const LegacyTheme {
- if (p.theme_preview) |i| return &colors.legacy_themes[i];
- if (p.custom_theme) |*custom| return custom;
- return &colors.legacy_themes[p.settings.theme];
+ if (p.theme_preview == null) if (p.custom_theme) |*custom| return custom;
+ return &p.chromeTheme().view;
}
/// The colours of the chrome: the theme's, set as it changes.
@@ -2158,16 +2192,6 @@ pub fn chrome(p: *const Pardes) *const colors.Chrome {
return &p.chromeTheme().resolved;
}
-/// The theme's own chrome, not a fade's (`theme()`'s, worked out once
-/// per theme: its contrast searches take pow calls, too many for a
-/// grapheme or a row).
-pub fn bodyChrome(p: *Pardes) *const ChromeTheme {
- const th = p.theme();
- if (p.body_chrome) |*cached| if (std.meta.eql(cached.theme, th.*)) return &cached.chrome;
- p.body_chrome = .{ .theme = th.*, .chrome = ChromeTheme.fromTheme(th) };
- return &p.body_chrome.?.chrome;
-}
-
/// When the core next needs a frame, on the `stepped_ns` timeline: a
/// frame from now while work goes on (places to find, a picture
/// decoding, a PDF page on a lane), the end of the wait while something
@@ -4210,6 +4234,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());
@@ -4276,6 +4301,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 = .{
@@ -4321,3 +4347,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), "$ "));
+}