summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-06 15:58:05 -0300
committerGabriel Schneider <[email protected]>2026-11-06 17:53:43 -0300
commit2ddd5bcbe8d470c00b045af5822418fe429357bc (patch)
tree47d837b2151a7393bdcf5ba362b8c2f6bf457f55
parente9f9f65ace7650a02cee6bf2b2eb466522485834 (diff)
downloadpardes-2ddd5bcbe8d470c00b045af5822418fe429357bc.tar.gz
pardes-2ddd5bcbe8d470c00b045af5822418fe429357bc.zip
kinds #37, tests and docs for ABI 3: the image dump tests reopen from the path (through the same /n/os mount, and a file gone waits saying so until a watch or a Look opens it), the PDF view tests assert the art words in every view and each view told, /addons says 3.0 and a 2.2 fake is refused, reference.typ's Addons section and the changelog say ABI 3
Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
-rw-r--r--docs/typ/reference.typ95
-rw-r--r--src/CHANGELOG.md11
-rw-r--r--test/behaviour/addons.zig29
-rw-r--r--test/behaviour/addons_pdf.zig2
-rw-r--r--test/fs_namespace.zig16
-rw-r--r--test/panes.zig63
-rw-r--r--test/pdf_scroll_bench.zig2
7 files changed, 140 insertions, 78 deletions
diff --git a/docs/typ/reference.typ b/docs/typ/reference.typ
index 4763f36c..22065cd1 100644
--- a/docs/typ/reference.typ
+++ b/docs/typ/reference.typ
@@ -984,9 +984,13 @@ Exec, a message, a new text pane, its selection) it is handed at load.
`paint` is a valid one. In Zig, `src/kinds/addon.zig` (over the same
header, and nothing of the core) makes the `pa_ops` from a struct of the
functions a kind has (`export const pardes_addon = addon.ops(Snake);`),
-with the pane's arena as a `std.mem.Allocator`, typed keys, a window to
-`put` text in, a deadline for `tick`, a struct's bytes as its record, and
-its own `zig test` (`zig build addon-test` runs them):
+wrapping every function of the header and every call of `pa_api`: the
+pane's arena and pardes's heap as `std.mem.Allocator`s, typed keys, clicks
+and views, a window to `put` text in (column first, where the header's
+`pa_put` is row first), a deadline for `tick`, a `prefix` written after
+every tick, a struct's bytes as its record, and its own `zig test` (`zig
+build addon-test` runs them); a Zig kind outside the tree runs `zig
+translate-c src/kinds/pardes_addon.h` once for the header:
`addons/snake/snake.zig` is a game in it. Pictures
are an addon too, `addons/image/image.zig` (PNG, JPEG, GIF, BMP, PPM, PGM and
TGA through stb_image, at most 1280 pixels a side), which `zig build image`
@@ -999,26 +1003,35 @@ PDF on a terminal without graphics shows its page's text layer, the moving
keys and the wheel a page a step; with them its pages, a fast scroll
rendering only the rows each page shows until it rests, a touchpad's turn
moving it by its fraction of a row, and the pointer a hand over a link.
-The header is ABI 2.2: an addon built against another major is refused,
-and an older one runs as it did (2.1 added at the ends of its records:
-`heap`, `view`, `exec` and `select` in its `pa_api`, the rail's thumb in
-`pa_paint`, its own `search`; 2.2 the core's ABI in `pa_api`, a wheel's
-`amount` in `pa_mouse`, `glyphs` in `pa_view`, the `pointer` in
-`pa_paint` and PA_FRAMED in tick's flags).
+The header is ABI 3.0: an addon built against another major (a 2.x one)
+is refused. A kind's state is one thing, stepped by `tick` however many
+views (windows and terminals on the session) show it; what each view sees
+of it is laid out by `view` and drawn by `paint`.
-- `tick(state, now, flags)` returns the absolute time of its next step
- (0: none) on a monotonic clock. It is called when that time comes and
- once after `open`, a key or click it took, a word, a job's answer, a
- `load`, and whenever `PA_FOCUSED` (its pane has the keyboard in some
- view, its window focused) changes: a kind that returned 0 is woken by
- the next thing that happens to it, and one that steps only while focused
- asks for nothing otherwise. `paint` is called once a frame and changes
- nothing (a Debug build checks the kind's memory across it).
-- The tag of its pane is the prefix its last frame gave (else its kind's
- name), then, when that frame placed a picture, the core's own
- `petscii:on palette:commodore ascii:off` (#word("Petscii"),
- #word("Palette") and #word("Ascii") are the core's words), then its
- path.
+- `tick(state, t)` steps the state at `t->now` on a monotonic clock, and
+ sets `t->next`, the absolute time of its next step (0: none), and
+ `t->prefix`, the start of its pane's tag. It is called when that time
+ comes and once after `open`, a key or click it took, a word, a job's
+ answer, a `load`, a `view`, and whenever `PA_FOCUSED` (its pane has the
+ keyboard in some view, its window focused) changes: a kind that set no
+ next step is woken by the next thing that happens to it, and one that
+ steps only while focused asks for nothing otherwise.
+- `view(state, v)` is called when a view starts showing the pane, when its
+ facts change (its cells, a cell's pixels, the theme, whether it shows
+ pictures as glyph art) and when it stops (`v->cols` 0), `v->id` naming
+ the view; a kind lays out for it and asks for its rasters there. A key
+ and a click say the view they came from. `paint` is called once a frame
+ in each view, `win->view` the one, and changes nothing (a Debug build
+ checks the kind's memory across it); a picture over 32 MiB is dropped.
+- Every call returns within 2 ms; what takes longer goes on a job. A Debug
+ pardes says a call over 16 ms once (`pdf: search took 118 ms, over 16
+ ms`) and `--addon-test` fails on it.
+- The tag of its pane is the prefix its last tick set (else its kind's
+ name), then, for a kind whose head says `PA_PICTURES` (image, PDF), the
+ core's own `petscii:on palette:commodore ascii:off` from its first frame,
+ the same in every view (`petscii:on` when #word("Petscii") says so or the
+ session's first view shows no pictures; #word("Petscii"),
+ #word("Palette") and #word("Ascii") are the core's words), then its path.
- Its jobs run on the host's workers, allocating from what the job is
handed (the last allocation the answer); one asked before an
#word("Addon") `reload` answers into nothing, and the old library stays
@@ -1044,35 +1057,43 @@ and an older one runs as it did (2.1 added at the ends of its records:
kind opens a pane of it from anywhere, its argument the path; any other
elsewhere is refused. A Look of a file whose extension an addon claims
opens a pane of its kind.
-- A pane of an addon's kind takes every key but #key("Esc") when its kind
- takes keys, as a raw terminal does (#key("Esc") too, first, for a kind
- of 2.1: not taken, it leaves), and its clicks when it takes the mouse,
+- A pane of an addon's kind takes every key when its kind takes keys, as
+ a raw terminal does (#key("Esc") first: not taken, it leaves), and its
+ clicks when it takes the mouse,
a press's drag and release wherever they go, and a motion off its body
- when the pointer leaves it. `tick` is called again when its view (its
- window, a cell's pixels, the theme) changes. A `/` in it asks its kind's
- `search`, a `+Search` of its rows; a Look of `file:<place>` (`:<place>`
+ when the pointer leaves it. A `/` in it asks its kind's `search`, which
+ returns at once, a `+Search` of the rows it hands `found` (then or later,
+ from a job); a kind may `cancel` a job whose answer it no longer wants.
+ A Look of `file:<place>` (`:<place>`
in it) is its kind's `address`, a miss said `<path>` and what the kind
said (`has no page 99`), one from a list its kind made (`text`) handed
with the list's name first (`+PdfSections 3:2`). Its #file("body") is the kind's text, if it has any; its
#file("ctl") read ends with the kind's own fields.
- A dump keeps each such pane: its kind, version, path and place, and the
- kind's own record (a PDF's: its file's bytes, its fit, tint and page).
+ kind's own record, its small state of at most 1 MiB (a PDF's: its fit,
+ tint and page; a picture has none), never the file: a Restore reads the
+ file at its path as a Look does, then hands the kind the record.
Restored without its addon, the pane waits in its place saying `addon
<name> <version> is not loaded: Addon load <path>`; the addon loaded, it
- opens there. One with no record opens from its file, at its place, its
- words given again; a PDF pane of a dump made before the PDF addon comes
- back so. A pane whose file changes on disk opens again from it, its
- record kept for its `load` (a PDF stays on its page).
+ opens there. Restored without its file, it waits saying `<path> is not
+ here`, its record kept, and opens at the next Look or watch of the path.
+ One with no record opens from its file, at its place, its words given
+ again; a PDF pane of a dump made before the PDF addon comes back so. A
+ pane whose file changes on disk opens again from it, its record kept for
+ its `load` (a PDF stays on its page).
- An addon runs in pardes's process. A load is marked on disk while it
runs; a start that finds the mark of one that never finished skips that
library, listed so, until #word("Addon") `load` asks for it again. A
crash inside one says `in addon <file>, <call>` in the crash record.
- `pardes --addon-test <lib> <script>` runs a script of keys, clicks,
words and ticks (its clock starts at 1 s), `focus` and `blur`, `size C
- R` (the session's terminal), `dump` (the pane's record, loaded into a
- fresh pane), `body` and `ctl` against a pane of its kind and prints the
- pane after each, with `window CxR` (the cells it paints) at the start
- and after `size`: an addon's test, compared with `diff`. `settle` ticks
+ R` (the session's terminal), `graphics on|off`, `view N on|off` (into
+ view N, a second client's, with pictures or not; `size`, `focus` and
+ `graphics` are the current view's), `dump` (the pane's record, loaded
+ into a fresh pane), `body` and `ctl` against a pane of its kind and
+ prints the pane after each, as the current view sees it, with `window
+ CxR` (the cells it paints) at the start and after `size`: an addon's
+ test, compared with `diff`. `settle` ticks
until the kind asks for no step, and fails for one that asks while idle.
`key` sends the rest of its line, its ends trimmed and a space within
sent as one, a character a key; `<space>`, `<enter>`, `<tab>`, `<bs>`,
diff --git a/src/CHANGELOG.md b/src/CHANGELOG.md
index c465032d..a6922a07 100644
--- a/src/CHANGELOG.md
+++ b/src/CHANGELOG.md
@@ -2,6 +2,17 @@
## Unreleased
+- Addons speak ABI 3 (2.x ones are refused): a kind's state is stepped
+ once by `tick`, which now also gives the tag's prefix, however many
+ views show it; each view (a window, a terminal) is told to the kind by
+ `view`, by id, and `paint` draws for the view it names. `search` hands
+ its rows to `found`, now or from a job; `cancel` drops a job's answer.
+ A dump keeps a pane's path and the kind's small record (at most 1 MiB),
+ never its file: a Restore reads the file again, and one not there waits
+ saying so until a Look or a watch of it. A picture's or a PDF's tag has
+ its art words from the first frame. A Debug pardes says a kind's call
+ over 16 ms; `--addon-test` fails on it, and has `view N on|off`.
+ `src/kinds/addon.zig` wraps the whole header.
- `zig build static -Dplatform=tui -Dtarget=x86_64-linux-musl`: one
statically linked `pardes` with the image and PDF addons compiled in
(`/addons` lists them `builtin`; `Addon reload` refuses them). It
diff --git a/test/behaviour/addons.zig b/test/behaviour/addons.zig
index b64a6974..3a53766a 100644
--- a/test/behaviour/addons.zig
+++ b/test/behaviour/addons.zig
@@ -37,7 +37,7 @@ test "addons: Addon load takes a library in, /addons lists it with the kinds com
defer unload(&s, "fake");
// `<kind> <version> <abi> <panes open> <path> <blake3> <state>`.
const listed = try s.read("/addons");
- try std.testing.expect(std.mem.startsWith(u8, listed, "fake 1 2.2 0 /"));
+ try std.testing.expect(std.mem.startsWith(u8, listed, "fake 1 3.0 0 /"));
var fields = std.mem.tokenizeScalar(u8, listed[0..std.mem.indexOfScalar(u8, listed, '\n').?], ' ');
for (0..5) |_| _ = fields.next();
try std.testing.expectEqual(@as(usize, 64), fields.next().?.len);
@@ -51,7 +51,7 @@ test "addons: Addon load takes a library in, /addons lists it with the kinds com
// A pane of it open, it stays; closed, it goes.
try s.write("/ctl", "Fake\n");
const pane = try paneOf(&s, "fake");
- try std.testing.expect(std.mem.startsWith(u8, try s.read("/addons"), "fake 1 2.2 1 /"));
+ try std.testing.expect(std.mem.startsWith(u8, try s.read("/addons"), "fake 1 3.0 1 /"));
try std.testing.expect(try s.refused("/ctl", "Addon unload fake\n") != 0);
try std.testing.expect(has(s.said, "1 fake pane is open"));
try s.write(s.at("/pane/{d}/ctl", .{pane}), "Del\n");
@@ -65,10 +65,10 @@ test "addons: a library of another ABI, one with no pardes_addon, and one whose
defer s.deinit();
for ([_][]const u8{ fake.abi, fake.no_export, fake.core_word }) |path| try load(&s, path);
const listed = try s.read("/addons");
- try std.testing.expect(std.mem.startsWith(u8, listed, "fakeabi 1 3.0 0 /"));
- try std.testing.expect(has(listed, " refused: wants abi 3, this pardes speaks 2\n"));
+ try std.testing.expect(std.mem.startsWith(u8, listed, "fakeabi 1 2.2 0 /"));
+ try std.testing.expect(has(listed, " refused: wants abi 2, this pardes speaks 3\n"));
try std.testing.expect(has(listed, " refused: it has no pardes_addon\n"));
- try std.testing.expect(has(listed, "\nfakeword 1 2.2 0 /"));
+ try std.testing.expect(has(listed, "\nfakeword 1 3.0 0 /"));
try std.testing.expect(has(listed, " refused: word Save is the core's\n"));
// A file that is no library at all: listed with what the loader said.
var tmp = std.testing.tmpDir(.{});
@@ -115,12 +115,12 @@ test "addons: a pane of an addon's kind shows its cells and its picture, takes i
try std.testing.expect(try s.focused() != pane);
}
-test "addons: the image addon opens the pictures a Look names, fitted, with the core's art words in its tag; refuses what it cannot read; and keeps a picture's bytes through a dump" {
+test "addons: the image addon opens the pictures a Look names, fitted, with the core's art words in its tag; refuses what it cannot read; and a dump's pane reads its file again" {
var s = try Session.initFile(std.testing.allocator, "x\n");
defer s.deinit();
try load(&s, Session.image_addon);
const listed = try s.read("/addons");
- try std.testing.expect(std.mem.startsWith(u8, listed, "image 1 2.2 0 /") and has(listed, " loaded\n"));
+ try std.testing.expect(std.mem.startsWith(u8, listed, "image 1 3.0 0 /") and has(listed, " loaded\n"));
var tmp = std.testing.tmpDir(.{});
defer tmp.cleanup();
var buf: [4096]u8 = undefined;
@@ -134,6 +134,7 @@ test "addons: the image addon opens the pictures a Look names, fitted, with the
.{ "red.jpeg", "/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAIBAQEBAQIBAQECAgICAgQDAgICAgUEBAMEBgUGBgYFBgYGBwkIBgcJBwYGCAsICQoKCgoKBggLDAsKDAkKCgr/2wBDAQICAgICAgUDAwUKBwYHCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgr/wgARCAAIABADASIAAhEBAxEB/8QAFQABAQAAAAAAAAAAAAAAAAAAAAf/xAAVAQEBAAAAAAAAAAAAAAAAAAAGCP/aAAwDAQACEAMQAAABkIC1V//EABQQAQAAAAAAAAAAAAAAAAAAABD/2gAIAQEAAQUCP//EABQRAQAAAAAAAAAAAAAAAAAAAAD/2gAIAQMBAT8Bf//EABQRAQAAAAAAAAAAAAAAAAAAAAD/2gAIAQIBAT8Bf//EABQQAQAAAAAAAAAAAAAAAAAAABD/2gAIAQEABj8CP//EABQQAQAAAAAAAAAAAAAAAAAAABD/2gAIAQEAAT8hP//aAAwDAQACAAMAAAAQA//EABQRAQAAAAAAAAAAAAAAAAAAAAD/2gAIAQMBAT8Qf//EABQRAQAAAAAAAAAAAAAAAAAAAAD/2gAIAQIBAT8Qf//EABQQAQAAAAAAAAAAAAAAAAAAABD/2gAIAQEAAT8QP//Z", 16, 8 },
.{ "pixel.ppm", "P6\n2 1\n255\n\x0d\x4d\xe7\x0d\x4d\xe7", 2, 1 },
};
+ var red: []const u8 = "";
for (pictures) |pic| {
const bytes = if (std.mem.endsWith(u8, pic[0], ".ppm")) pic[1] else blk: {
const out = try s.arena.allocator().alloc(u8, try b64.calcSizeForSlice(pic[1]));
@@ -141,6 +142,7 @@ test "addons: the image addon opens the pictures a Look names, fitted, with the
break :blk out;
};
try tmp.dir.writeFile(std.testing.io, .{ .sub_path = pic[0], .data = bytes });
+ if (red.len == 0) red = bytes;
try s.write("/look", s.at("{s}/{s}\n", .{ dir, pic[0] }));
try std.testing.expect(has(try s.read("/screen"), s.at("\"serial\":{d},\"rect\":", .{try s.focused()})));
try std.testing.expect(has(try s.read("/screen"), s.at("\"src\":[0,0,{d},{d}]", .{ pic[2], pic[3] })));
@@ -160,8 +162,8 @@ test "addons: the image addon opens the pictures a Look names, fitted, with the
try std.testing.expect(try s.refused("/look", s.at("{s}/bad.png\n", .{dir})) != 0);
try std.testing.expect(has(s.said, "bad.png: not an image pardes can read"));
try std.testing.expectEqual(panes, (try s.read("/index")).len);
- // Its record is the file's bytes: restored without the addon it waits
- // as a placeholder holding them, and shows them again when it comes.
+ // A dump keeps its path, not its bytes: restored without the addon it
+ // waits as a placeholder, and reads its file again when the addon comes.
try s.write("/ctl", "Dump\n");
const label = try s.arena.allocator().dupe(u8, std.mem.sliceTo(try s.read("/dumps"), ' '));
var lines = std.mem.tokenizeScalar(u8, try s.read("/index"), '\n');
@@ -172,6 +174,15 @@ test "addons: the image addon opens the pictures a Look names, fitted, with the
try load(&s, Session.image_addon);
defer unload(&s, "image");
try std.testing.expect(has(try s.read("/screen"), "\"src\":[0,0,4,2]"));
+ // Its file gone, a restore waits saying so; back, a Look of it opens it.
+ try tmp.dir.deleteFile(std.testing.io, "red.png");
+ try s.write("/ctl", s.at("Restore {s}\n", .{label}));
+ const said = s.at("{s}/red.png is not here", .{dir});
+ try std.testing.expect(has(try s.screen(), said[0..@min(said.len, 40)]));
+ try std.testing.expect(!has(try s.read("/screen"), "\"src\":[0,0,4,2]"));
+ try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "red.png", .data = red });
+ try s.write("/look", s.at("{s}/red.png\n", .{dir}));
+ try std.testing.expect(has(try s.read("/screen"), "\"src\":[0,0,4,2]"));
}
test "addons: a Plumb rule to a loaded kind opens that kind's pane, is refused naming one not loaded, and with its kind gone the look falls through to text" {
diff --git a/test/behaviour/addons_pdf.zig b/test/behaviour/addons_pdf.zig
index 60379457..7b92b84c 100644
--- a/test/behaviour/addons_pdf.zig
+++ b/test/behaviour/addons_pdf.zig
@@ -38,7 +38,7 @@ test "addons: a PDF is the pdf addon's pane, its pages pictures, its page in its
s.graphics();
const n = try s.lookFile("docs/design.pdf");
try std.testing.expect(has(try s.read("/index"), " pdf "));
- try std.testing.expect(std.mem.startsWith(u8, try s.read("/addons"), "pdf 1 2.2 1 /"));
+ try std.testing.expect(std.mem.startsWith(u8, try s.read("/addons"), "pdf 1 3.0 1 /"));
const pages = (try s.pdfPage(n))[1];
try std.testing.expectEqual(@as(u32, 16), pages);
// Its first page, a picture over its body.
diff --git a/test/fs_namespace.zig b/test/fs_namespace.zig
index 22ce27fe..fa6657eb 100644
--- a/test/fs_namespace.zig
+++ b/test/fs_namespace.zig
@@ -285,7 +285,7 @@ test "owned cwd failed file opens never publish a pane or retain a reservation"
try std.testing.expect(succeeded);
}
-test "images decode through explicit filesystem mounts, and a dump reads one on disk from there" {
+test "images decode through explicit filesystem mounts, and a dump's pane reads its file again through the same mount" {
if (!filesystem.platform_has_fs) return error.SkipZigTest;
const gpa = std.testing.allocator;
var tmp = std.testing.tmpDir(.{});
@@ -310,13 +310,19 @@ test "images decode through explicit filesystem mounts, and a dump reads one on
try std.testing.expectEqual(@as(usize, 1), shown.len);
try std.testing.expectEqual(@as(u32, 1), shown[0].raster.w);
try std.testing.expectEqual(@as(u32, 1), shown[0].raster.h);
- // The picture's bytes are in the dump: it comes back as it was shown
- // (a placeholder holding them, as a core without the addon keeps it).
+ // The dump keeps its path, not its bytes: restored, it reads the file
+ // again through the mount its path names, and shows the same pixel.
try pardes.dump.dumpState(p);
- const restored = try pardes.dump.initFromDump(gpa, .{ .tty_only = true }, p.dump_out.?);
+ var words: [64]pardes.Kind.LoadedWord = undefined;
+ const k = p.kinds.byName("image").?;
+ const brought = [_]pardes.Kind.Loaded{pardes.Kind.loadedOf(p.kinds.ops[k].?, p.kinds.kinds[k].path.slice(), p.kinds.kinds[k].hash, &words)};
+ const restored = try pardes.dump.initFromDump(gpa, .{ .tty_only = true, .addons = &brought }, p.dump_out.?);
defer restored.deinit();
const slot = for (restored.panes) |pane| {
if (pane) |each| if (each.addon) |s| break s;
} else return error.NoImagePane;
- try std.testing.expectEqualStrings(bytes, slot.record.?);
+ try std.testing.expect(slot.record == null and slot.live and std.mem.eql(u8, slot.path, path));
+ while (restored.nextEffect()) |e| if (e == .job) restored.perform(e);
+ _ = try restored.render(arena.allocator());
+ try std.testing.expectEqual(@as(u32, 1), restored.surface.placements.items[0].raster.w);
}
diff --git a/test/panes.zig b/test/panes.zig
index d1c8af02..28256495 100644
--- a/test/panes.zig
+++ b/test/panes.zig
@@ -2266,16 +2266,22 @@ const ImageTests = struct {
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" {
+ test "an image's dump keeps its path, its renderer choices and its tag's tail, and reopens from the file; a file gone waits as a placeholder saying so" {
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;
+ var tmp = std.testing.tmpDir(.{});
+ defer tmp.cleanup();
const source = "P6\n1 1\n255\n\x0d\x4d\xe7";
+ try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "restored-image.ppm", .data = source });
+ var dir_buf: [4096]u8 = undefined;
+ const file = try std.fmt.allocPrint(gpa, "{s}/restored-image.ppm", .{dir_buf[0..try tmp.dir.realPath(std.testing.io, &dir_buf)]});
+ defer gpa.free(file);
const k = load(p);
- const pane = try pardes.Kind.open(p, 0, k, "/missing/restored-image.ppm", source);
+ const pane = try pardes.Kind.open(p, 0, k, file, 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");
@@ -2294,16 +2300,21 @@ const ImageTests = struct {
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;
+ // No record: opened from its file, as a Look reads it.
const slot = restored_pane.addon.?;
- try std.testing.expectEqualSlices(u8, source, kept[0..slot.ops.?.dump.?(slot.st, &kept, kept.len)]);
+ try std.testing.expect(slot.record == null and slot.live);
+ try std.testing.expectEqual(std.hash.Wyhash.hash(0, source), slot.opened);
- // 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.?);
+ // Its file gone, a restore waits saying so; back, a watch opens it.
+ try tmp.dir.deleteFile(std.testing.io, "restored-image.ppm");
+ const gone = try dump.initFromDump(gpa, .{ .tty_only = true, .addons = &brought }, p.dump_out.?);
+ defer gone.deinit();
+ const waiting = gone.panes[0].?.addon.?;
+ try std.testing.expect(!waiting.live);
+ try std.testing.expect(std.mem.endsWith(u8, waiting.refused.slice(), "restored-image.ppm is not here"));
+ try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "restored-image.ppm", .data = source });
+ try std.testing.expect(pardes.Kind.fileChanged(gone, 0, ""));
+ try std.testing.expect(waiting.live and waiting.refused.len == 0);
}
};
@@ -3917,7 +3928,7 @@ const PdfAddon = struct {
try std.testing.expect(r.stats.stopped >= 1);
}
- test "the tag a step lays out for a PDF's pane is of the frame its tick left, not the frame before it" {
+ test "a PDF's tag has the core's art words from its first step, in a view without graphics and with them" {
if (!addons.has_pdf) return error.SkipZigTest;
const R = pardes.replica;
const gpa = std.testing.allocator;
@@ -3932,19 +3943,16 @@ const PdfAddon = struct {
const land: Land = .{ .a = a };
const id = try opened(a, land);
const slot = a.core.panes[id].?.addon.?;
- // A view without graphics: the page's text layer, no picture.
- try std.testing.expect(std.mem.indexOf(u8, slot.told.slice(), "petscii") == null);
- // A window's: its tick lays the pages out as pictures and asks
- // for them; the step their answers land in ticks it again, and its
- // tag says what that tick placed, as the next step's will (a
- // replica's guess of its next input is the tag this step laid out).
+ // A view without graphics: the page's text layer, its pictures'
+ // words glyph art's (PA_PICTURES: the kind's, not the frame's).
+ try std.testing.expect(std.mem.indexOf(u8, slot.told.slice(), " petscii:on ") != null);
+ // A window's: the pages as pictures, the same words, its own.
try land.step(.{ .frontend = .{ .windowed = true, .native_images = true } });
try jobs(a.core, land);
- try std.testing.expect(slot.placed);
- try std.testing.expect(std.mem.indexOf(u8, slot.told.slice(), "petscii") != null);
+ try std.testing.expect(std.mem.indexOf(u8, slot.told.slice(), " petscii:off ") != null);
}
- test "a PDF's pane in a window's view and a terminal's in turn: each one's step lays its tag out as its frame shows it" {
+ test "a PDF's pane in a window's view and a terminal's in turn: each is told its view, its tag its page and art words in both" {
if (!addons.has_pdf) return error.SkipZigTest;
const R = pardes.replica;
const gpa = std.testing.allocator;
@@ -3973,15 +3981,19 @@ const PdfAddon = struct {
defer win.deinit();
_ = try a.take(try win.input(.{ .frontend = .{ .windowed = true, .native_images = true } }));
try jobs(a.core, land);
- try std.testing.expect(std.mem.indexOf(u8, slot.told.slice(), "petscii") != null);
+ try std.testing.expect(std.mem.indexOf(u8, slot.told.slice(), " petscii:on ") != null);
+ // Both views told (by id, the session's 1 and the window's), each
+ // with its own frontend's facts.
+ try std.testing.expect(slot.views[0] != 0 and slot.views[k] != 0 and slot.views[0] != slot.views[k]);
for (0..2) |_| {
- // The terminal's key: its view's tick, the page's text layer.
+ // The terminal's key, the strip laid out for its view, and the
+ // window's: the same tag whichever view's step laid it out (the
+ // session's first view's art words, a terminal's: glyph art).
_ = try a.take(try tty.input(.{ .key = .{ .cp = 'j', .text = "j" } }));
try jobs(a.core, land);
- try std.testing.expect(std.mem.indexOf(u8, slot.told.slice(), "petscii") == null);
- // The window's: the pages as pictures again, in its tag at once.
+ try std.testing.expect(std.mem.indexOf(u8, slot.told.slice(), "/16] petscii:on ") != null);
_ = try a.take(try win.input(.{ .key = .{ .cp = 'j', .text = "j" } }));
- try std.testing.expect(std.mem.indexOf(u8, slot.told.slice(), "petscii") != null);
+ try std.testing.expect(std.mem.indexOf(u8, slot.told.slice(), "/16] petscii:on ") != null);
try jobs(a.core, land);
}
}
@@ -4013,6 +4025,7 @@ const PdfAddon = struct {
// again, on the page it can still be on, as height-fitted.
try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "live.pdf", .data = try std.Io.Dir.cwd().readFileAlloc(std.testing.io, "test/pdf-fixtures/outline.pdf", p.scratch.allocator(), .unlimited) });
try std.testing.expect(p.reloadWatchedFile(@intCast(id), &.{}));
+ p.update(.tick);
var arena: std.heap.ArenaAllocator = .init(gpa);
defer arena.deinit();
_ = try p.render(arena.allocator());
diff --git a/test/pdf_scroll_bench.zig b/test/pdf_scroll_bench.zig
index 93067d03..58e7cfb0 100644
--- a/test/pdf_scroll_bench.zig
+++ b/test/pdf_scroll_bench.zig
@@ -228,7 +228,7 @@ fn probeTravel(config: Config) Travel {
const slot = pdfPane(core).addon.?;
if (slot.thumb_span <= 0) fatal("{s}: the strip never laid out", .{config.path});
// The strip is the window over the share of it shown.
- const window_px = @as(f64, @floatFromInt(pardes.Kind.viewOf(core, core.view().active).rows)) * @as(f64, @floatFromInt(config.cell.h));
+ const window_px = @as(f64, @floatFromInt(pardes.Kind.viewOf(core, core.live, core.view().active).rows)) * @as(f64, @floatFromInt(config.cell.h));
var pages: u32 = 0;
const prefix = slot.prefix.slice();
if (std.mem.indexOfScalar(u8, prefix, '/')) |slash| pages = std.fmt.parseInt(u32, prefix[slash + 1 .. prefix.len - 1], 10) catch 0;