summaryrefslogtreecommitdiff
path: root/test/terminal.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-19 20:31:32 -0300
committerGabriel Schneider <[email protected]>2026-11-19 20:31:32 -0300
commit0db34fbf28e70c8c6a3c6025c0888fc5ec75201c (patch)
treef2e288668decded9276ebc45907f16d651b06f9e /test/terminal.zig
parent2ab05b536bc3b063666b5aaab497157adc2a9120 (diff)
parentbf351b62e8843a3d173cedeefa2dd0b8ef4b4392 (diff)
downloadpardes-0db34fbf28e70c8c6a3c6025c0888fc5ec75201c.tar.gz
pardes-0db34fbf28e70c8c6a3c6025c0888fc5ec75201c.zip
integration: a pane's and a view's slot as types, with the regular-expression fixes and the fixes the real loops asked for: pardes-ids (Pane.Id and View.Id through the entries, the events, the effects, the Host table and the device messages) and pardes-merge21, merged without a textual conflict; one call site written since on the old type follows (core/draw.zig: the twin test's file_changed event, .pane = .at(0)); tui core-test 848/991 (143 skipped), shell-test 1027/1030, the window builds; gates in the coordinator's ledger
Co-Authored-By: Claude Fable 5.2 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
Diffstat (limited to 'test/terminal.zig')
-rw-r--r--test/terminal.zig72
1 files changed, 36 insertions, 36 deletions
diff --git a/test/terminal.zig b/test/terminal.zig
index fafaa605..e6c530d5 100644
--- a/test/terminal.zig
+++ b/test/terminal.zig
@@ -57,7 +57,7 @@ fn ptyWritesByPane(p: *Pardes, out: *std.ArrayList(u8)) ![]const u8 {
var per: [pardes.MAX_PANES]std.ArrayList(u8) = @splat(.empty);
defer for (&per) |*b| b.deinit(p.gpa);
while (p.nextEffect()) |effect| {
- if (effect == .write) try per[effect.write.pane].appendSlice(p.gpa, effect.write.bytes.slice());
+ if (effect == .write) try per[effect.write.pane.index()].appendSlice(p.gpa, effect.write.bytes.slice());
}
for (per, 0..) |b, id| if (b.items.len > 0) try out.print(p.gpa, "{d}:{s}\n", .{ id, b.items });
return out.items;
@@ -163,15 +163,15 @@ test "terminal state keeps parser fragments and sends emulator replies through i
const pane = p.panes[0].?;
const state = of(pane.terminal.?);
try std.testing.expect(state.stream.handler.inner.terminal == &state.vt);
- p.update(.{ .output = .{ .pane = 0, .bytes = "\x1b[" } });
+ p.update(.{ .output = .{ .pane = .at(0), .bytes = "\x1b[" } });
while (p.nextEffect()) |effect| {
if (effect == .write) return error.PrematureTerminalReply;
}
- p.update(.{ .output = .{ .pane = 0, .bytes = "6n" } });
+ p.update(.{ .output = .{ .pane = .at(0), .bytes = "6n" } });
var answers: usize = 0;
while (p.nextEffect()) |effect| {
if (effect != .write) continue;
- try std.testing.expectEqual(@as(u8, 0), effect.write.pane);
+ try std.testing.expectEqual(0, effect.write.pane.index());
try std.testing.expectEqualStrings("\x1b[1;1R", effect.write.bytes.slice());
answers += 1;
}
@@ -212,7 +212,7 @@ test "a restored command pane comes back finished, its command not run again" {
const cmd = p.freeSlot().?;
_ = try panes.newCommand(p, cmd, "/tmp", "make test");
p.panes[cmd].?.feedOutput(p, "ok\r\n");
- p.update(.{ .exited = .{ .pane = @intCast(cmd), .status = 2 } });
+ p.update(.{ .exited = .{ .pane = .at(cmd), .status = 2 } });
try pardes.dump.dumpState(p);
const restored = try pardes.dump.initFromDump(gpa, .{ .tty_only = true, .cols = 60, .rows = 16 }, p.dump_out.?);
defer restored.deinit();
@@ -248,7 +248,7 @@ test "a restored terminal keeps its history above a marker and gets a shell wher
defer restored.deinit();
var spawned = false;
while (restored.nextEffect()) |effect| switch (effect) {
- .spawn => |sp| spawned = sp.pane == 0 and std.mem.eql(u8, sp.cwd.slice(), "/tmp"),
+ .spawn => |sp| spawned = sp.pane.index() == 0 and std.mem.eql(u8, sp.cwd.slice(), "/tmp"),
else => {},
};
try std.testing.expect(spawned);
@@ -323,7 +323,7 @@ test "terminal Filter keys indexed truecolor OSC and background-only cells throu
try testing.expect(pane.tty_filter);
pane.tty_filter = false;
- p.update(.{ .output = .{ .pane = 0, .bytes = "\x1b[31mA" ++
+ p.update(.{ .output = .{ .pane = .at(0), .bytes = "\x1b[31mA" ++
"\x1b[38;5;196mB" ++
"\x1b[38;2;255;0;0mC" ++
"\x1b[0;48;5;25mD" ++
@@ -384,7 +384,7 @@ test "terminal Filter keys indexed truecolor OSC and background-only cells throu
}
}
- p.update(.{ .output = .{ .pane = 0, .bytes = "\x1b]4;1;#ff0000\x1b\\" } });
+ p.update(.{ .output = .{ .pane = .at(0), .bytes = "\x1b]4;1;#ff0000\x1b\\" } });
const osc_red = of(pane.terminal.?).vt.colorForXterm(.{ .palette = 1 }).?;
try testing.expect(osc_red.eql(.{ .r = 255, .g = 0, .b = 0 }));
pane.tty_filter = false;
@@ -396,7 +396,7 @@ test "terminal Filter keys indexed truecolor OSC and background-only cells throu
// Dynamic default foreground/background colours key every default cell,
// including the otherwise blank end of the row.
- p.update(.{ .output = .{ .pane = 0, .bytes = "\x1b]10;#ff0000\x1b\\" ++
+ p.update(.{ .output = .{ .pane = .at(0), .bytes = "\x1b]10;#ff0000\x1b\\" ++
"\x1b]11;#5f5f5f\x1b\\" } });
const dyn_fg = of(pane.terminal.?).vt.colorForXterm(.{ .dynamic = .foreground }).?;
const dyn_bg = of(pane.terminal.?).vt.colorForXterm(.{ .dynamic = .background }).?;
@@ -410,7 +410,7 @@ test "terminal Filter keys indexed truecolor OSC and background-only cells throu
const explicit_before_reverse = dynamic.at(tx, body_y).style.fg;
try testing.expectEqual(asPardesColor(asGhostRgb(expected[196])), explicit_before_reverse);
- p.update(.{ .output = .{ .pane = 0, .bytes = "\x1b[?5h" } });
+ p.update(.{ .output = .{ .pane = .at(0), .bytes = "\x1b[?5h" } });
_ = frame.reset(.retain_capacity);
const reversed = try p.render(frame.allocator());
const reversed_blank = reversed.at(tx + r.w - config.GUTTER - 1, body_y + 2).style;
@@ -421,7 +421,7 @@ test "terminal Filter keys indexed truecolor OSC and background-only cells throu
try testing.expectEqual(plain.Color{ .rgb = p.theme().bg.? }, reversed_explicit.fg);
try testing.expect(!std.meta.eql(reversed_explicit.fg, reversed_explicit.bg));
- p.update(.{ .output = .{ .pane = 0, .bytes = "\x1b[?5l" } });
+ p.update(.{ .output = .{ .pane = .at(0), .bytes = "\x1b[?5l" } });
_ = frame.reset(.retain_capacity);
const unreversed = try p.render(frame.allocator());
const unreversed_blank = unreversed.at(tx + r.w - config.GUTTER - 1, body_y + 2).style;
@@ -430,7 +430,7 @@ test "terminal Filter keys indexed truecolor OSC and background-only cells throu
// The cache is keyed by values, not a theme name. Replacing a custom
// theme in place immediately recolours already-rendered indexed cells.
- p.update(.{ .output = .{ .pane = 0, .bytes = "\x1b]104;1\x1b\\" } });
+ p.update(.{ .output = .{ .pane = .at(0), .bytes = "\x1b]104;1\x1b\\" } });
var custom = p.theme().*;
custom.name = try p.gpa.dupe(u8, "same-name");
custom.palette = null;
@@ -482,7 +482,7 @@ test "terminal Filter preserves exact palette-null light theme default roles" {
try testing.expectEqual(plain.Color{ .rgb = light.fg.? }, ordinary.at(tx, body_y).style.fg);
try testing.expectEqual(plain.Color{ .rgb = light.bg.? }, ordinary.at(tx, body_y).style.bg);
- p.update(.{ .output = .{ .pane = 0, .bytes = "\x1b[?5h" } });
+ p.update(.{ .output = .{ .pane = .at(0), .bytes = "\x1b[?5h" } });
_ = frame.reset(.retain_capacity);
const reversed = try p.render(frame.allocator());
try testing.expectEqual(plain.Color{ .rgb = light.bg.? }, reversed.at(tx, body_y).style.fg);
@@ -514,7 +514,7 @@ test "terminal Filter maps the default roles before it maps anything else" {
}
p.settings.theme = 0;
- p.update(.{ .output = .{ .pane = 0, .bytes = "\x1b]11;#5f5f5f\x1b\\" } });
+ p.update(.{ .output = .{ .pane = .at(0), .bytes = "\x1b]11;#5f5f5f\x1b\\" } });
var moved = filterOf(&ansi.inkOf(p.theme()), &p.tty_filter_palette, &of(pane.terminal.?).vt);
try testing.expect(!asGhostRgb(moved.default_bg).eql(asGhostRgb(moved.theme_bg)));
try testing.expect(asGhostRgb(moved.default_bg).eql(keyedRgb(&moved, .{ .r = 0x5f, .g = 0x5f, .b = 0x5f })));
@@ -528,7 +528,7 @@ test "terminal Filter refuses a foreground that would collapse onto the page" {
const pane = p.panes[0].?;
try testing.expect(pane.tty_filter);
- p.update(.{ .output = .{ .pane = 0, .bytes = "\x1b[38;2;255;255;255mW" ++
+ p.update(.{ .output = .{ .pane = .at(0), .bytes = "\x1b[38;2;255;255;255mW" ++
"\x1b[0;30mB" ++
"\x1b[0;31mR" } });
@@ -623,7 +623,7 @@ test "tty ansi colors follow the prompt hug into normal mode" {
const pane = p.panes[0].?;
pane.tty_filter = false;
- p.update(.{ .output = .{ .pane = 0, .bytes = "\x1b]133;A\x1b\\\x1b[32mPP\x1b]133;B\x1b\\\x1b[31mR\x1b[34mB\x1b[0m out" } });
+ p.update(.{ .output = .{ .pane = .at(0), .bytes = "\x1b]133;A\x1b\\\x1b[32mPP\x1b]133;B\x1b\\\x1b[31mR\x1b[34mB\x1b[0m out" } });
var frame = std.heap.ArenaAllocator.init(testing.allocator);
defer frame.deinit();
@@ -660,7 +660,7 @@ test "a prompt row hidden end to end paints nothing at all" {
p.sync();
pane.tty_filter = false;
pane.body.mode = .normal;
- p.update(.{ .output = .{ .pane = 0, .bytes = "\x1b]133;A\x1b\\\x1b[32maaaaaaaaa\x1b]133;B\x1b\\\x1b[41;36m\u{754C}\x1b[0m\r\n" } });
+ p.update(.{ .output = .{ .pane = .at(0), .bytes = "\x1b]133;A\x1b\\\x1b[32maaaaaaaaa\x1b]133;B\x1b\\\x1b[41;36m\u{754C}\x1b[0m\r\n" } });
var frame = std.heap.ArenaAllocator.init(testing.allocator);
defer frame.deinit();
@@ -686,9 +686,9 @@ test "a program that asked for focus reports hears CSI I and CSI O as its pane t
_ = try ptyWritesByPane(p, &out);
p.view().active = 0;
// Asking while its pane has the keyboard: told at once that it has.
- p.update(.{ .output = .{ .pane = 0, .bytes = "\x1b[?1004h" } });
+ p.update(.{ .output = .{ .pane = .at(0), .bytes = "\x1b[?1004h" } });
try std.testing.expectEqualStrings("0:\x1b[I\n", try ptyWritesByPane(p, &out));
- p.update(.{ .output = .{ .pane = 1, .bytes = "\x1b[?1004h" } });
+ p.update(.{ .output = .{ .pane = .at(1), .bytes = "\x1b[?1004h" } });
try std.testing.expectEqualStrings("", try ptyWritesByPane(p, &out));
// A click into the other pane moves the keyboard: out of one, into the
// other.
@@ -724,7 +724,7 @@ test "a terminal's kitty graphics image is drawn where its program placed it, an
defer frame.deinit();
const pane = p.panes[0].?;
pane.body.mode = .tty;
- p.update(.{ .output = .{ .pane = 0, .bytes = "\x1b[3;5H" ++ kittyTransmit("c=2,r=1") } });
+ p.update(.{ .output = .{ .pane = .at(0), .bytes = "\x1b[3;5H" ++ kittyTransmit("c=2,r=1") } });
var s = try p.render(frame.allocator());
const places = imagePlaces(s);
try std.testing.expectEqual(@as(usize, 1), places.len);
@@ -740,20 +740,20 @@ test "a terminal's kitty graphics image is drawn where its program placed it, an
try std.testing.expectEqual(plain.RectPx{ .x = 0, .y = 0, .w = 20, .h = 20 }, place.at.?);
// Scrolled up by the shell's output, it goes up with the text.
- p.update(.{ .output = .{ .pane = 0, .bytes = "\x1b[24;1H\n\n" } });
+ p.update(.{ .output = .{ .pane = .at(0), .bytes = "\x1b[24;1H\n\n" } });
_ = frame.reset(.retain_capacity);
s = try p.render(frame.allocator());
try std.testing.expectEqual(p.bodyTop(pane, r), imagePlaces(s)[0].dst.y);
- p.update(.{ .output = .{ .pane = 0, .bytes = "\n" } });
+ p.update(.{ .output = .{ .pane = .at(0), .bytes = "\n" } });
_ = frame.reset(.retain_capacity);
s = try p.render(frame.allocator());
try std.testing.expectEqual(@as(usize, 0), imagePlaces(s).len);
- p.update(.{ .output = .{ .pane = 0, .bytes = "\x1b[1;1H" ++ kittyTransmit("c=2,r=1") } });
+ p.update(.{ .output = .{ .pane = .at(0), .bytes = "\x1b[1;1H" ++ kittyTransmit("c=2,r=1") } });
_ = frame.reset(.retain_capacity);
s = try p.render(frame.allocator());
try std.testing.expectEqual(@as(usize, 1), imagePlaces(s).len);
- p.update(.{ .output = .{ .pane = 0, .bytes = "\x1b_Ga=d,d=A\x1b\\" } });
+ p.update(.{ .output = .{ .pane = .at(0), .bytes = "\x1b_Ga=d,d=A\x1b\\" } });
_ = frame.reset(.retain_capacity);
s = try p.render(frame.allocator());
try std.testing.expectEqual(@as(usize, 0), imagePlaces(s).len);
@@ -770,15 +770,15 @@ test "ED 3 takes away a kitty placement whose row it erased: it never comes back
defer frame.deinit();
const pane = p.panes[0].?;
pane.body.mode = .tty;
- p.update(.{ .output = .{ .pane = 0, .bytes = "\x1b[1;1H" ++ kittyTransmit("c=2,r=1") } });
+ p.update(.{ .output = .{ .pane = .at(0), .bytes = "\x1b[1;1H" ++ kittyTransmit("c=2,r=1") } });
const storage = &of(pane.terminal.?).vt.screens.active.kitty_images;
try std.testing.expectEqual(@as(usize, 1), storage.placements.count());
// Scrolled into the history, it is not on screen; `clear` (ED 2 then
// ED 3) erases that history and the placement with it.
- p.update(.{ .output = .{ .pane = 0, .bytes = &lineBreaks(40) } });
+ p.update(.{ .output = .{ .pane = .at(0), .bytes = &lineBreaks(40) } });
var s = try p.render(frame.allocator());
try std.testing.expectEqual(@as(usize, 0), imagePlaces(s).len);
- p.update(.{ .output = .{ .pane = 0, .bytes = "\x1b[H\x1b[2J\x1b[3J" } });
+ p.update(.{ .output = .{ .pane = .at(0), .bytes = "\x1b[H\x1b[2J\x1b[3J" } });
try std.testing.expectEqual(@as(usize, 0), storage.placements.count());
_ = frame.reset(.retain_capacity);
s = try p.render(frame.allocator());
@@ -791,7 +791,7 @@ test "a finished command's output erased by a later ED 3 is not called whole, an
defer p.deinit();
const pane = p.panes[0].?;
const marked = "\x1b]133;A;cl=line;aid=pardes\x07$ \x1b]133;B;aid=pardes\x07";
- p.update(.{ .output = .{ .pane = 0, .bytes = marked ++ "\r\n\x1b]133;C;aid=pardes\x07printed\r\n\x1b]133;D;0;aid=pardes\x07" ++ marked } });
+ p.update(.{ .output = .{ .pane = .at(0), .bytes = marked ++ "\r\n\x1b]133;C;aid=pardes\x07printed\r\n\x1b]133;D;0;aid=pardes\x07" ++ marked } });
const before = try commandOutput(pane.terminal, gpa, 100);
defer gpa.free(before.text);
try std.testing.expect(before.whole);
@@ -799,8 +799,8 @@ test "a finished command's output erased by a later ED 3 is not called whole, an
// The command's rows go into the history, and ED 3 erases them: its
// pins are `garbage` now (ghostty 1.4), not moved to the screen's top,
// where another program's text would be read as its output.
- p.update(.{ .output = .{ .pane = 0, .bytes = &lineBreaks(20) } });
- p.update(.{ .output = .{ .pane = 0, .bytes = "\x1b[3J" } });
+ p.update(.{ .output = .{ .pane = .at(0), .bytes = &lineBreaks(20) } });
+ p.update(.{ .output = .{ .pane = .at(0), .bytes = "\x1b[3J" } });
const after = try commandOutput(pane.terminal, gpa, 100);
defer gpa.free(after.text);
try std.testing.expect(!after.whole);
@@ -814,13 +814,13 @@ test "a selection whose row ED 3 erased goes; one on the screen stays" {
defer p.deinit();
const pane = p.panes[0].?;
pane.body.mode = .tty;
- p.update(.{ .output = .{ .pane = 0, .bytes = &lineBreaks(20) } });
+ p.update(.{ .output = .{ .pane = .at(0), .bytes = &lineBreaks(20) } });
pane.body.mode = .normal;
const pages = &of(pane.terminal.?).vt.screens.active.pages;
const top: i32 = @intCast(pages.total_rows - pane.rows);
const row: i32 = if (in_history) top - 3 else top + 2;
pane.body.vsel = .{ .active = true, .row = row, .col = 1 };
- p.update(.{ .output = .{ .pane = 0, .bytes = "\x1b[3J" } });
+ p.update(.{ .output = .{ .pane = .at(0), .bytes = "\x1b[3J" } });
try std.testing.expectEqual(!in_history, pane.body.vsel.active);
if (!in_history) try std.testing.expectEqual(@as(i32, 2), pane.body.vsel.row);
}
@@ -840,7 +840,7 @@ test "a virtual kitty placement shows through its placeholder cells, which draw
// yazi's way: a virtual placement two cells by one, then the two
// placeholders, the image's id in their colour, row and column in
// their diacritics.
- p.update(.{ .output = .{ .pane = 0, .bytes = kittyTransmit("U=1,c=2,r=1,q=2") ++
+ p.update(.{ .output = .{ .pane = .at(0), .bytes = kittyTransmit("U=1,c=2,r=1,q=2") ++
"\x1b[2;3H\x1b[38;2;0;0;7m\u{10EEEE}\u{0305}\u{0305}\u{10EEEE}\u{0305}\u{030D}\x1b[39mX" } });
const s = try p.render(frame.allocator());
const places = imagePlaces(s);
@@ -864,7 +864,7 @@ test "a terminal's image is a placement whatever the frontend draws, and the Pet
defer frame.deinit();
const pane = p.panes[0].?;
pane.body.mode = .tty;
- p.update(.{ .output = .{ .pane = 0, .bytes = kittyTransmit("c=2,r=1") } });
+ p.update(.{ .output = .{ .pane = .at(0), .bytes = kittyTransmit("c=2,r=1") } });
const r = p.view().rects[0];
const tx = r.x + config.GUTTER;
const y = p.bodyTop(pane, r);
@@ -921,7 +921,7 @@ test "a program asking the cell size in pixels (CSI 16 t) is told the shell's" {
var out: std.ArrayList(u8) = .empty;
defer out.deinit(gpa);
_ = try ptyWritesByPane(p, &out);
- p.update(.{ .output = .{ .pane = 0, .bytes = "\x1b[16t" } });
+ p.update(.{ .output = .{ .pane = .at(0), .bytes = "\x1b[16t" } });
try std.testing.expectEqualStrings("0:\x1b[6;20;10t\n", try ptyWritesByPane(p, &out));
}
@@ -960,7 +960,7 @@ test "a replica's terminal pane draws as its authority's does" {
var line: [256]u8 = undefined;
for (0..60) |i| {
const bytes = try std.fmt.bufPrint(&line, "\x1b[1;3{d}m{d}\x1b[0m 漢字 e\u{301} \x1b[48;2;{d};40;60mbg\x1b[0m and then some text that wraps past the width of the pane\r\n", .{ i % 8, i, i * 4 % 256 });
- a.update(.{ .output = .{ .pane = 0, .bytes = bytes } });
+ a.update(.{ .output = .{ .pane = .at(0), .bytes = bytes } });
delta.clearRetainingCapacity();
try testing.expect(try encode(&enc, &tr, &peer, ta, @intCast(i + 1), "", &delta.writer));
peer.ack((try rep.apply(gpa, std.Io.Threaded.global_single_threaded.io(), tb, delta.written())).seq);