diff options
| author | Gabriel Schneider <[email protected]> | 2026-10-28 21:03:48 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-10-28 21:23:53 -0300 |
| commit | b250eb6135475699a945324c005890e8e1b4dd0b (patch) | |
| tree | c32f06f89cdbd501ba5d75dc8ba80ecebbe3c278 /src/TerminalImages.zig | |
| parent | a48a825b06cc45947adaecf42073ed86af8b7a2d (diff) | |
| download | pardes-b250eb6135475699a945324c005890e8e1b4dd0b.tar.gz pardes-b250eb6135475699a945324c005890e8e1b4dd0b.zip | |
kitty graphics conformance for terminal panes: a core suite (test/kitty.zig, `zig build kitty-test`, in unit-test) and an end-to-end harness (`zig build kitty-harness`, tty and gui); four gaps it found fixed, one left
The core suite feeds a pane's output as pty reads do and checks what the program reads back, ghostty's image storage and the ImagePlaces a frame draws: queries and their errors, q=0/1/2, f=24/32/100 and o=z, chunked m=1 split at every read size, t=f/t=t/t=s, a=T and C=1 cursor movement, a=p by placement id with source rects and re-puts, image numbers, every d= delete (a/A i/I n/N c/C p/P q/Q x/X y/Y z/Z r/R) and a delete abandoning a chunked load, Unicode placeholders over two rows with implicit columns and a placement named in the underline colour, scroll/resize/reflow, the alternate screen, clear (ED 2 + ED 3), replies per pane and never in the cells, many replies from one read, kitty before DA, CAN/SUB, an oversized image, 300 images against the storage limit, animations and relative placements.
The harness runs test/kitty_client.zig in a pane's bash (query, a 16-chunk 8x4-cell place, the three media, quiet levels, CAN, show then delete) and kitten icat (stream and detect) and chafa when installed. Outside, the tty arm is a kitty terminal (a ghostty-vt emulator): the image pardes re-emits lands at the cell after ANCHOR>, 8x4 cells a row at a time, the client's own commands and replies never pass through, and d=I frees what was sent. The gui arm reads the GPU capture.
Fixed: kitty file, temporary-file and shared-memory media (libghostty defaults to direct only; now allWithTempDir like ghostty and kitty); replies past 256 bytes of one read were cut mid-sequence (4 KiB now, an answer that does not fit dropped whole and counted); animations never played (TerminalImages draws renderData(), ticks ImageStorage.animationTick on the core clock, nextWake wakes for the next frame); relative placements (P=/Q=/H=/V=) were not drawn (resolveChain, as ghostty's renderer). image.decode no longer jumps through stb_image's null allocator before image.start.
Known gap (a knownGap test): no z-index; every image is drawn over the cells in storage order.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Diffstat (limited to 'src/TerminalImages.zig')
| -rw-r--r-- | src/TerminalImages.zig | 35 |
1 files changed, 29 insertions, 6 deletions
diff --git a/src/TerminalImages.zig b/src/TerminalImages.zig index 4140813f..f3333460 100644 --- a/src/TerminalImages.zig +++ b/src/TerminalImages.zig @@ -29,6 +29,9 @@ petscii: bool = false, converted: std.AutoHashMapUnmanaged(u32, Converted) = .empty, /// Glyph art for the fragments drawn as cells, kept while on screen. glyphs: std.AutoHashMapUnmanaged(GlyphKey, Glyphs) = .empty, +/// When the next frame of a playing animation (a=a) is due, in ms on the +/// core's clock (`Pardes.stepped_ns`): the core wakes for it (nextWake). +animation_due_ms: ?u64 = null, const Converted = struct { generation: u64, rgba: []u8, used: bool = true }; const Glyphs = struct { cells: []GlyphArt.Cell, used: bool = true }; @@ -147,6 +150,11 @@ pub fn draw( const screen = vt.screens.active; const storage = &screen.kitty_images; + // Animations step on the core's clock, as this frame shows them; the + // shown frame is `renderData()` (a new `generation` each step, which + // the caches key on). + const now_ms = p.stepped_ns / std.time.ns_per_ms; + ti.animation_due_ms = if (storage.animationTick(vt.io(), now_ms)) |delay| now_ms +| delay else null; const pages = &screen.pages; const top = pages.getTopLeft(.viewport); const bottom = pages.getBottomRight(.viewport) orelse return; @@ -187,10 +195,25 @@ pub fn draw( var it = storage.placements.iterator(); while (it.next()) |entry| { const placed = entry.value_ptr.*; + // A placement relative to another (P=/Q=) sits at its chain's root + // plus the chain's cell offsets (H=/V=), as ghostty's renderer puts it. + var dx: i64 = 0; + var dy: i64 = 0; const pin = switch (placed.location) { .pin => |pin| pin, - // ponytail: a placement relative to another (P=/Q=, new in ghostty) is not drawn; resolve its chain if a program needs it. - .virtual, .relative => continue, + .virtual => continue, + .relative => |rel| root: { + const chain = storage.resolveChain(rel) orelse continue; + dx = chain.horizontal_offset; + dy = chain.vertical_offset; + break :root switch (chain.root.location) { + .pin => |pin| pin, + // ponytail: a chain rooted on a virtual placement (shown + // through placeholders) is not drawn; ghostty anchors it at + // the placeholder run. + .virtual, .relative => continue, + }; + }, }; const img = storage.images.get(entry.key_ptr.image_id) orelse continue; const at = pages.pointFromPin(.screen, pin.*) orelse continue; @@ -201,8 +224,8 @@ pub fn draw( const sh = if (placed.source_height > 0) @min(placed.source_height, img.height - sy) else img.height - sy; if (size.width == 0 or size.height == 0 or sw == 0 or sh == 0) continue; ctx.place(img, .{ .x = sx, .y = sy, .w = sw, .h = sh }, .{ - .x = @as(i64, at.screen.x) * cw + placed.x_offset, - .y = (@as(i64, at.screen.y) - @as(i64, origin.screen.y)) * ch + placed.y_offset, + .x = (@as(i64, at.screen.x) + dx) * cw + placed.x_offset, + .y = (@as(i64, at.screen.y) - @as(i64, origin.screen.y) + dy) * ch + placed.y_offset, .w = size.width, .h = size.height, }); @@ -289,7 +312,7 @@ const Ctx = struct { fn pixelsOf(ti: *TerminalImages, gpa: std.mem.Allocator, img: gfx.Image) ?[]const u8 { const n = @as(usize, img.width) * img.height; if (n == 0) return null; - const data = img.data.bytes() orelse return null; + const data = img.renderData().bytes() orelse return null; if (img.format == .rgba) return if (data.len == n * 4) data else null; const gop = ti.converted.getOrPut(gpa, img.id) catch return null; if (gop.found_existing) { @@ -316,7 +339,7 @@ fn convert(gpa: std.mem.Allocator, img: gfx.Image, n: usize) ?[]u8 { .gray => 1, else => return null, }; - const data = img.data.bytes() orelse return null; + const data = img.renderData().bytes() orelse return null; if (data.len != n * depth) return null; const out = gpa.alloc(u8, n * 4) catch return null; for (0..n) |i| { |
