summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--build/process.zig13
-rw-r--r--src/gui/gui.zig39
-rw-r--r--test/gui-goldens.txt15
-rw-r--r--test/process/window.zig196
4 files changed, 44 insertions, 219 deletions
diff --git a/build/process.zig b/build/process.zig
index bec37d65..1968aaab 100644
--- a/build/process.zig
+++ b/build/process.zig
@@ -60,10 +60,8 @@ pub fn add(b: *std.Build, opts: struct {
run_process_test.has_side_effects = true;
b.step("process-test", "run the process tests: real sessions over their sockets, the tty's in a pty each (-- [--update] [filter])").dependOn(&run_process_test.step);
// The window's own, run in full when asked (test/process/window.zig):
- // the monkey over every Motion, and the frames against
- // this machine's goldens (PARDES_GUI_GOLDEN=update rewrites them).
+ // the monkey over every Motion.
const monkey_gui_step = b.step("monkey-gui", "random input to the hidden window across the effect settings (-Dplatform=gui; PARDES_GUI_MONKEY_SEED, _STEPS)");
- const gui_golden_step = b.step("gui-golden", "the hidden window's scenes against test/gui-goldens.txt, this machine's (-Dplatform=gui; PARDES_GUI_GOLDEN=update rewrites)");
if (opts.gui) {
const run_monkey_gui = b.addRunArtifact(process_test);
run_monkey_gui.addArtifactArg(opts.exe);
@@ -72,16 +70,7 @@ pub fn add(b: *std.Build, opts: struct {
run_monkey_gui.setEnvironmentVariable("PARDES_GUI_MONKEY", "all");
run_monkey_gui.has_side_effects = true;
monkey_gui_step.dependOn(&run_monkey_gui.step);
- const run_gui_golden = b.addRunArtifact(process_test);
- run_gui_golden.addArtifactArg(opts.exe);
- for (opts.addons) |a| run_gui_golden.addPrefixedFileArg("--addon=", a.getEmittedBin());
- run_gui_golden.addArgs(&.{ "--backend=gui", "window: its scenes" });
- run_gui_golden.setEnvironmentVariable("PARDES_GUI_GOLDEN", b.graph.environ_map.get("PARDES_GUI_GOLDEN") orelse "check");
- run_gui_golden.setCwd(b.path("."));
- run_gui_golden.has_side_effects = true;
- gui_golden_step.dependOn(&run_gui_golden.step);
} else {
monkey_gui_step.dependOn(&b.addFail("monkey-gui needs -Dplatform=gui").step);
- gui_golden_step.dependOn(&b.addFail("gui-golden needs -Dplatform=gui").step);
}
}
diff --git a/src/gui/gui.zig b/src/gui/gui.zig
index f4424520..b7ba1fb7 100644
--- a/src/gui/gui.zig
+++ b/src/gui/gui.zig
@@ -5795,6 +5795,22 @@ test "concealed terminal text emits no ink on its ground" {
try std.testing.expectEqual(bg_default, resolved.bg);
}
+test "a block cursor's cell is drawn reversed: the cell's ink its ground, its ground its ink" {
+ var g = testGui(10, 20, 6, 12);
+ // A blank, so no glyph is looked up in this atlas-less Gui.
+ const cell: pardes.Cell = .{
+ .text = .{ ' ', ' ', ' ', ' ', ' ', ' ', ' ' },
+ .len = 1,
+ .default = false,
+ .style = .{ .fg = .{ .rgb = .{ 10, 20, 30 } }, .bg = .{ .rgb = .{ 200, 210, 220 } } },
+ };
+ const plain = resolveCell(&g, (&cell)[0..1], 0, null, .body, false, bg_default);
+ const cursor = resolveCell(&g, (&cell)[0..1], 0, 0, .body, true, bg_default);
+ try std.testing.expectEqual([3]u8{ 10, 20, 30 }, plain.fg);
+ try std.testing.expectEqual(plain.fg, cursor.bg);
+ try std.testing.expectEqual(plain.bg, cursor.fg);
+}
+
fn cellInstanceCount(cell: *const pardes.Cell) u32 {
return if (cellFontRole(cell) == .tagline) 2 else 1;
}
@@ -7942,6 +7958,29 @@ test "the scrollbar thumb moves by the pixel and follows a glide" {
try std.testing.expectApproxEqAbs(at10, try thumb.top(&g, core), 1e-3);
}
+test "the scrollbar thumb lies in its scroll column, a pixel short of the column's right edge, so the track edges it" {
+ const gpa = std.testing.allocator;
+ const core = try pardes.Pardes.init(gpa, .{ .cols = 80, .rows = 24 });
+ defer core.deinit();
+ _ = try core.setTestFile(std.mem.asBytes(&@as([1000][5]u8, @splat("line\n".*))));
+ var g = testGui(10, 20, 6, 12);
+ defer g.decor.deinit(gpa);
+ core.sync();
+ const s = try core.render(core.scratch.allocator());
+ var groups: Groups = .{};
+ try buildDecor(&g, gpa, s, &groups, fixedCellLayout(&g), 800, 480, true);
+ const ink = s.chrome.scroll_thumb;
+ const thumb = for (g.decor.items) |item| {
+ if (@abs(item.br - @as(f32, @floatFromInt(ink[0])) / 255) < 1e-3 and
+ @abs(item.bg - @as(f32, @floatFromInt(ink[1])) / 255) < 1e-3 and
+ @abs(item.bb - @as(f32, @floatFromInt(ink[2])) / 255) < 1e-3) break item;
+ } else return error.TestExpectedThumb;
+ // The pane is the window's first: its scroll column is at cell 0.
+ const column = scrollColumn(&g, &s.chrome, 0, fixedCellLayout(&g));
+ try std.testing.expectApproxEqAbs(column[0], (thumb.x0 + 1) / 2 * 800, 1e-3);
+ try std.testing.expectApproxEqAbs(column[1] - 1, (thumb.x1 + 1) / 2 * 800, 1e-3);
+}
+
test "the rule between stacked panes stays in the tag band's slack, at any tagline size" {
const gpa = std.testing.allocator;
const core = try pardes.Pardes.init(gpa, .{ .cols = 80, .rows = 24 });
diff --git a/test/gui-goldens.txt b/test/gui-goldens.txt
deleted file mode 100644
index 253df55c..00000000
--- a/test/gui-goldens.txt
+++ /dev/null
@@ -1,15 +0,0 @@
-01-boot bb684190c85d17f6688d458756b38d645f019fbb081b4cd4d0d435a01e9de0c3
-02-second-document 1be84e0cb97531cfe37ae3382951ad6d4489b871c3000cc3d3c46d30df794a1d
-03-notice 712ed4b9c02cbb8f3e18c03597dbcb5cd678a77ac560845245a44e266d038ea9
-04-context-rows-mid-thumb 429a50197dc7fa442fe0b9aa8c732c741c372348c3394e1809361086cceb1ff4
-05-body-selection 65619d076aec3d24cc2dac308228a282a898be0f6292a416197ae0f9ffe68532
-06-tag-focus-selection 248bcdad20febb363e35a53bd8b14d15289b2f56e7edc7d087ee86668236b670
-07-prompt-notice 4b1511f42b1cc06d3fe8b07e44a296a6c3fb2a37788cf0e9b5b1c7837a00993b
-08-wide-glyph-edges c200d9fd0254af6b39a6387a074b1e29efeb3bd4114b373f83650a8bae8900ad
-09-collapsed-focus-tint 5f2caa8496cd0d223eda7dbbbd6f37c6540b31f56458f7680011b1e212718100
-12-multiline-tag e0d7cf913d500589d9d47a6cdb553323c76611168b380df5094f2e02946c1704
-13-image 81c1cb7d9aa0b91ba5abc4e896fe499215f75f43df0bcccdd9c1cc6e5f319650
-14-theme-ink ff44cd685cb95f8a74832bbc6822dfd6dfe7805df15ec4c35016c43cdac18862
-15-theme-acme-light a475cd29cf0cd8bca5a2a453d87552a283d7c47d73fdb8d41fa55d277b0a4b69
-16-debug 80ccae7579437eba04d2f2221fff5739aac69ce38e78186f88e8f6b7749e7d94
-17-terminal c23f79212ab9afc9d3ccf982c44503b34b09742e45b74f8e3c375e9ae50a5bb2
diff --git a/test/process/window.zig b/test/process/window.zig
index ea7d21d5..8d1afed8 100644
--- a/test/process/window.zig
+++ b/test/process/window.zig
@@ -1,33 +1,18 @@
-//! The window's own (T4 of docs/next-tests.md): what only its pixels and
-//! its own input show, on the hidden window `zig build process-test
-//! -Dplatform=gui` drives. test/gui_monkey.py and test/gui_golden.py, here.
+//! The window's own (T4 of docs/next-tests.md): its own input, on the
+//! hidden window `zig build process-test -Dplatform=gui` drives, settling
+//! alive. Its pixels are its unit tests' (`unit-test -Dplatform=gui`) and
+//! the image and kitty harnesses'; what the core draws, the tty cases'.
const std = @import("std");
const process = @import("../process.zig");
-extern "c" fn system(cmd: [*:0]const u8) c_int;
pub const cases = .{
.{ "window: a monkey over the effects: random clicks, drags, wheels, keys, columns, looks and themes, then it settles, alive, with no crash record", monkey },
- .{ "window: its scenes are the frames test/gui-goldens.txt hashes (PARDES_GUI_GOLDEN=check|update, this machine's)", goldens },
};
fn envOr(name: [*:0]const u8, default: []const u8) []const u8 {
return if (std.c.getenv(name)) |v| std.mem.span(v) else default;
}
-/// The serial of the first pane whose tag holds `word`, waited for.
-fn paneWith(f: *process.Files, word: []const u8) !u32 {
- const deadline = process.nowMs() + 10_000;
- while (process.nowMs() < deadline) : (process.nap(50)) {
- var rows = std.mem.tokenizeScalar(u8, try f.read("/index"), '\n');
- while (rows.next()) |row| {
- const serial = std.fmt.parseInt(u32, row[0 .. std.mem.indexOfScalar(u8, row, ' ') orelse continue], 10) catch continue;
- if (process.has(try f.read(f.at("/pane/{d}/tag", .{serial})), word)) return serial;
- }
- }
- std.debug.print("no pane's tag holds {s}\n", .{word});
- return error.NoSuchPane;
-}
-
const themes = [_][]const u8{ "lapis", "forge", "acme", "dusk", "daybreak" };
/// test/gui_monkey.py's: random bursts, each run then settling with its
@@ -172,176 +157,3 @@ fn firstPane(f: *process.Files) !?u32 {
const end = std.mem.indexOfScalar(u8, index, ' ') orelse return null;
return std.fmt.parseInt(u32, index[0..end], 10) catch null;
}
-
-/// test/gui_golden.py's scenes, each frame's sha256 against
-/// test/gui-goldens.txt: an exact gate for one machine (a GPU, a driver,
-/// software rendering here draw their own pixels), never a CI one, so it
-/// runs only when asked: PARDES_GUI_GOLDEN=check, or =update to rewrite the
-/// goldens; PARDES_GUI_GOLDEN_KEEP=<dir> keeps each frame as <scene>.ppm.
-/// The root is fixed: its paths are drawn in the tags.
-fn goldens(gpa: std.mem.Allocator, exe: [:0]const u8) !void {
- try process.only(.gui);
- const mode = envOr("PARDES_GUI_GOLDEN", "");
- if (!std.mem.eql(u8, mode, "check") and !std.mem.eql(u8, mode, "update")) return error.SkipZigTest;
- var arena = std.heap.ArenaAllocator.init(gpa);
- defer arena.deinit();
- const a = arena.allocator();
- const root = "/tmp/pardes-gui-golden";
- _ = system("rm -rf -- /tmp/pardes-gui-golden");
- if (std.c.mkdir(root, 0o700) != 0) return error.NoRoot;
- defer _ = system("rm -rf -- /tmp/pardes-gui-golden");
- var zig: std.ArrayList(u8) = .empty;
- try zig.appendSlice(a,
- \\const std = @import("std");
- \\
- \\pub const Shape = union(enum) {
- \\ circle: f32,
- \\ square: f32,
- \\
- \\ pub fn area(shape: Shape) f32 {
- \\ return switch (shape) {
- \\ .circle => |r| std.math.pi * r * r,
- \\ .square => |s| s * s,
- \\ };
- \\ }
- \\};
- \\
- \\pub fn main() void {
- \\ var total: f32 = 0;
- \\ const shapes = [_]Shape{ .{ .circle = 1 }, .{ .square = 2 } };
- \\ for (shapes) |shape| {
- \\
- );
- for (0..60) |n| try zig.print(a, " total += shape.area() * {d}; // line {d}\n", .{ n, n });
- try zig.appendSlice(a, " }\n std.debug.print(\"{d}\\n\", .{total});\n}\n");
- try process.writeFile(a, root ++ "/shapes.zig", zig.items);
- var notes: std.ArrayList(u8) = .empty;
- for (0..4) |_| try notes.appendSlice(a, "Pardes GUI golden\n\nA second document, opened by Look.\n");
- try process.writeFile(a, root ++ "/notes.txt", notes.items);
- // One of the two alignments puts a wide glyph across the body's right edge.
- var wide: std.ArrayList(u8) = .empty;
- try wide.append(a, 'x');
- for (0..80) |_| try wide.appendSlice(a, "\u{754c}");
- try wide.append(a, '\n');
- for (0..80) |_| try wide.appendSlice(a, "\u{754c}");
- try wide.append(a, '\n');
- try process.writeFile(a, root ++ "/wide.txt", wide.items);
- var ppm: std.ArrayList(u8) = .empty;
- try ppm.print(a, "P6\n{d} {d}\n255\n", .{ 96, 64 });
- for (0..64) |yy| for (0..96) |xx| try ppm.appendSlice(a, &.{ @intCast(xx * 255 / 96), @intCast(yy * 255 / 64), 128 });
- try process.writeFile(a, root ++ "/ramp.ppm", ppm.items);
-
- var d = try process.Detached.start(gpa, exe, "gui-golden", .{
- .root = root,
- .file = root ++ "/shapes.zig",
- .init = "Shell /bin/sh\nTheme forge\nMessageLinger 0\n",
- // The virtual clock: the same frames on any machine.
- .grid = .{ 120, 40 },
- .env = &.{ .{ "PARDES_TEST_CLOCK", "1" }, .{ "PARDES_TEST_PAD", "7" } },
- });
- defer d.deinit();
- const f = &d.files;
- var results: std.ArrayList(u8) = .empty;
- const keep = std.c.getenv("PARDES_GUI_GOLDEN_KEEP");
- const Scene = struct {
- fn shot(dd: *process.Detached, al: std.mem.Allocator, out: *std.ArrayList(u8), kept: ?[*:0]const u8, label: []const u8, file: []const u8) !void {
- const bytes = try dd.capture(al, file);
- var digest: [32]u8 = undefined;
- std.crypto.hash.sha2.Sha256.hash(bytes, &digest, .{});
- try out.print(al, "{s} {x}\n", .{ label, digest });
- if (kept) |dir| try process.writeFile(al, try std.fmt.allocPrint(al, "{s}/{s}.ppm", .{ std.mem.span(dir), label }), bytes);
- std.debug.print("{s} {x}\n", .{ label, digest[0..8] });
- }
- };
- const shot = Scene.shot;
- const first = try paneWith(f, "shapes.zig");
- try shot(&d, a, &results, keep, "01-boot", "latest.ppm");
- try f.write(f.at("/pane/{d}/look", .{first}), root ++ "/notes.txt\n");
- const notes_pane = try paneWith(f, "notes.txt");
- try shot(&d, a, &results, keep, "02-second-document", "latest.ppm");
- try f.write(f.at("/pane/{d}/ctl", .{first}), "Msg a golden notice\n");
- try shot(&d, a, &results, keep, "03-notice", "latest.ppm");
- try f.write(f.at("/pane/{d}/ctl", .{first}), "TreeContext\n");
- try f.write(f.at("/pane/{d}/dot", .{first}), "45\n");
- try shot(&d, a, &results, keep, "04-context-rows-mid-thumb", "latest.ppm");
- try f.write(f.at("/pane/{d}/dot", .{first}), "40,43\n");
- try shot(&d, a, &results, keep, "05-body-selection", "latest.ppm");
- // A press and a drag along the source's tag: the tag takes the keyboard
- // with a selection and a caret. The pointer then rests on empty body
- // space, far right.
- for ([_]struct { []const u8, i32, u32, u32 }{ .{ "down", 1, 500, 87 }, .{ "motion", 1, 620, 87 }, .{ "up", 1, 620, 87 }, .{ "motion", 0, 1880, 1300 } }) |ev| {
- try d.mouse(ev[0], ev[1], ev[2], ev[3]);
- process.nap(100);
- }
- try shot(&d, a, &results, keep, "06-tag-focus-selection", "latest.ppm");
- try d.typeKeys("\x1b");
- process.nap(200);
- const scratch = try f.newPane();
- try f.write(f.at("/pane/{d}/exec", .{scratch}), "Save\n");
- try shot(&d, a, &results, keep, "07-prompt-notice", "latest.ppm");
- try d.typeKeys("\x1b");
- process.nap(200);
- try f.write(f.at("/pane/{d}/exec", .{scratch}), "Del\n");
- try f.write(f.at("/pane/{d}/look", .{first}), root ++ "/wide.txt\n");
- const wide_pane = try paneWith(f, "wide.txt");
- var name: std.ArrayList(u8) = .empty;
- try name.append(a, 'x');
- for (0..70) |_| try name.appendSlice(a, "\u{754c}");
- try name.append(a, '\n');
- try f.write(f.at("/pane/{d}/name", .{wide_pane}), name.items);
- try f.write("/ctl", "Wrap off\n");
- try shot(&d, a, &results, keep, "08-wide-glyph-edges", "latest.ppm");
- try f.write("/ctl", "Wrap on\n");
- try f.write(f.at("/pane/{d}/exec", .{wide_pane}), "Del\n");
- try f.write(f.at("/pane/{d}/ctl", .{notes_pane}), "Collapse\n");
- try shot(&d, a, &results, keep, "09-collapsed-focus-tint", "latest.ppm");
- try f.write(f.at("/pane/{d}/ctl", .{notes_pane}), "Collapse\n");
- try f.write(f.at("/pane/{d}/tag", .{first}), " Second\nthird line of the tag");
- try shot(&d, a, &results, keep, "12-multiline-tag", "latest.ppm");
- try f.write(f.at("/pane/{d}/look", .{first}), root ++ "/ramp.ppm\n");
- _ = try paneWith(f, "ramp.ppm");
- try shot(&d, a, &results, keep, "13-image", "latest.ppm");
- try f.write("/ctl", "Theme ink\n");
- try shot(&d, a, &results, keep, "14-theme-ink", "latest.ppm");
- try f.write("/ctl", "Theme acme\n");
- try shot(&d, a, &results, keep, "15-theme-acme-light", "latest.ppm");
- try f.write("/ctl", "Debug\n");
- try shot(&d, a, &results, keep, "16-debug", "latest.ppm");
- try f.write("/ctl", "Debug\n");
- // A terminal pane: raw rows, ANSI colours, a hidden prompt.
- const before = try f.read("/index");
- try f.write(f.at("/pane/{d}/exec", .{first}), "Term\n");
- const terminal = blk: {
- const deadline = process.nowMs() + 10_000;
- while (process.nowMs() < deadline) : (process.nap(50)) {
- var rows = std.mem.tokenizeScalar(u8, try f.read("/index"), '\n');
- while (rows.next()) |row| {
- const head = row[0 .. std.mem.indexOfScalar(u8, row, ' ') orelse continue];
- if (std.mem.indexOf(u8, before, f.at("{s} ", .{head})) == null) break :blk try std.fmt.parseInt(u32, head, 10);
- }
- }
- return error.NoTerminal;
- };
- try f.write(f.at("/pane/{d}/pty/data", .{terminal}), "PS1='$ '; clear; printf '\\033[1;36mcolour\\033[0m plain \\033[32mgreen\\033[0m\\n'\r");
- {
- const deadline = process.nowMs() + 10_000;
- while (!process.has(try f.read(f.at("/pane/{d}/body", .{terminal})), "green")) : (process.nap(50))
- if (process.nowMs() > deadline) return error.NoTerminalOutput;
- }
- try shot(&d, a, &results, keep, "17-terminal", "latest.ppm");
-
- const goldens_path = "test/gui-goldens.txt";
- if (std.mem.eql(u8, mode, "update")) {
- try process.writeFile(a, goldens_path, results.items);
- std.debug.print("updated {s}\n", .{goldens_path});
- return;
- }
- const want = try process.readWhole(a, goldens_path);
- var bad: usize = 0;
- var got = std.mem.tokenizeScalar(u8, results.items, '\n');
- while (got.next()) |line| if (std.mem.indexOf(u8, want, line) == null) {
- bad += 1;
- std.debug.print("frame changed: {s}\n", .{line[0..std.mem.indexOfScalar(u8, line, ' ').?]});
- };
- if (bad > 0) return error.FramesChanged;
-}