From 8e850e6c923dcd84b7a5483f73377bd192b94a2b Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Sun, 22 Nov 2026 17:55:03 -0300 Subject: terminals: where a view stands in a terminal's history is the view's, not the emulator's (pardes-term-join-10, item 1; the note's point 3, the coordinator's choice): `Pane.scrolled_to` (core/panes.zig), a per-view field (views.zig `pane_fields`, `PaneView`: in the rollback copy, the digest and the dump, each view's own), the row its top shows or null on the output, written only by a step (`scrollBy`, `followOutput`), and carried with every open view's through each write of the emulator that moves rows, once, in the confirmed unit's apply, on every side alike (`Term.feed`/`Term.resize` take the places; core/term/terminal.zig `carry`/`carried` pin each place's row on the primary screen and read the pin back: up by the rows the history drops, 0 when its own row goes, null in the active area or after a reset: a function of the fed bytes); the draw reads the rows from the view's place (`viewport`, `paint`, `ImagesAt.place`, terminal.zig `shown`), and ghostty's own viewport is never moved, read, digested or dumped (`Grid.offset`/`view`, `Parts.view` and the digest's offset gone): two clients no longer scroll one viewport (the new views.zig test failed on the base, `expected 80, found 77`), and a speculation's scroll is in the copy, so `putViews`, the view half of `keepViews` (now `keepSerials`), `viewTo`/`scroll`/`follow` (ops, wrappers, bodies), the Debug screen hash's view exclusion, `reflow`'s column-0 cure and `feedOutput`'s follow-after-read are deleted, and S1's `calls` lists no view write (the rows `viewTo`, `scroll`, `follow` gone); tests: the two-view test (with a dump), the place at the history's cap (`setMaxBytes(1)`), a 300-seed fuzz of the carried place against ghostty's own pinned view, a client's wheel over a shared terminal through output and a rollback, round 6's order explorer (30 seeds a run); the wire at 31 (abi/wire.zig, test/daemon.py `WIRE`): an installed build's dump loads with every view on the output; IN THE WORKSPACE core-test 912/1072 (160 skipped), shell-test 1114/1117 (3 skipped), term-test 16/16, kitty-test 45/45, pane-test 181/182, behaviour-test 275/275, --replay 275/275, process-test 0 of 146 failed, as pairs 0 of 146; gui unit-test 1707/1711, its one error BaselineHarnessMismatch (every base's) Co-Authored-By: Claude Opus Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T --- test/daemon.py | 2 +- test/kitty.zig | 8 ++++---- test/panes.zig | 14 +++++++------- test/perf.zig | 2 +- test/replicas.zig | 19 +++++++++---------- test/terminal.zig | 6 ++---- 6 files changed, 24 insertions(+), 27 deletions(-) (limited to 'test') diff --git a/test/daemon.py b/test/daemon.py index 55cffaf4..c91e6dde 100644 --- a/test/daemon.py +++ b/test/daemon.py @@ -276,7 +276,7 @@ class Replica: """A replica's connection (abi/wire.zig): length-prefixed messages, a tag byte and a little-endian u32 length. It is a near client: its first word after the hello says so.""" - WIRE = 30 + WIRE = 31 def __init__(self, path, timeout=10): self.path, self.timeout = path, timeout diff --git a/test/kitty.zig b/test/kitty.zig index 76d97421..22b62fb2 100644 --- a/test/kitty.zig +++ b/test/kitty.zig @@ -641,14 +641,14 @@ test "kitty: an image follows its text when the shell scrolls, resizes and reflo try std.testing.expectEqual(o.y + 2, (try r.placesOf(10))[0].dst.y); // A narrower pane reflows the text; the image stays on its row. const pane = r.pane(0); - pane.resizeGrid(40, pane.rows); + pane.resizeGrid(0, 40, pane.rows); const text = try pardes.Term.scrollback(pane.terminal, r.frame.allocator()); var row: usize = 0; var lines = std.mem.splitScalar(u8, text, '\n'); while (lines.next()) |line| : (row += 1) if (std.mem.startsWith(u8, line, "marker")) break; const drawn = try r.placesOf(10); try std.testing.expectEqual(@as(usize, 1), drawn.len); - const viewport_top: usize = pardes.Term.grid(pane.terminal).offset; + const viewport_top: usize = pane.termTop(); try std.testing.expectEqual(o.y + @as(u16, @intCast(row - viewport_top)), drawn[0].dst.y); } @@ -1167,7 +1167,7 @@ fn fuzzRun(seed: u64, steps: usize, trace: bool) !bool { r.p.update(.{ .resize = .{ .cols = cols, .rows = rows, .cell_pixels = .{ .w = 1 + rng.uintLessThan(u16, 30), .h = 1 + rng.uintLessThan(u16, 60) } } }); r.drain(); }, - 1 => r.pane(0).resizeGrid(1 + rng.uintLessThan(u16, 120), 1 + rng.uintLessThan(u16, 40)), + 1 => r.pane(0).resizeGrid(0, 1 + rng.uintLessThan(u16, 120), 1 + rng.uintLessThan(u16, 40)), 2, 3 => { const drawn = try r.places(); if (trace) std.debug.print(" {d} places, {d} placements, {d} images\n", .{ drawn.len, r.placementCount(0), r.storage(0).images.count() }); @@ -1224,7 +1224,7 @@ test "kitty: scrolled back by pardes, an image shows on its row; scrolled forwar r.feed(0, &nl); try std.testing.expectEqual(@as(usize, 0), (try r.placesOf(20)).len); // Back to the top of the history: the marker row is the body's first. - pardes.Term.scroll(pane.terminal.?, -1000); + pane.scrollBy(-1000); const o = r.origin(0); const drawn = try r.placesOf(20); try std.testing.expectEqual(@as(usize, 1), drawn.len); diff --git a/test/panes.zig b/test/panes.zig index 32cfd530..0a0bd3f9 100644 --- a/test/panes.zig +++ b/test/panes.zig @@ -965,7 +965,7 @@ test "terminal overlay recoloring never materializes unrelated history" { _ = try p.render(frame.allocator()); try testing.expect(p.shell_rows.pane == null); - pane.ovl.?.row = @intCast(pardes.Term.grid(pane.terminal).offset); + pane.ovl.?.row = @intCast(pane.termTop()); p.gpa.free(pane.ovl.?.text); pane.ovl.?.text = try p.gpa.dupe(u8, "caf\xc3\xa9 \xe7\x95\x8c"); _ = frame.reset(.retain_capacity); @@ -994,8 +994,8 @@ test "terminal output keeps following new rows after scrollback eviction" { for (0..3) |phase| { if (phase > 0) { pane.body.mode = .normal; - pardes.Term.scroll(pane.terminal.?, -30); - try std.testing.expect(pages.scrollbar().offset < pages.scrollbar().total - pane.rows); + pane.scrollBy(-30); + try std.testing.expect(pane.termTop() < pages.scrollbar().total - pane.rows); pardes.keys.enterTty(p, 0); } for (phase * 20_000..(phase + 1) * 20_000) |n| { @@ -1008,7 +1008,7 @@ test "terminal output keeps following new rows after scrollback eviction" { try std.testing.expect(evictions > phase); try std.testing.expect(pages.page_size <= pages.limits.max(.bytes)); const sb = pages.scrollbar(); - try std.testing.expectEqual(sb.total - pane.rows, sb.offset); + try std.testing.expectEqual(sb.total - pane.rows, pane.termTop()); const full = try pardes.Term.scrollback(pane.terminal, gpa); defer gpa.free(full); var last_buf: [16]u8 = undefined; @@ -2686,14 +2686,14 @@ const TerminalTests = struct { p.update(.{ .output = .{ .pane = .at(0), .bytes = bytes } }); } p.shell_rows.stale = true; - pardes.Term.scroll(pane.terminal.?, -20); + pane.scrollBy(-20); // ONE buffer line standing in for SIX shell rows: everything below slides // UP five, so the last rows of the body resolve past the viewport's bottom // edge. `PageList.pin` answers for those rows anyway — it walks down the // pagelist, not the viewport — so without a bound of its own this pass // painted the scrollback's colours onto rows the text pass left blank. - const anchor: i32 = @intCast(pardes.Term.grid(pane.terminal).offset); + const anchor: i32 = @intCast(pane.termTop()); pane.ovl = .{ .row = anchor, .rows = 6, .text = try p.gpa.dupe(u8, "one") }; p.shell_rows.stale = true; @@ -2958,7 +2958,7 @@ const TerminalTests = struct { // a buffer whose covered span STRADDLES the viewport top is an ordinary // state. tty mode does not apply the buffer, so it must not be moved by one // either — and `surfRow`/`gridRow` are not inverses across that span. - const anchor: i32 = @intCast(pardes.Term.grid(pane.terminal).offset); + const anchor: i32 = @intCast(pane.termTop()); pane.ovl = .{ .row = anchor - 1, .rows = 4, .text = try p.gpa.dupe(u8, "one\ntwo") }; p.shell_rows.stale = true; _ = frame.reset(.retain_capacity); diff --git a/test/perf.zig b/test/perf.zig index e9ee43d7..30e15dcc 100644 --- a/test/perf.zig +++ b/test/perf.zig @@ -1138,7 +1138,7 @@ fn measureTerminalSession(io: std.Io, mib: usize, reps: usize, json: bool) !void const begin = nowNs(); core.update(.{ .output = .{ .pane = .at(0), .bytes = update } }); pump(core); - const cursor_row = @as(i32, @intCast(pardes.Term.grid(pane.terminal).offset)) + @as(i32, pardes.Term.grid(pane.terminal).cursor_y); + const cursor_row = @as(i32, @intCast(pane.termTop())) + @as(i32, pardes.Term.grid(pane.terminal).cursor_y); pane.ovl.?.row = if (phase == 0) 0 else cursor_row - 1; pane.body.cur_row = pane.ovl.?.row; pane.body.cur_col = 0; diff --git a/test/replicas.zig b/test/replicas.zig index 90f7c10d..a68ce222 100644 --- a/test/replicas.zig +++ b/test/replicas.zig @@ -856,19 +856,18 @@ const Watchdog = struct { /// the untraced one. const Named = struct { const Parted = struct { c: usize, origin: u16, seq: u32, parts: []u64, terms: [pardes.MAX_PANES]Term }; - /// A terminal pane's: its screen's digest without its view and with - /// it, and where its view and cursor stand. - const Term = struct { content: u64 = 0, viewed: u64 = 0, grid: pardes.Term.Grid = .{} }; + /// A terminal pane's: its screen's digest, where the live view stands + /// in it (the pane's, `scrolled_to`), and its grid. + const Term = struct { content: u64 = 0, place: ?usize = null, grid: pardes.Term.Grid = .{} }; fn terms(p: *const pardes.Pardes) [pardes.MAX_PANES]Term { var out: [pardes.MAX_PANES]Term = @splat(.{}); for (p.panes, &out) |slot, *t| { - const state = (slot orelse continue).terminal orelse continue; + const pane = slot orelse continue; + const state = pane.terminal orelse continue; var a = pardes.walk.Hasher.init(0); - state.digestScreen(&a, false); - var b = pardes.walk.Hasher.init(0); - state.digestScreen(&b, true); - t.* = .{ .content = a.final(), .viewed = b.final(), .grid = pardes.Term.grid(state) }; + state.digest(&a); + t.* = .{ .content = a.final(), .place = pane.scrolled_to, .grid = pardes.Term.grid(state) }; } return out; } @@ -898,8 +897,8 @@ const Named = struct { const theirs = arena.allocator().create(pardes.tape.Parts) catch return; const want = pardes.tape.digestParts(rp.core(), theirs); w.print("seed {d} rtt {d} ms: client {d} names: at unit {d}/{d}, against the witness's replay: {s}\n", tag ++ .{ x.c + 1, u.origin, u.seq, pardes.tape.partsDiffer(x.parts, want, arena.allocator()) }) catch {}; - for (x.terms, terms(rp.core()), 0..) |a, b, id| if (a.viewed != b.viewed or a.content != b.content) { - w.print(" pane {d}'s terminal: content {s}, view {s}; the client's {any}; the witness's {any}\n", .{ id, if (a.content == b.content) "equal" else "DIFFERS", if (a.viewed == b.viewed) "equal" else "DIFFERS", a.grid, b.grid }) catch {}; + for (x.terms, terms(rp.core()), 0..) |a, b, id| if (a.place != b.place or a.content != b.content) { + w.print(" pane {d}'s terminal: content {s}, view {s}; the client's {any} at {?d}; the witness's {any} at {?d}\n", .{ id, if (a.content == b.content) "equal" else "DIFFERS", if (a.place == b.place) "equal" else "DIFFERS", a.grid, a.place, b.grid, b.place }) catch {}; }; }; } diff --git a/test/terminal.zig b/test/terminal.zig index 7e7106a1..bad70081 100644 --- a/test/terminal.zig +++ b/test/terminal.zig @@ -25,7 +25,6 @@ const close = Term.close; const grid = Term.grid; const modes = Term.modes; const prompt = Term.prompt; -const scroll = Term.scroll; const scrollback = Term.scrollback; const commandOutput = Term.commandOutput; const filterOf = emu.filterOf; @@ -110,7 +109,7 @@ test "document construction allocates only the pane and has inert terminal defau try std.testing.expectEqual(Term.Prompt{}, prompt(pane.terminal)); pane.scrollBy(100); pane.followOutput(); - pane.resizeGrid(80, 24); + pane.resizeGrid(0, 80, 24); try std.testing.expectEqual(Term.Grid{}, grid(pane.terminal)); try std.testing.expectEqualStrings("", try scrollback(pane.terminal, allocator)); try std.testing.expect(!failing.has_induced_failure); @@ -139,7 +138,7 @@ test "terminal state keeps parser fragments and sends emulator replies through i try std.testing.expectEqual(@as(u16, 0), state.reply_len); } -test "a terminal's dump restores the cells it drew, its history and where its view was" { +test "a terminal's dump restores the cells it drew and its history (where a view stands is the view's, dumped with its pane)" { const gpa = std.testing.allocator; const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 40, .rows = 12 }); defer p.deinit(); @@ -150,7 +149,6 @@ test "a terminal's dump restores the cells it drew, its history and where its vi var line: [16]u8 = undefined; pane.feedOutput(p, std.fmt.bufPrint(&line, "line {d}\r\n", .{i}) catch unreachable); } - scroll(pane.terminal.?, -5); const bytes = try pardes.walk.save(State, gpa, pane.terminal.?); defer gpa.free(bytes); var arena: std.heap.ArenaAllocator = .init(gpa); -- cgit v1.3