From c8553032ef84aec74cbb5d07d07f934eecf3d4a9 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Fri, 6 Nov 2026 05:19:21 -0300 Subject: kinds #9, the core's image code gone: src/image.zig (558 lines) and the static table go, so no kind is compiled in (Registry.init, Kind.image, compiledIn, `static` in /addons and "is compiled in" with them) and a test of the core's side of a kind's pane opens Kind.test_kind (a picture of one pixel, no library); a placement's fit (NativeGeometry, containGeometry) moves to surface.zig and a PDF's fit modes to pdf_view.zig; a terminal's kitty PNG decodes in TerminalImages.zig through wuffs as before, its downscale through stb_image_resize, the one part of zstbi the core keeps (stb_image patched out of it, the wuffs_images option, tag_image and image_exts gone); the image cases load the built image.so by path: test/panes.zig's and fs_namespace's through Addon.perform, T1 through Addon load (a new behaviour case: PNG, JPEG and PPM through 9P, the art words, a refused corrupt PNG, a dump's placeholder and its picture back, which replaces the decode unit test and ctl.zig's corrupt-image case), the snapshot, process and image harnesses by linking it into each session's data directory; images.snap unchanged Co-Authored-By: Claude Fable 5.1 Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge --- test/panes.zig | 56 ++++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 48 insertions(+), 8 deletions(-) (limited to 'test/panes.zig') diff --git a/test/panes.zig b/test/panes.zig index e0c383fd..28a884ab 100644 --- a/test/panes.zig +++ b/test/panes.zig @@ -8,7 +8,6 @@ const Key = pardes.Key; const config = pardes.config; const modal = pardes.modal; const dump = pardes.dump; -const image = pardes.image; const syntax = pardes.syntax; const filesystem = pardes.filesystem; @@ -2246,24 +2245,65 @@ const OutputTests = struct { } }; +/// The image addon (addons/image/image.c), loaded as `Addon load` loads it. const ImageTests = struct { + fn load(p: *Pardes) u8 { + pardes.Addon.perform(p, .load, 0, @import("test_addons").image); + return p.kinds.byName("image").?; + } + test "pane-local renderer choices are visible in the image tag" { const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true }); defer p.deinit(); - pardes.image.start(std.testing.io, std.testing.allocator); - defer pardes.image.stop(); // A picture shown (its decode landed, a frame drawn): the core's // art words after the kind's `img`, then its path. const id = p.freeSlot().?; - const pane = try pardes.Kind.open(p, id, pardes.Kind.image, "/tmp/picture.ppm", "P6\n1 1\n255\n\x01\x02\x03"); + const pane = try pardes.Kind.open(p, id, load(p), "/tmp/picture.ppm", "P6\n1 1\n255\n\x01\x02\x03"); while (p.nextEffect()) |e| p.perform(e); pardes.exec.placeNew(p, 0, 0, id, .doc); _ = try p.render(p.scratch.allocator()); pane.addon.?.art = .{ .glyph = true, .palette = .terminal, .ascii = false }; - try std.testing.expectEqualStrings( - config.tag_image ++ " petscii:on palette:terminal ascii:off /tmp/picture.ppm", - try pardes.tagline.tagPrefix(p, pane), - ); + try std.testing.expectEqualStrings("img petscii:on palette:terminal ascii:off /tmp/picture.ppm", try pardes.tagline.tagPrefix(p, pane)); + } + + test "an image's dump keeps its file's bytes, its renderer choices and its tag's tail" { + const gpa = std.testing.allocator; + const p = try Pardes.init(gpa, .{ .tty_only = true }); + defer p.deinit(); + try pardes.panes.deinitPane(p, p.panes[0].?); + p.panes[0] = null; + + const source = "P6\n1 1\n255\n\x0d\x4d\xe7"; + const k = load(p); + const pane = try pardes.Kind.open(p, 0, k, "/missing/restored-image.ppm", source); + pane.addon.?.art = .{ .glyph = true, .palette = .terminal, .ascii = false }; + if (pane.tag.own) |own| p.gpa.free(own); + pane.tag.own = try p.gpa.dupe(u8, " Keep Del"); + try dump.dumpState(p); + + // Restored where its addon is (a Restore's kinds are the process's). + var words: [64]pardes.Kind.LoadedWord = undefined; + const e = &p.kinds.kinds[k]; + const brought = [_]pardes.Kind.Loaded{pardes.Kind.loadedOf(p.kinds.ops[k].?, e.path.slice(), e.hash, &words)}; + const restored = try dump.initFromDump(gpa, .{ .tty_only = true, .addons = &brought }, p.dump_out.?); + defer restored.deinit(); + const restored_pane = restored.panes[0].?; + const art = restored_pane.addon.?.art; + try std.testing.expect(art.glyph); + try std.testing.expectEqual(pardes.Placement.Art.Palette.terminal, art.palette); + try std.testing.expect(!art.ascii); + try std.testing.expect(restored_pane.tag.own != null); + try std.testing.expectEqualStrings(" Keep Del", pardes.tagline.curTail(restored_pane)); + var kept: [64]u8 = undefined; + const slot = restored_pane.addon.?; + try std.testing.expectEqualSlices(u8, source, kept[0..slot.ops.?.dump.?(slot.st, &kept, kept.len)]); + + // And dumped again, its bytes still there. + try dump.dumpState(restored); + const again = try dump.load(gpa, .{ .tty_only = true }, restored.dump_out.?, null); + defer again.deinit(); + // Loaded as a replica loads it: a placeholder holding the record. + try std.testing.expectEqualSlices(u8, source, again.panes[0].?.addon.?.record.?); } }; -- cgit v1.3