summaryrefslogtreecommitdiff
path: root/core/views.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-22 17:55:03 -0300
committerGabriel Schneider <[email protected]>2026-11-22 19:48:03 -0300
commit8e850e6c923dcd84b7a5483f73377bd192b94a2b (patch)
tree0730a84095f75d8a46e4dcdfebddb8d8b90af7c6 /core/views.zig
parentbad506bd45846e012246a33b5d3097b3e92f02bc (diff)
downloadpardes-8e850e6c923dcd84b7a5483f73377bd192b94a2b.tar.gz
pardes-8e850e6c923dcd84b7a5483f73377bd192b94a2b.zip
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 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
Diffstat (limited to 'core/views.zig')
-rw-r--r--core/views.zig55
1 files changed, 52 insertions, 3 deletions
diff --git a/core/views.zig b/core/views.zig
index 663610c3..f414eb6c 100644
--- a/core/views.zig
+++ b/core/views.zig
@@ -38,9 +38,10 @@ pub const max = 4;
pub const away_kept_ns: u64 = 30 * std.time.ns_per_s;
/// A pane's fields that are each view's own: where it is in the view's
-/// layout, which of its texts has the keyboard, how far it is scrolled, and
-/// what the view's step measured of it (its tag's rows, its bands).
-const pane_fields = [_][:0]const u8{ "focus", "vweight", "collapsed", "docked_to", "hscroll", "tag_scroll", "tag_top", "tag_rows", "view", "layers", "notices", "pan", "follow_scroll" };
+/// layout, which of its texts has the keyboard, how far it is scrolled (a
+/// terminal's history too), and what the view's step measured of it (its
+/// tag's rows, its bands).
+const pane_fields = [_][:0]const u8{ "focus", "vweight", "collapsed", "docked_to", "hscroll", "tag_scroll", "tag_top", "tag_rows", "view", "layers", "notices", "pan", "follow_scroll", "scrolled_to" };
/// The body's: its cursor, selections and mode. Its undo stays the pane's.
const body_fields = [_][:0]const u8{ "mode", "cur_pinned", "cur_row", "cur_col", "vsel", "sels", "nsel", "select", "sticky_col", "restore_cursor", "last_edit", "reg_wait", "normal", "find_op", "find_ch" };
@@ -60,6 +61,7 @@ pub const PaneView = struct {
notices: Pane.Notices = .{},
pan: u16 = 0,
follow_scroll: usize = 0,
+ scrolled_to: ?usize = null,
body: Part(Text, &body_fields) = .{},
/// A document's scroll and size; a terminal's size is its pty's, which
/// every view shows (sized by its last typist, `Pardes.sync`).
@@ -944,6 +946,53 @@ test "a terminal shown in a view shorter than it keeps its cursor in sight" {
try testing.expectEqual(@as(u16, 0), term.pan);
}
+test "each view has its own place in a terminal's history: a wheel in one scrolls it back, the other stays on the output and follows it" {
+ if (pardes.Term.ops == null) return error.SkipZigTest; // a shell
+ const gpa = testing.allocator;
+ const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 80, .rows = 24 });
+ defer p.deinit();
+ const id = p.view().active;
+ const term = p.panes[id].?;
+ var out: std.ArrayList(u8) = .empty;
+ defer out.deinit(gpa);
+ for (0..100) |i| try out.print(gpa, "line-{d}\r\n", .{i});
+ p.update(.{ .output = .{ .pane = .at(id), .bytes = out.items } });
+ p.sync();
+ const bottom = term.scroll();
+ try testing.expect(bottom > 0);
+ const k = p.openView().?;
+ p.toView(k);
+ const r = p.view().rects[id];
+ const at = .{ .col = r.x + r.w / 2, .row = p.bodyTop(term, r) + 1 };
+ for (0..3) |_| p.update(.{ .mouse = .{ .button = .wheel_up, .kind = .press, .col = at.col, .row = at.row } });
+ p.sync();
+ const back = term.scroll();
+ try testing.expect(back < bottom);
+ // The session's view is where it was: on the output.
+ p.toView(.at(0));
+ p.sync();
+ try testing.expectEqual(bottom, term.scroll());
+ // Output comes: the view on the output follows it, the one scrolled
+ // back stays on its row.
+ p.update(.{ .output = .{ .pane = .at(id), .bytes = "more-1\r\nmore-2\r\n" } });
+ p.sync();
+ try testing.expectEqual(bottom + 2, term.scroll());
+ p.toView(k);
+ p.sync();
+ try testing.expectEqual(back, term.scroll());
+ // A session's dump keeps each view's place.
+ const bytes = try pardes.dump.dumpBytes(p);
+ defer gpa.free(bytes);
+ const loaded = try pardes.dump.load(gpa, .{ .tty_only = true, .cols = 80, .rows = 24 }, bytes, null);
+ defer loaded.deinit();
+ try testing.expectEqual(pardes.walk.digest(Pardes, p), pardes.walk.digest(Pardes, loaded));
+ const lt = loaded.panes[id].?;
+ loaded.toView(k);
+ try testing.expectEqual(back, lt.scroll());
+ loaded.toView(.at(0));
+ try testing.expectEqual(bottom + 2, lt.scroll());
+}
+
test "a session's dump keeps its views: loaded, each where it was; revived for one client, the live one alone" {
const gpa = testing.allocator;
const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 80, .rows = 24 });