diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-05 22:21:45 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-05 23:08:36 -0300 |
| commit | 71e5a0f4a8685b385fac762995d45575b638179f (patch) | |
| tree | bf643875b0567b45cf659c1b3ad4b872f311a774 /test/kitty.zig | |
| parent | d8e5fc18f5923c4213de1cb4105a677e725200af (diff) | |
| download | pardes-71e5a0f4a8685b385fac762995d45575b638179f.tar.gz pardes-71e5a0f4a8685b385fac762995d45575b638179f.zip | |
kinds #1, the paint contract: a picture over the cells is one Placement (raster: ptr, w, h, stride; src in pixels; dst in the frame's cells; at, where in them in pixels, or none for the frontend to fit; key, the pixels' identity by pane serial, page and revision; a terminal program's kitty z; dirty, the rows changed since an older key; art, the pane's Petscii, Palette and Ascii), where ImagePlace carried native.{revision, page, fit, pan_x, pan_y, geometry, pixel_offset_y, paper_bg, exact}, cell rects and an ImageCacheKey of three shapes by build; a PDF strip's scroll is its body region's scroll_px, whose fraction the window draws as pixel_offset_y was; glyph art leaves the core for src/Art.zig, the frontends' (the matcher, both palettes and a cache by key, ex image.zig's GlyphArt and TerminalImages' glyph cache): the core always hands an image pane, a PDF's pages and a terminal's kitty images as placements, whatever the frontend shows, and the tty draws them as glyph art without kitty graphics or when the pane asks, the window when the pane asks; the four words set the same pane bytes as before and the frontend reads them off the placement, so config.zig, builtins.zig and exec.zig are untouched; /screen lists a frame's placements as images (only a frame with pictures has the field); no golden changes: the snapshot goldens are the tty's, which draws the same art (images.snap and tagbottomimage.snap pass unchanged, and the tty's bytes for an image, its Palette and its Ascii are byte-identical to the base's), no /screen golden holds a picture, and the window's goldens hash the same; tests: kitty.zig's glyph-art case becomes its core half (a placement over the 8x4 cells, the cells the pane's) with the art in tui.zig's own test, terminal.zig's glyph-art case the same, surface.zig's two ImageCacheKey cases one keyOf case, the GlyphArt cases move to Art.zig with a frame case; gates: core-test 959/959, behaviour-test 244/244, unit-test 1486/1487 tui and 1530/1531 gui, pane-test 171/172, snap all ok, process-test 0 of 37 failed on both, hxdiff 19 and hxparity 6 mismatches by the base's names, replicas, gui-golden, monkey-gui, kitty-test 44/44, kitty-harness and image-harness on both, daemon.py main and window-clients
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
Diffstat (limited to 'test/kitty.zig')
| -rw-r--r-- | test/kitty.zig | 127 |
1 files changed, 66 insertions, 61 deletions
diff --git a/test/kitty.zig b/test/kitty.zig index daa01060..f222f9cf 100644 --- a/test/kitty.zig +++ b/test/kitty.zig @@ -9,7 +9,7 @@ //! and what the emulator stores is drawn where the program put it. Each case //! feeds a pane's output the way a pty read does and checks all three: the //! bytes the program would read back, ghostty's image storage, and the -//! `ImagePlace`s a frame hands the shell (which a tty re-emits to the outer +//! placements a frame hands the shell (which a tty re-emits to the outer //! terminal and the GUI draws; test/kitty_harness.zig follows them there). //! //! A case pardes does not pass yet is a `knownGap`: its check runs, the test @@ -125,10 +125,18 @@ const Rig = struct { return &r.vt(id).screens.active.kitty_images; } - fn places(r: *Rig) ![]const pardes.ImagePlace { + fn places(r: *Rig) ![]const pardes.Placement { _ = r.frame.reset(.retain_capacity); const s = try r.p.render(r.frame.allocator()); - return s.images.items; + return s.placements.items; + } + + /// The id its program gave the image a place draws. + fn idOf(r: *Rig, place: pardes.Placement) ?u32 { + const shown = r.p.panes[place.pane] orelse return null; + var it = shown.terminal.?.vt.screens.active.kitty_images.images.iterator(); + while (it.next()) |e| if (pardes.Placement.keyOf(shown.serial, e.key_ptr.*, @truncate(e.value_ptr.generation)) == place.key) return e.key_ptr.*; + return null; } /// The top-left cell of pane `id`'s body, in screen cells. @@ -138,9 +146,9 @@ const Rig = struct { } /// The places drawn for the image a program called `image_id`. - fn placesOf(r: *Rig, image_id: u32) ![]const pardes.ImagePlace { - var out: std.ArrayList(pardes.ImagePlace) = .empty; - for (try r.places()) |place| if (place.native.page == image_id) + fn placesOf(r: *Rig, image_id: u32) ![]const pardes.Placement { + var out: std.ArrayList(pardes.Placement) = .empty; + for (try r.places()) |place| if (r.idOf(place) == image_id) try out.append(r.frame.allocator(), place); return out.items; } @@ -155,8 +163,8 @@ const Rig = struct { }; /// The pixel at `(x, y)` of a drawn place's whole image, as RGBA. -fn pixel(place: pardes.ImagePlace, x: usize, y: usize) [4]u8 { - return place.rgba[(y * place.iw + x) * 4 ..][0..4].*; +fn pixel(place: pardes.Placement, x: usize, y: usize) [4]u8 { + return place.raster.bytes()[y * place.raster.stride + x * 4 ..][0..4].*; } test "kitty: a support query is answered on the asking pane's pty and stores nothing" { @@ -221,7 +229,7 @@ test "kitty: RGB, RGBA, PNG and zlib-compressed RGB all draw the same pixels" { try std.testing.expectEqual(@as(u32, 2), img.height); const drawn = try r.placesOf(1); try std.testing.expectEqual(@as(usize, 1), drawn.len); - try std.testing.expectEqual(@as(usize, 4), drawn[0].iw); + try std.testing.expectEqual(@as(usize, 4), drawn[0].raster.w); for ([_][2]usize{ .{ 0, 0 }, .{ 1, 1 } }) |at| try std.testing.expectEqual(red, pixel(drawn[0], at[0], at[1])); for ([_][2]usize{ .{ 2, 0 }, .{ 3, 1 } }) |at| try std.testing.expectEqual(blue, pixel(drawn[0], at[0], at[1])); } @@ -361,10 +369,10 @@ test "kitty: a=T draws at the cursor and moves the cursor past the image; C=1 le // A cell row at a time: two rows. try std.testing.expectEqual(@as(usize, 2), drawn.len); const o = r.origin(0); - try std.testing.expectEqual(o.x + 4, drawn[0].x); - try std.testing.expectEqual(o.y + 2, drawn[0].y); - try std.testing.expectEqual(o.y + 3, drawn[1].y); - for (drawn) |place| try std.testing.expectEqual(@as(u16, 2), place.w); + try std.testing.expectEqual(o.x + 4, drawn[0].dst.x); + try std.testing.expectEqual(o.y + 2, drawn[0].dst.y); + try std.testing.expectEqual(o.y + 3, drawn[1].dst.y); + for (drawn) |place| try std.testing.expectEqual(@as(u16, 2), place.dst.w); } } @@ -383,14 +391,14 @@ test "kitty: a=p places one image twice by placement id, a source rect crops it, const o = r.origin(0); var drawn = try r.placesOf(7); try std.testing.expectEqual(@as(usize, 2), drawn.len); - var cropped: ?pardes.ImagePlace = null; - for (drawn) |place| if (place.y == o.y + 5) { + var cropped: ?pardes.Placement = null; + for (drawn) |place| if (place.dst.y == o.y + 5) { cropped = place; }; const crop = cropped orelse return error.CroppedPlacementMissing; - try std.testing.expectEqual(o.x + 9, crop.x); - try std.testing.expectEqual(@as(u16, 1), crop.w); - const g = crop.native.geometry.?; + try std.testing.expectEqual(o.x + 9, crop.dst.x); + try std.testing.expectEqual(@as(u16, 1), crop.dst.w); + const g: pardes.image.NativeGeometry = .{ .src = crop.src, .dst = crop.at.? }; try std.testing.expectEqual(@as(u32, 2), g.src.x); try std.testing.expectEqual(@as(u32, 2), g.src.w); // Put again under the same id, placement 1 moves; it is not doubled. @@ -400,8 +408,8 @@ test "kitty: a=p places one image twice by placement id, a source rect crops it, var at_ten = false; var at_one = false; for (drawn) |place| { - if (place.y == o.y + 9) at_ten = true; - if (place.y == o.y) at_one = true; + if (place.dst.y == o.y + 9) at_ten = true; + if (place.dst.y == o.y) at_one = true; } try std.testing.expect(at_ten and !at_one); } @@ -441,7 +449,7 @@ test "kitty: z-index travels with the image, and images are handed on lowest z f var ids: [4]u32 = undefined; for (drawn, 0..) |place, i| { zs[i] = place.z; - ids[i] = place.native.page; + ids[i] = r.idOf(place).?; } try std.testing.expectEqualSlices(i32, &.{ -7, 0, 3, 5 }, &zs); try std.testing.expectEqualSlices(u32, &.{ 9, 10, 11, 8 }, &ids); @@ -547,13 +555,13 @@ test "kitty: Unicode placeholders draw a virtual placement over two rows, with i const drawn = try r.placesOf(7); const o = r.origin(0); try std.testing.expectEqual(@as(usize, 2), drawn.len); - try std.testing.expectEqual(o.x + 2, drawn[0].x); - try std.testing.expectEqual(o.y + 1, drawn[0].y); - try std.testing.expectEqual(o.y + 2, drawn[1].y); - for (drawn) |place| try std.testing.expectEqual(@as(u16, 2), place.w); + try std.testing.expectEqual(o.x + 2, drawn[0].dst.x); + try std.testing.expectEqual(o.y + 1, drawn[0].dst.y); + try std.testing.expectEqual(o.y + 2, drawn[1].dst.y); + for (drawn) |place| try std.testing.expectEqual(@as(u16, 2), place.dst.w); // The top row shows the image's top half, the bottom its bottom half. - try std.testing.expectEqual(@as(u32, 0), drawn[0].native.geometry.?.src.y); - try std.testing.expectEqual(@as(u32, 1), drawn[1].native.geometry.?.src.y); + try std.testing.expectEqual(@as(u32, 0), drawn[0].src.y); + try std.testing.expectEqual(@as(u32, 1), drawn[1].src.y); } test "kitty: a placeholder naming its placement in the underline colour picks that placement" { @@ -566,7 +574,7 @@ test "kitty: a placeholder naming its placement in the underline colour picks th const drawn = try r.placesOf(7); try std.testing.expectEqual(@as(usize, 1), drawn.len); // Placement 2 spans two cells, so each cell is half the image. - try std.testing.expectEqual(@as(u16, 2), drawn[0].w); + try std.testing.expectEqual(@as(u16, 2), drawn[0].dst.w); } test "kitty: an image follows its text when the shell scrolls, resizes and reflows" { @@ -574,10 +582,10 @@ test "kitty: an image follows its text when the shell scrolls, resizes and reflo defer r.deinit(); r.feed(0, "\x1b[5;1Hmarker" ++ apc("a=T,i=10,f=24,s=4,v=2,c=2,r=1,q=2", rgb_b64)); const o = r.origin(0); - try std.testing.expectEqual(o.y + 4, (try r.placesOf(10))[0].y); + try std.testing.expectEqual(o.y + 4, (try r.placesOf(10))[0].dst.y); // Two lines of output at the bottom scroll it up two rows. r.feed(0, "\x1b[40;1H\n\n"); - try std.testing.expectEqual(o.y + 2, (try r.placesOf(10))[0].y); + try std.testing.expectEqual(o.y + 2, (try r.placesOf(10))[0].dst.y); // A narrower pane reflows the text; the image stays on its row. const pane = r.pane(0); terminal.resizeGrid(pane, 40, pane.rows); @@ -588,7 +596,7 @@ test "kitty: an image follows its text when the shell scrolls, resizes and reflo const drawn = try r.placesOf(10); try std.testing.expectEqual(@as(usize, 1), drawn.len); const viewport_top: usize = @intCast(terminal.gridOffset(pane)); - try std.testing.expectEqual(o.y + @as(u16, @intCast(row - viewport_top)), drawn[0].y); + try std.testing.expectEqual(o.y + @as(u16, @intCast(row - viewport_top)), drawn[0].dst.y); } test "kitty: the alternate screen has its own images, and the primary's come back after it" { @@ -777,7 +785,7 @@ test "kitty: a placement relative to another (P=, Q=) is drawn at its parent's c try std.testing.expectEqual(@as(usize, 3), drawn.len); const o = r.origin(0); var cells: [3][2]u16 = undefined; - for (drawn, 0..) |place, i| cells[i] = .{ place.x - o.x, place.y - o.y }; + for (drawn, 0..) |place, i| cells[i] = .{ place.dst.x - o.x, place.dst.y - o.y }; std.mem.sort([2]u16, &cells, {}, struct { fn lt(_: void, a: [2]u16, b: [2]u16) bool { return a[0] < b[0]; @@ -1167,8 +1175,8 @@ test "kitty: scrolled back by pardes, an image shows on its row; scrolled forwar const o = r.origin(0); const drawn = try r.placesOf(20); try std.testing.expectEqual(@as(usize, 1), drawn.len); - try std.testing.expectEqual(o.y, drawn[0].y); - try std.testing.expectEqual(o.x + 6, drawn[0].x); + try std.testing.expectEqual(o.y, drawn[0].dst.y); + try std.testing.expectEqual(o.x + 6, drawn[0].dst.x); terminal.followOutput(pane); try std.testing.expectEqual(@as(usize, 0), (try r.placesOf(20)).len); } @@ -1179,13 +1187,13 @@ test "kitty: an edited copy taller than the rows it covers pushes the images bel const pane = r.pane(0); r.feed(0, "\x1b[1;1Hone\r\ntwo\r\n\x1b[6;1H" ++ apc("a=T,i=21,f=24,s=4,v=2,c=2,r=1,q=2", rgb_b64)); const o = r.origin(0); - try std.testing.expectEqual(o.y + 5, (try r.placesOf(21))[0].y); + try std.testing.expectEqual(o.y + 5, (try r.placesOf(21))[0].dst.y); // Row 1 ("two") edited into three lines. pane.body.mode = .normal; pane.ovl = .{ .row = 1, .rows = 1, .text = try gpa.dupe(u8, "two\nthree\nfour") }; const drawn = try r.placesOf(21); try std.testing.expectEqual(@as(usize, 1), drawn.len); - try std.testing.expectEqual(o.y + 7, drawn[0].y); + try std.testing.expectEqual(o.y + 7, drawn[0].dst.y); } test "kitty: an image wider than its pane is cut at the pane's edge, never drawn over the next one" { @@ -1201,11 +1209,11 @@ test "kitty: an image wider than its pane is cut at the pane's edge, never drawn r.feed(0, apc("a=T,i=22,f=24,s=4,v=2,c=4,r=1,q=2", rgb_b64)); const drawn = try r.placesOf(22); try std.testing.expectEqual(@as(usize, 1), drawn.len); - try std.testing.expect(drawn[0].x + drawn[0].w <= o.x + r.pane(0).cols); - try std.testing.expect(drawn[0].x + drawn[0].w <= right); + try std.testing.expect(drawn[0].dst.x + drawn[0].dst.w <= o.x + r.pane(0).cols); + try std.testing.expect(drawn[0].dst.x + drawn[0].dst.w <= right); // And the pixels it takes are only that cell's. - const g = drawn[0].native.geometry.?; - try std.testing.expect(g.dst.w <= @as(u32, drawn[0].w) * 10); + const g: pardes.image.NativeGeometry = .{ .src = drawn[0].src, .dst = drawn[0].at.? }; + try std.testing.expect(g.dst.w <= @as(u32, drawn[0].dst.w) * 10); } test "kitty: a collapsed pane draws no image" { @@ -1224,16 +1232,16 @@ test "kitty: a new cell size (font zoom) redraws an image at the same cells, sca defer r.deinit(); r.feed(0, "\x1b[2;3H" ++ apc("a=T,i=24,f=24,s=4,v=2,c=2,r=1,q=2", rgb_b64)); var drawn = try r.placesOf(24); - try std.testing.expectEqual(@as(u32, 20), drawn[0].native.geometry.?.dst.w); + try std.testing.expectEqual(@as(u32, 20), drawn[0].at.?.w); r.p.update(.{ .resize = .{ .cols = 120, .rows = 40, .cell_pixels = .{ .w = 15, .h = 30 } } }); r.drain(); drawn = try r.placesOf(24); const o = r.origin(0); try std.testing.expectEqual(@as(usize, 1), drawn.len); - try std.testing.expectEqual(o.x + 2, drawn[0].x); - try std.testing.expectEqual(o.y + 1, drawn[0].y); - try std.testing.expectEqual(@as(u32, 30), drawn[0].native.geometry.?.dst.w); - try std.testing.expectEqual(@as(u32, 30), drawn[0].native.geometry.?.dst.h); + try std.testing.expectEqual(o.x + 2, drawn[0].dst.x); + try std.testing.expectEqual(o.y + 1, drawn[0].dst.y); + try std.testing.expectEqual(@as(u32, 30), drawn[0].at.?.w); + try std.testing.expectEqual(@as(u32, 30), drawn[0].at.?.h); } test "kitty: a dumped and restored terminal keeps its images" { @@ -1292,22 +1300,23 @@ test "kitty: recorded kitten icat and chafa traffic replays: answers whole, imag continue; }; const o = r.origin(0); - var top: ?pardes.ImagePlace = null; + var top: ?pardes.Placement = null; for (drawn) |place| { - if (top == null or place.y < top.?.y or (place.y == top.?.y and place.x < top.?.x)) top = place; + if (top == null or place.dst.y < top.?.dst.y or (place.dst.y == top.?.dst.y and place.dst.x < top.?.dst.x)) top = place; } const first = top orelse { std.debug.print("{s}: nothing drawn\n", .{rec.name}); return error.NothingDrawn; }; - std.testing.expectEqual([2]u16{ o.x + want[0], o.y + want[1] }, [2]u16{ first.x, first.y }) catch |err| { - std.debug.print("{s}: drawn at {d},{d}, live at {d},{d}\n", .{ rec.name, first.x - o.x, first.y - o.y, want[0], want[1] }); + std.testing.expectEqual([2]u16{ o.x + want[0], o.y + want[1] }, [2]u16{ first.dst.x, first.dst.y }) catch |err| { + std.debug.print("{s}: drawn at {d},{d}, live at {d},{d}\n", .{ rec.name, first.dst.x - o.x, first.dst.y - o.y, want[0], want[1] }); return err; }; } } -test "kitty: under a shell that draws no pixels, a 64x64 image over 8x4 cells is glyph art in every cell" { +test "kitty: under a shell that draws no pixels, a 64x64 image over 8x4 cells is still handed on over those cells, its cells left to the shell" { + // The glyph art a tty draws there is the tty's test (tui.zig). var r = try Rig.init(1); defer r.deinit(); r.p.frontend.native_images = false; @@ -1337,17 +1346,13 @@ test "kitty: under a shell that draws no pixels, a 64x64 image over 8x4 cells is } try cmds.appendSlice(arena, "\r\n"); r.feed(0, cmds.items); - _ = try r.places(); - const s = &r.p.surface; + const drawn = try r.places(); const o = r.origin(0); - var painted: usize = 0; - for (0..4) |dy| for (0..8) |dx| { - const cell = s.at(o.x + 7 + @as(u16, @intCast(dx)), o.y + 1 + @as(u16, @intCast(dy))); - if (cell.style.bg == .rgb and !cell.default) painted += 1; - }; - std.testing.expectEqual(@as(usize, 32), painted) catch |err| { - std.debug.print("helix theme {}: {d} cells painted\n", .{ helix, painted }); - return err; - }; + try std.testing.expectEqual(@as(usize, 4), drawn.len); + for (drawn, 0..) |place, dy| { + try std.testing.expectEqual(pardes.RectCell{ .x = o.x + 7, .y = o.y + 1 + @as(u16, @intCast(dy)), .w = 8, .h = 1 }, place.dst); + try std.testing.expect(!place.art.glyph); + try std.testing.expectEqualStrings(" ", r.p.surface.at(o.x + 7, place.dst.y).grapheme()); + } } } |
