diff options
Diffstat (limited to 'test/kitty_harness.zig')
| -rw-r--r-- | test/kitty_harness.zig | 116 |
1 files changed, 116 insertions, 0 deletions
diff --git a/test/kitty_harness.zig b/test/kitty_harness.zig index ad864671..652395b8 100644 --- a/test/kitty_harness.zig +++ b/test/kitty_harness.zig @@ -66,6 +66,7 @@ pub fn main(init: std.process.Init) !void { var run: Run = .{ .arena = arena, .h = &h, .base = base, .kc = kc, .gui = gui }; try run.start(); + if (std.c.getenv("PARDES_KITTY_EXPLORE")) |list| return run.explore(std.mem.span(list)); std.debug.print("kitty harness ({s}):\n", .{if (gui) "gui" else "tty"}); try run.query(); try run.place(); @@ -73,14 +74,53 @@ pub fn main(init: std.process.Init) !void { try run.quiet(); try run.cancel(); if (!gui) try run.delete(); + if (!gui) try run.under(); try run.icat(); try run.chafa(); + try run.yazi(); + + if (!gui) try plainOuter(arena, exe, kc, base); std.debug.print("kitty harness: {d} failed, {d} skipped\n", .{ failures, skipped }); if (failures > 0) return error.KittyHarnessFailed; } +/// Outside, a terminal without kitty graphics (it answers DA, not the +/// graphics query): pardes must send it no graphics command, and draws the +/// pane's image as glyph art; the program in the pane is answered as ever. +fn plainOuter(arena: std.mem.Allocator, exe: [:0]const u8, kc: []const u8, base: [:0]const u8) !void { + var h = try eh.Harness.initArgv(gpa, exe, rows, cols, &.{}); + defer h.deinit(); + try h.expectRawWaitFor("\x1b_Gi=1,a=q\x1b\\", 8000, "pardes did not probe for kitty graphics"); + try h.send("\x1b[?62;22c"); + try h.expectWaitFor("$ ", 10_000, "the shell's prompt did not show"); + try h.pump(400); + var run: Run = .{ .arena = arena, .h = &h, .base = base, .kc = kc, .gui = false }; + const probe_end = h.raw.items.len; + const got = try run.case("place"); + check(std.mem.eql(u8, got, "\x1b_Gi=42;OK\x1b\\" ++ sync_reply), "plain outer: the pane's program is answered as ever ({f})", .{std.ascii.hexEscape(got, .lower)}); + const raw = h.raw.items[probe_end..]; + const sent = std.mem.count(u8, raw, "\x1b_G"); + check(sent == 0, "plain outer: no graphics command reaches a terminal without them ({d})", .{sent}); + // Glyph art fills the 8x4 cells after ANCHOR>: a solid picture is all + // background colour (C64's nearest blue), no glyph. + const anchor = try run.find("ANCHOR>") orelse { + check(false, "plain outer: ANCHOR> on the screen", .{}); + return; + }; + var art: usize = 0; + for (0..4) |dy| for (0..8) |dx| { + const cell = h.term.screens.active.pages.getCell(.{ .viewport = .{ .x = @intCast(anchor.x + 7 + dx), .y = @intCast(anchor.y + dy) } }) orelse continue; + if (cell.style().bg_color != .none) art += 1; + }; + check(art == 32, "plain outer: the image is glyph art in its cells ({d} of 32 coloured)", .{art}); +} + fn hermetic(arena: std.mem.Allocator, base: [:0]const u8, gui: bool) !void { + // zig build hands its children NO_COLOR, and vaxis honours it: pardes + // would draw no colour at all, glyph art included. Emptied, not unset: + // unsetenv compacts the environment block std captured (a null later). + _ = setenv("NO_COLOR", "", 1); for ([_][*:0]const u8{ "PARDES_PID", "PARDES_9P", "PARDES_PANE", "PARDES_MOUNT", "PARDES_TEST", "PARDES_TEST_CAPTURE_DIR", "PARDES_TEST_COLS", "PARDES_TEST_ROWS", "PARDES_DUMP" }) |name| _ = unsetenv(name); _ = setenv("HOME", base, 1); @@ -256,6 +296,69 @@ const Run = struct { check(cells.count == 0, "delete: no placement of it left outside ({d})", .{cells.count}); } + /// PARDES_KITTY_EXPLORE=<file>: each line `name<TAB>command` runs in + /// the pane under `script`, whose log (the client's own bytes, as it + /// ran under pardes) goes to $PARDES_KITTY_RECORD/<name>.log; then the + /// outer screen and pardes's placements there are printed. + fn explore(r: *Run, list_path: []const u8) !void { + const list = try readFile(r.arena, try r.arena.dupeSentinel(u8, list_path, 0)); + const record = if (std.c.getenv("PARDES_KITTY_RECORD")) |d| std.mem.span(d) else r.base; + var lines = std.mem.splitScalar(u8, list, '\n'); + while (lines.next()) |line| { + const tab = std.mem.indexOfScalar(u8, line, '\t') orelse continue; + const name = line[0..tab]; + const cmd = std.mem.replaceOwned(u8, r.arena, line[tab + 1 ..], "$BASE", r.base) catch line[tab + 1 ..]; + const raw_from = r.h.raw.items.len; + const shell_line = try std.fmt.allocPrint(r.arena, "clear; script -q -O {s}/{s}.log -c '{s}' 2>{s}/{s}.err; touch {s}/{s}.out.done", .{ record, name, cmd, r.base, name, r.base, name }); + _ = try r.shell(name, shell_line); + try r.h.pump(800); + std.debug.print("=== {s}: {s}\n", .{ name, cmd }); + const err = readFile(r.arena, try std.fmt.allocPrintSentinel(r.arena, "{s}/{s}.err", .{ r.base, name }, 0)) catch ""; + if (err.len > 0) std.debug.print("stderr: {s}\n", .{err}); + const raw = r.h.raw.items[raw_from..]; + std.debug.print("outer: {d} transmits, {d} puts, {d} deletes\n", .{ std.mem.count(u8, raw, "\x1b_Gf="), std.mem.count(u8, raw, "\x1b_Ga=p"), std.mem.count(u8, raw, "\x1b_Ga=d") }); + var kinds: std.array_hash_map.String(usize) = .empty; + var from: usize = 0; + while (std.mem.indexOfPos(u8, raw, from, "\x1b_Ga=")) |i| : (from = i + 1) { + const end = std.mem.indexOfAnyPos(u8, raw, i + 1, ";\x1b") orelse continue; + var key = raw[i + 3 .. @min(end, i + 3 + 40)]; + // Ids and geometry vary; the command's shape is the point. + if (std.mem.indexOf(u8, key, ",i=")) |cut| key = key[0..cut]; + const gop = try kinds.getOrPut(r.arena, key); + gop.value_ptr.* = if (gop.found_existing) gop.value_ptr.* + 1 else 1; + } + for (kinds.keys(), kinds.values()) |k, n| std.debug.print(" {d}x {s}\n", .{ n, k }); + const screen = r.h.term.screens.active; + const storage = &screen.kitty_images; + var it = storage.placements.iterator(); + while (it.next()) |entry| { + const img = storage.imageById(entry.key_ptr.image_id) orelse continue; + const where: []const u8 = switch (entry.value_ptr.location) { + .pin => |pin| if (screen.pages.pointFromPin(.viewport, pin.*)) |at| try std.fmt.allocPrint(r.arena, "{d},{d}", .{ at.viewport.x, at.viewport.y }) else "off-viewport", + .virtual => "virtual", + .relative => "relative", + }; + std.debug.print(" image {d} {d}x{d}px at {s} {d}x{d} cells src {d},{d} {d}x{d}\n", .{ entry.key_ptr.image_id, img.width, img.height, where, entry.value_ptr.columns, entry.value_ptr.rows, entry.value_ptr.source_x, entry.value_ptr.source_y, entry.value_ptr.source_width, entry.value_ptr.source_height }); + } + r.h.dump(name); + } + } + + fn under(r: *Run) !void { + _ = try r.case("under"); + const storage = &r.h.term.screens.active.kitty_images; + var it = storage.placements.iterator(); + var seen: usize = 0; + var below: usize = 0; + while (it.next()) |entry| { + const img = storage.imageById(entry.key_ptr.image_id) orelse continue; + if (img.width != client.side or img.height != client.side) continue; + seen += 1; + if (entry.value_ptr.z == -1) below += 1; + } + check(seen > 0 and below == seen, "under: z=-1 reaches the outer terminal on every row ({d} of {d})", .{ below, seen }); + } + fn haveTool(r: *Run, name: []const u8) bool { const which = std.fmt.allocPrintSentinel(r.arena, "command -v {s} >/dev/null 2>&1", .{name}, 0) catch return false; return system(which) == 0; @@ -288,6 +391,19 @@ const Run = struct { check(std.mem.indexOf(u8, raw, "\x1b_Gf=32,s=") != null and err.len == 0, "chafa -f kitty: drawn outside ({s})", .{std.mem.trim(u8, err, " \r\n")}); } + /// yazi previews the PNG (its first entry) through shared memory and a + /// virtual placement shown by placeholders, in its right-hand column. + /// Killed after 6 s, it leaves the preview up. + fn yazi(r: *Run) !void { + if (!r.haveTool("yazi")) return skip("yazi: not installed", .{}); + const raw_from = r.h.raw.items.len; + _ = try r.shell("yazi", try std.fmt.allocPrint(r.arena, "clear; mkdir -p {s}/yz; cp {s}/solid.png {s}/yz/; timeout --foreground -s KILL 6 yazi {s}/yz 2>{s}/yazi.out; touch {s}/yazi.out.done", .{ r.base, r.base, r.base, r.base, r.base, r.base })); + if (r.gui) return r.placedNear("yazi"); + const raw = r.h.raw.items[raw_from..]; + const cells = try r.outerPlacements(client.side, client.side); + check(std.mem.indexOf(u8, raw, "\x1b_Gf=32,s=64,v=64,i=") != null and cells.count == 4 and cells.min_x > cols / 2, "yazi: its preview drawn outside, in its right half ({d} rows at {d},{d})", .{ cells.count, cells.min_x, cells.min_y }); + } + fn placedNear(r: *Run, name: []const u8) !void { const path = try r.capturePath(); const deadline = eh.nowMs() + 4000; |
