summaryrefslogtreecommitdiff
path: root/src/terminal.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/terminal.zig')
-rw-r--r--src/terminal.zig43
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