summaryrefslogtreecommitdiff
path: root/src/terminal.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-05 22:21:45 -0300
committerGabriel Schneider <[email protected]>2026-11-05 23:08:36 -0300
commit71e5a0f4a8685b385fac762995d45575b638179f (patch)
treebf643875b0567b45cf659c1b3ad4b872f311a774 /src/terminal.zig
parentd8e5fc18f5923c4213de1cb4105a677e725200af (diff)
downloadpardes-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 'src/terminal.zig')
-rw-r--r--src/terminal.zig72
1 files changed, 26 insertions, 46 deletions
diff --git a/src/terminal.zig b/src/terminal.zig
index 6f9e2071..a285d1f8 100644
--- a/src/terminal.zig
+++ b/src/terminal.zig
@@ -3142,7 +3142,7 @@ pub fn drawImages(p: *Pardes, s: *Surface, pane: *Pane, id: usize, tx: u16, tw:
}
// Nothing to draw, no placeholder to blank and nothing cached to let
// go: the common case costs the rows' flags.
- if (!any_placeholder and screen.kitty_images.placements.count() == 0 and state.images.converted.count() == 0 and state.images.glyphs.count() == 0) return;
+ if (!any_placeholder and screen.kitty_images.placements.count() == 0 and state.images.converted.count() == 0) return;
state.images.draw(p, s, &state.vt, @intCast(id), pane.serial, tx, body_y, @min(tw, pane.cols), rows_of[0..vp_rows]);
}
@@ -3210,8 +3210,8 @@ inline fn kittyTransmit(comptime extra: []const u8) []const u8 {
};
}
-fn imagePlaces(s: *const Surface) []const pardes.ImagePlace {
- return s.images.items;
+fn imagePlaces(s: *const Surface) []const pardes.Placement {
+ return s.placements.items;
}
test "a terminal's kitty graphics image is drawn where its program placed it, and a delete takes it away" {
@@ -3232,25 +3232,20 @@ test "a terminal's kitty graphics image is drawn where its program placed it, an
try std.testing.expectEqual(@as(usize, 1), places.len);
const place = places[0];
const r = p.rects[0];
- try std.testing.expect(place.native.exact);
- try std.testing.expectEqual(@as(u32, 7), place.native.page);
- try std.testing.expectEqual(pane.serial, place.serial);
- try std.testing.expectEqual(r.x + config.GUTTER + 4, place.x);
- try std.testing.expectEqual(p.bodyTop(pane, r) + 2, place.y);
- try std.testing.expectEqual(@as(u16, 2), place.w);
- try std.testing.expectEqual(@as(u16, 1), place.h);
- try std.testing.expectEqual(@as(usize, 4), place.iw);
- try std.testing.expectEqual(@as(usize, 2), place.ih);
- try std.testing.expectEqualSlices(u8, &.{ 255, 0, 0, 255 }, place.rgba[0..4]);
- const g = place.native.geometry.?;
- try std.testing.expectEqual(pardes.image.PixelRect{ .x = 0, .y = 0, .w = 4, .h = 2 }, g.src);
- try std.testing.expectEqual(pardes.image.PixelRect{ .x = 0, .y = 0, .w = 20, .h = 20 }, g.dst);
+ const img = pane.terminal.?.vt.screens.active.kitty_images.imageById(7).?;
+ try std.testing.expectEqual(pardes.Placement.keyOf(pane.serial, 7, @truncate(img.generation)), place.key);
+ try std.testing.expectEqual(pardes.RectCell{ .x = r.x + config.GUTTER + 4, .y = p.bodyTop(pane, r) + 2, .w = 2, .h = 1 }, place.dst);
+ try std.testing.expectEqual(@as(u32, 4), place.raster.w);
+ try std.testing.expectEqual(@as(u32, 2), place.raster.h);
+ try std.testing.expectEqualSlices(u8, &.{ 255, 0, 0, 255 }, place.raster.bytes()[0..4]);
+ try std.testing.expectEqual(pardes.RectPx{ .x = 0, .y = 0, .w = 4, .h = 2 }, place.src);
+ try std.testing.expectEqual(pardes.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" } });
_ = frame.reset(.retain_capacity);
s = try p.render(frame.allocator());
- try std.testing.expectEqual(p.bodyTop(pane, r), imagePlaces(s)[0].y);
+ try std.testing.expectEqual(p.bodyTop(pane, r), imagePlaces(s)[0].dst.y);
p.update(.{ .output = .{ .pane = 0, .bytes = "\n" } });
_ = frame.reset(.retain_capacity);
s = try p.render(frame.allocator());
@@ -3362,15 +3357,13 @@ test "a virtual kitty placement shows through its placeholder cells, which draw
const r = p.rects[0];
const tx = r.x + config.GUTTER;
const y = p.bodyTop(pane, r) + 1;
- try std.testing.expectEqual(tx + 2, places[0].x);
- try std.testing.expectEqual(y, places[0].y);
- try std.testing.expectEqual(@as(u16, 2), places[0].w);
+ try std.testing.expectEqual(pardes.RectCell{ .x = tx + 2, .y = y, .w = 2, .h = 1 }, places[0].dst);
try std.testing.expectEqualStrings(" ", s.at(tx + 2, y).grapheme());
try std.testing.expectEqualStrings(" ", s.at(tx + 3, y).grapheme());
try std.testing.expectEqualStrings("X", s.at(tx + 4, y).grapheme());
}
-test "without pixels, or by the Petscii builtin, a terminal's image is glyph art in its cells" {
+test "a terminal's image is a placement whatever the frontend draws, and the Petscii builtin asks for it as glyph art" {
if (comptime !images_enabled) return error.SkipZigTest;
const gpa = std.testing.allocator;
const p = try Pardes.init(gpa, .{ .cols = 80, .rows = 24, .shells = 1 });
@@ -3384,40 +3377,27 @@ test "without pixels, or by the Petscii builtin, a terminal's image is glyph art
const r = p.rects[0];
const tx = r.x + config.GUTTER;
const y = p.bodyTop(pane, r);
- const commodore = pardes.image.GlyphArt.commodore;
- const painted = struct {
- fn check(cell: *const pardes.Cell) bool {
- const bg = switch (cell.style.bg) {
- .rgb => |rgb| rgb,
- else => return false,
- };
- for (commodore) |c| if (std.mem.eql(u8, &c, &bg)) return true;
- return false;
- }
- }.check;
- // A shell that draws no pixels (a tty under no kitty graphics): forced.
+ // A frontend that draws no pixels (a tty under no kitty graphics) is
+ // handed the picture all the same, and the cells under it are its.
p.frontend.native_images = false;
var s = try p.render(frame.allocator());
- try std.testing.expectEqual(@as(usize, 0), imagePlaces(s).len);
- try std.testing.expect(painted(s.at(tx, y)) and painted(s.at(tx + 1, y)));
- try std.testing.expect(!painted(s.at(tx + 2, y)));
- // The tag says what is drawn, glyph art, as an image pane's does.
+ try std.testing.expectEqual(@as(usize, 1), imagePlaces(s).len);
+ try std.testing.expect(!imagePlaces(s)[0].art.glyph);
+ try std.testing.expectEqualStrings(" ", s.at(tx, y).grapheme());
+ try std.testing.expectEqualStrings(" ", s.at(tx + 1, y).grapheme());
+ // The tag says what that frontend draws, glyph art, as an image pane's does.
try std.testing.expect(std.mem.indexOf(u8, try tagline.tagPrefix(p, pane), " petscii:on") != null);
- // Pixels where they can be drawn; the builtin flips the pane to glyphs
- // and back.
+ // The builtin flips the pane to glyph art and back.
p.frontend.native_images = true;
- _ = frame.reset(.retain_capacity);
- s = try p.render(frame.allocator());
- try std.testing.expectEqual(@as(usize, 1), imagePlaces(s).len);
try std.testing.expect(p.executeBuiltinLine(0, "Petscii"));
_ = frame.reset(.retain_capacity);
s = try p.render(frame.allocator());
- try std.testing.expectEqual(@as(usize, 0), imagePlaces(s).len);
- try std.testing.expect(painted(s.at(tx, y)));
+ try std.testing.expectEqual(@as(usize, 1), imagePlaces(s).len);
+ try std.testing.expect(imagePlaces(s)[0].art.glyph);
try std.testing.expect(std.mem.indexOf(u8, try tagline.tagPrefix(p, pane), " petscii:on") != null);
- // Dumped and restored, it is still glyph art.
+ // Dumped and restored, it still asks for glyph art.
try pardes.dump.dumpState(p);
const restored = try pardes.dump.restore(p, p.dump_out.?, "/tmp/pardes.dump.zon");
defer restored.deinit();
@@ -3425,7 +3405,7 @@ test "without pixels, or by the Petscii builtin, a terminal's image is glyph art
try std.testing.expect(p.executeBuiltinLine(0, "Petscii"));
_ = frame.reset(.retain_capacity);
s = try p.render(frame.allocator());
- try std.testing.expectEqual(@as(usize, 1), imagePlaces(s).len);
+ try std.testing.expect(!imagePlaces(s)[0].art.glyph);
}
test "TermImages is real by default, and petscii makes new terminals draw glyph art" {