diff options
| author | Gabriel Schneider <[email protected]> | 2026-10-30 16:16:25 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-10-30 20:25:56 -0300 |
| commit | 05826d5148b8d75c32397380b9f64e0b3477e5bb (patch) | |
| tree | 37263052ca93ebf7dc6d823631997ed7f8251dd0 /src/terminal.zig | |
| parent | 6cb07327b717603be983fdd6df0e6d9009aae39a (diff) | |
| download | pardes-05826d5148b8d75c32397380b9f64e0b3477e5bb.tar.gz pardes-05826d5148b8d75c32397380b9f64e0b3477e5bb.zip | |
replica: pardes's own steps over a terminal speculated, not every input while one has the keyboard (H14): what reaches its program is a pty write and stops as before; its view (normal-mode keys, the wheel, Ctrl-u) moves here at once, the rollback copy keeping each terminal's view (it holds no emulator) and a delta setting it, put back between the units it replays in the order the deltas came among them; what was applied over a terminal applied again over each delta or rows that come while it waits, and its unit taken at once rather than kept to replay over later deltas; closing a terminal stops (its pty's end is the authority's)
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Diffstat (limited to 'src/terminal.zig')
| -rw-r--r-- | src/terminal.zig | 43 |
1 files changed, 38 insertions, 5 deletions
diff --git a/src/terminal.zig b/src/terminal.zig index be886044..20a9a015 100644 --- a/src/terminal.zig +++ b/src/terminal.zig @@ -192,15 +192,17 @@ pub const State = struct { // a replica's is what the last delta made it: compared as screens // (test/replicas.zig), not step by step. if (pardes.tape.screenState()) return; - s.digestScreen(h); + s.digestScreen(h, true); } - pub fn digestScreen(s: *const State, h: *pardes.walk.Hasher) void { + /// `view`: where its view is too (a replica's speculation may move it). + pub fn digestScreen(s: *const State, h: *pardes.walk.Hasher, view: bool) void { if (comptime !enabled) return; const screen = s.vt.screens.active; const sb = screen.pages.scrollbar(); const cur = screen.cursor; - const facts = .{ sb.total, sb.offset, sb.len, cur.x, cur.y, s.vt.modes.get(.cursor_visible), s.vt.screens.active_key, s.reply_dropped }; + const offset = if (view) sb.offset else 0; + const facts = .{ sb.total, offset, sb.len, cur.x, cur.y, s.vt.modes.get(.cursor_visible), s.vt.screens.active_key, s.reply_dropped }; inline for (facts) |fact| h.update(std.mem.asBytes(&fact)); h.update(s.reply[0..s.reply_len]); var buf: [4096]u8 = undefined; @@ -613,10 +615,40 @@ fn authorityOnly(comptime why: []const u8) bool { return true; } +/// A speculation that moves a terminal's view: a screen-state replica's +/// may (its rollback puts the view back, replica.zig `views`, and a delta +/// sets it), any other stops (`authorityOnly`). +fn viewOnly(comptime why: []const u8) bool { + if (!pardes.tape.speculating()) return false; + if (pardes.tape.screenState()) { + pardes.tape.touchTerminal(); + return false; + } + pardes.tape.poison(why); + return true; +} + +/// Where a terminal's view is: its top row counted from the top of its +/// history, or null following its output (a replica's rollback copy, +/// which holds no emulator, keeps it so). +pub fn viewOf(pane: *const Pane) ?usize { + if (comptime !enabled) return null; + const state = pane.terminal orelse return null; + const pages = &state.vt.screens.active.pages; + if (pages.viewport == .active) return null; + return pages.scrollbar().offset; +} + +pub fn viewTo(pane: *Pane, at: ?usize) void { + if (comptime !enabled) return; + const state = pane.terminal orelse return; + state.vt.screens.active.scroll(if (at) |row| .{ .row = row } else .active); +} + /// Move the emulator's viewport by `delta` shell rows (negative scrolls back). pub fn scrollGrid(pane: *Pane, delta: i32) void { if (comptime !enabled) return; - if (authorityOnly("scroll a terminal")) return; + if (viewOnly("scroll a terminal")) return; const state = pane.terminal orelse return; state.vt.screens.active.scroll(.{ .delta_row = delta }); state.changes +%= 1; @@ -632,7 +664,7 @@ pub fn atBottom(pane: *const Pane) bool { /// Snap the viewport back onto live output. pub fn followOutput(pane: *Pane) void { if (comptime !enabled) return; - if (authorityOnly("follow a terminal")) return; + if (viewOnly("follow a terminal")) return; const state = pane.terminal orelse return; const moved = state.vt.screens.active.pages.viewport != .active; state.vt.screens.active.scroll(.active); @@ -1858,6 +1890,7 @@ fn dumpedBytes(pin: ghostty_vt.Pin, cell: *const ghostty_vt.Cell) usize { pub fn shellRows(p: *Pardes, pane: *Pane) ![]const []const u8 { if (comptime !enabled) return &empty_grid; if (pane.terminal == null) return &empty_grid; + pardes.tape.touchTerminal(); const c = &p.shell_rows; if (!c.stale and c.pane == pane) { // A step's read whether the rows are kept or made: a client that |
