diff options
| author | Gabriel Schneider <[email protected]> | 2026-09-29 18:14:31 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-10-01 00:12:17 -0300 |
| commit | b8b9e87972f87abd28c5bebf7275e9bdd2754eac (patch) | |
| tree | 711ba91eec06d7cdb2d5f93b401ba10657df1a0c /test/snapshot.zig | |
| parent | 2d007737eb6f7f8e48bf6500e19ed44e62df5aa7 (diff) | |
| download | pardes-b8b9e87972f87abd28c5bebf7275e9bdd2754eac.tar.gz pardes-b8b9e87972f87abd28c5bebf7275e9bdd2754eac.zip | |
Snapshots leave out a blank cell's ink, which shows nowhere and the tty now keeps from the frame before
Diffstat (limited to 'test/snapshot.zig')
| -rw-r--r-- | test/snapshot.zig | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/test/snapshot.zig b/test/snapshot.zig index c49e7645..0514d8d8 100644 --- a/test/snapshot.zig +++ b/test/snapshot.zig @@ -1330,9 +1330,28 @@ fn styleRows(arena: std.mem.Allocator, h: *eh.Harness) ![]const []const u8 { var run_key: [64]u8 = undefined; var run_len: usize = 0; var run_start: u16 = 0; + // A blank's ink shows nowhere, and the tty leaves whatever ink the + // terminal had there (tty.zig blankInk), so it depends on the frames + // before: a blank is written with the ink of the cell before it. + var ink_buf: [16]u8 = undefined; + var ink: []const u8 = "d"; var x: u16 = 0; while (x <= h.cols) : (x += 1) { - const key: []const u8 = if (x == h.cols) "\x00end" else cellKey(h, x, y, &key_buf); + var key: []const u8 = if (x == h.cols) "\x00end" else cellKey(h, x, y, &key_buf); + if (x < h.cols) { + const comma = std.mem.indexOfScalar(u8, key, ',') orelse key.len; + if (inklessBlank(h, x, y)) { + var joined: [64]u8 = undefined; + const rest = key[comma..]; + @memcpy(joined[0..ink.len], ink); + @memcpy(joined[ink.len..][0..rest.len], rest); + @memcpy(key_buf[0 .. ink.len + rest.len], joined[0 .. ink.len + rest.len]); + key = key_buf[0 .. ink.len + rest.len]; + } else { + @memcpy(ink_buf[0..comma], key[0..comma]); + ink = ink_buf[0..comma]; + } + } if (x == 0) { @memcpy(run_key[0..key.len], key); run_len = key.len; @@ -1350,6 +1369,16 @@ fn styleRows(arena: std.mem.Allocator, h: *eh.Harness) ![]const []const u8 { return out; } +/// A cell whose ink shows nowhere: no text but a space, and no underline, +/// strike or reverse to draw with it. +fn inklessBlank(h: *eh.Harness, x: u16, y: u16) bool { + const ci = h.term.screens.active.pages.getCell(.{ .viewport = .{ .x = x, .y = y } }) orelse return false; + if (ci.cell.wide == .spacer_tail) return false; + if (ci.cell.hasText() and ci.cell.codepoint() != ' ') return false; + const flags = ci.style().flags; + return !flags.inverse and !flags.strikethrough and flags.underline == .none; +} + fn cellKey(h: *eh.Harness, x: u16, y: u16, buf: *[64]u8) []const u8 { const ci = h.term.screens.active.pages.getCell(.{ .viewport = .{ .x = x, .y = y } }) orelse return "d,d,"; if (ci.cell.wide == .spacer_tail) return "d,d,"; |
