summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-21 16:16:43 -0300
committerGabriel Schneider <[email protected]>2026-11-21 19:06:13 -0300
commit78aa898cf2a55c5e4e78d968b37388e0cbc6e2d2 (patch)
tree36808a2980b3f7165a1480259330cfb7d745eaa4 /core
parent49f3522b6421a634b7271a5244b6dde43104aa3b (diff)
downloadpardes-78aa898cf2a55c5e4e78d968b37388e0cbc6e2d2.tar.gz
pardes-78aa898cf2a55c5e4e78d968b37388e0cbc6e2d2.zip
terminals' views: the bytes soak's divergence (a client's terminal view one row above the session's, at its history's top, 5 whole runs of 29 in round 5) fails on purpose, without a soak, in two tests: at the terminal module, a view on a wrapped line's second row, joined into the row above by a widening (ghostty's view is a pinned CELL, now mid-row at row 0) and put back at the row it reports (`viewTo(grid.view)`, as a replica's rollback puts views back, replica.zig `putViews`: at row 0 that is ghostty's `.top`) is another view after the narrowing back (expected 1, found 0: the soak's sign); at the replica's surface (an Authority and a Replica, bytes), the session's frontend widens the shell with its view there, a key of the client's is rolled back under the session's (the copy put back, `putViews`), the session narrows again: the digests part on the terminal's view (17455102819691583991 against 7777253998216201365); found by a probe ring of pane 0's view at every engine step in the soak's clients against the witness (b7b-4: put back to row 0, then the next reflow moved the witness's view and not the client's) and a fuzz of put-back against left-alone terminals under random output, reflows and scrolls (5 apart in 191 seeds); both fail on this change, the next one fixes them
Co-Authored-By: Claude Opus <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
Diffstat (limited to 'core')
-rw-r--r--core/replica.zig34
-rw-r--r--core/term/terminal.zig21
2 files changed, 55 insertions, 0 deletions
diff --git a/core/replica.zig b/core/replica.zig
index ced4329d..fa9a0fda 100644
--- a/core/replica.zig
+++ b/core/replica.zig
@@ -4692,6 +4692,40 @@ test "bytes: a session's output that moves nothing the digest covers (a colour s
try sameTerminals(b.a, b.r);
}
+test "bytes: a terminal's view a rollback puts back is the session's through a reflow: a view on a wrapped line's second row, joined into the row above by the session's widening, is the same row after its narrowing on every side" {
+ if (pardes.Term.ops == null) return error.SkipZigTest; // a shell
+ const b = try BytesPair.init();
+ defer b.deinit();
+ const id = b.shell.index();
+ // Lines a row and a half long, the view on the first's second row (put
+ // there alike on both sides: no step of either moved it).
+ const cols = pardes.Term.grid(b.a.core.panes[id].?.terminal).cols;
+ var line: [512]u8 = undefined;
+ const text = line[0 .. cols + cols / 2];
+ @memset(text, 'x');
+ b.a.output(.{ .output = .{ .pane = b.shell, .bytes = "\x1bc" } });
+ for (0..40) |_| {
+ b.a.output(.{ .output = .{ .pane = b.shell, .bytes = text } });
+ b.a.output(.{ .output = .{ .pane = b.shell, .bytes = "\r\n" } });
+ }
+ b.r.confirm((try b.a.pending()).?);
+ b.r.settle();
+ for ([_]*Pardes{ b.a.core, b.r.core() }) |core| pardes.Term.viewTo(core.panes[id].?.terminal.?, 1);
+ // The session's frontend widens: the line one row, the view at row 0,
+ // its cell mid-row.
+ b.r.confirm(try b.a.own(.{ .resize = .{ .cols = 200, .rows = 24 } }));
+ b.r.settle();
+ try agrees(b.a, b.r);
+ try std.testing.expectEqual(@as(?usize, 0), pardes.Term.grid(b.a.core.panes[id].?.terminal).view);
+ // A key of the client's on top, the session's first: the copy put back.
+ try b.rollback();
+ try agrees(b.a, b.r);
+ // The session narrows again: every side's view the same row.
+ b.r.confirm(try b.a.own(.{ .resize = .{ .cols = 80, .rows = 24 } }));
+ b.r.settle();
+ try agrees(b.a, b.r);
+}
+
test "bytes: a mouse motion a speculation told a terminal's program is told again when its input is replayed: the cell last told is the pane's, put back with it" {
if (pardes.Term.ops == null) return error.SkipZigTest; // a shell
const gpa = std.testing.allocator;
diff --git a/core/term/terminal.zig b/core/term/terminal.zig
index 1673a3d8..535ca6dc 100644
--- a/core/term/terminal.zig
+++ b/core/term/terminal.zig
@@ -1591,6 +1591,27 @@ pub fn images(state: *State, gpa: std.mem.Allocator, at: ImagesAt, out: *std.Arr
state.images.draw(state.gpa, gpa, &state.vt, at, rows_of[0..vp_rows], out, frame, frame_cols);
}
+test "a view put back at the row it reports is the view it was, through a reflow: a view on a wrapped line's second row, joined into the row above by a widening and parted again by a narrowing, is the same row put back or not" {
+ // The bytes soak's divergence (reports/pardes-term-join-6.md): a
+ // client's rollback puts each terminal's view back at its row
+ // (core/replica.zig `putViews`), and ghostty's view is a cell, which
+ // a widening leaves mid-row and the next narrowing carries a row down.
+ const gpa = std.testing.allocator;
+ const left = try open(gpa, 20, 2);
+ defer close(left);
+ const put = try open(gpa, 20, 2);
+ defer close(put);
+ for ([_]*State{ left, put }) |s| {
+ // Lines two rows long at 20 columns, one at 40.
+ for (0..30) |_| ingest(s, "abcdefghijklmnopqrstuvwxyz0123\r\n");
+ viewTo(s, 1);
+ resize(s, 40, 2, false);
+ }
+ viewTo(put, grid(put).view);
+ for ([_]*State{ left, put }) |s| resize(s, 20, 2, false);
+ try std.testing.expectEqual(grid(left), grid(put));
+}
+
test "the luminance table answers exactly what ghostty computes" {
for (0..256) |i| {
const c: u8 = @intCast(i);