summaryrefslogtreecommitdiff
path: root/test/behaviour/addons_pdf.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-26 03:03:20 -0300
committerGabriel Schneider <[email protected]>2026-11-26 03:03:25 -0300
commit280306ed779368d7e20e9678eca45e4b81e0ccbf (patch)
tree9278534f32a3724b289761594ca658cb6549b227 /test/behaviour/addons_pdf.zig
parent1ce3bcb6178b720058518a12e45f25769be7d39c (diff)
downloadpardes-280306ed779368d7e20e9678eca45e4b81e0ccbf.tar.gz
pardes-280306ed779368d7e20e9678eca45e4b81e0ccbf.zip
Pick, Kind, look, draw, mouse: a picker previews a file an addon's kind takes through that kind in the pane it lands in, a binary no kind takes as one line naming it, and Enter on such a row lands as a Look does, never the file's bytes as text (the user: "the file preview wasn't working for images (maybe pdfs too? Didn't test)", "It should be a generic logic for addons btw, and I saw the bytes rendered as ascii"; the coordinator's W7 under SPEC principle 2); REPRODUCED with the installed build (install74, the S kit, 26 px): SPC f f from a reading main.zig, the cursor on photo.png left main.zig in the body (the previous row's file), on paper.pdf showed `%PDF-1.7 %âãÏÓ 1 0 obj …` as text (a PDF has no NUL in its first 8000 bytes, so Pick.preview's binary guard let it through), and Enter on photo.png put `�PNG … IHDR …` in the reading pane: THE BYTES-AS-TEXT PATH the user saw: Pick.land → look.open → walk → Trail.step → Trail.show → File.open, which reads any path as a text (look.resolve sends a typed or clicked `photo.png` to Kind.openFile, but look.open, every jump's way, had no kind route); THE FIX: look.open routes a path a kind takes (`kinds.forPath`, the routing resolve uses) to openKind, lookAt's kind branch made a function (the pane of it focused, else opened and placed as a Look places it), so a picker's Enter, the Walk queue and a held pane's step land as a Look; Find's row of a kind's file is the file whole (a place in it is its kind's address: line 1 made the image refuse it); Pick.preview: a file a kind takes is shown by a slot of that kind over the landing pane's text (Kind.newSlot, split from Kind.open; Pick.showKind), which stays under it unseen until the next row or the roll-up closes the slot (putBack, restore: Esc exact, nothing left), no per-kind code; any other file with a NUL is one read-only line, `blob.bin · binary · 3.0 kB` (Pick.nameLine); until the kind draws (its paint places nothing yet) the body shows `photo.png · image · 24.8 kB` (draw.zig; Kind.draw says whether it painted); a refused one is that line with its kind's why; the kind does its own work as for its pane (the image decoded on a worker); only the row the cursor rests on at a frame opens (the preview's existing tick rule), and a draw of a row passed by is dropped when it lands (Kind.Slot.drawn_from: this process's draw count when the slot was made; Kind.deliver drops older answers, which went to the next slot of the same kind on the same pane); a previewed kind says, looks at, runs and lists nothing (Kind.Call.end returns before them while Pick.previewing) and takes no mouse (mouse.kindMouse); RUN (TEST FIRST): test/behaviour/addons.zig, four tests through 9P with the fake addon (addons/fake: no kind code in Pick) and the image addon, and addons_pdf.zig one with the pdf addon: a `.fake` file previews as the fake's paint (`count 7`) and not its bytes, Esc puts the screen and /index back, Enter opens the fake's pane with the reading pane's text kept; blob.bin's one line, never other.txt's text after it, a kind's paint after the binary's; three pictures, two rows down with no frame between: one draw held per rested row (2, not 3), and the rested picture shown after the passed one's answer came last; Enter on a picture opens the image pane, the reading pane `the notes`; a PDF's pages as pictures in the landing pane, none after Esc; Session.tick (a host frame) added, as previews wait for the frame after the key; on the base they fail (the bytes `1234567` shown, no line, no image pane, `%PDF` on the screen): core-test 1128/1301 (173 skipped; the kept_out list names Kind.Slot's drawn_from and size), shell-test 1349/1352 (3 skipped), pane-test 183/184, behaviour-test 285/285 (+5) and --replay 285/285, process-test 0 of 147 failed (3 skipped), term-test 17/17, kitty-test 45/45; the gui unit-test on the stack's top (W8); no dump change (the two Slot fields are local, out of the digest and the dump); the S kit with this change's Debug gui at 26 px: the PNG and 9p.pdf previewing in the landing pane, blob.bin's line, Enter on photo.png an `img` pane with main.zig kept (.scratch/walkui/W78/png a02-a05, before r03 r05); no frame or perf gate (the user's rule of 2026-11-26); load 3.7 to 10
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNBFhdevVu48bvL9kCE
Diffstat (limited to 'test/behaviour/addons_pdf.zig')
-rw-r--r--test/behaviour/addons_pdf.zig28
1 files changed, 28 insertions, 0 deletions
diff --git a/test/behaviour/addons_pdf.zig b/test/behaviour/addons_pdf.zig
index 0c7982d1..d773f4e2 100644
--- a/test/behaviour/addons_pdf.zig
+++ b/test/behaviour/addons_pdf.zig
@@ -299,3 +299,31 @@ test "addons: a PDF whose file changes on disk while a page of it renders: the p
try s.keys("0");
try std.testing.expect((try shown(&s, n)).len >= 1);
}
+
+test "addons: a PDF under a picker's cursor shows through the pdf addon in the pane it lands in, never its bytes as text, and Esc puts the pane's own text back" {
+ var s = try Session.initFile(std.testing.allocator, "x\n");
+ defer s.deinit();
+ s.graphics();
+ try s.loadPdf();
+ var tmp = std.testing.tmpDir(.{});
+ defer tmp.cleanup();
+ const pdf = try std.Io.Dir.cwd().readFileAlloc(std.testing.io, "docs/design.pdf", s.arena.allocator(), .limited(4 << 20));
+ try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "paper.pdf", .data = pdf });
+ try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "notes.txt", .data = "the notes\n" });
+ var buf: [4096]u8 = undefined;
+ const dir = buf[0..try tmp.dir.realPath(std.testing.io, &buf)];
+ const pane = try s.lookFile(s.at("{s}/notes.txt", .{dir}));
+ try s.keys(" ffpaper");
+ // (Its kind told its view at the frame after the one that opened it.)
+ s.tick();
+ s.tick();
+ const screen = try s.screen();
+ try std.testing.expect(!has(screen, "%PDF") and !has(screen, "the notes"));
+ // Its pages pictures in that pane's body, as a PDF's pane shows them.
+ try std.testing.expect((try shown(&s, pane)).len > 0);
+ try s.keys("\x1b");
+ s.tick();
+ try s.expect(s.at("/pane/{d}/body", .{pane}), "the notes\n");
+ try std.testing.expectEqual(0, (try shown(&s, pane)).len);
+ try std.testing.expect(has(try s.screen(), "the notes"));
+}