summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-06 11:38:06 -0300
committerGabriel Schneider <[email protected]>2026-11-06 12:03:00 -0300
commitf922f8b5db1f3b92d954c43860c32cd251d5bc55 (patch)
tree25f1dacb589db526060c2e4dd11b8cbcf5121123
parent0b4142e6704c851f395da2cd8b74954272dadf45 (diff)
downloadpardes-f922f8b5db1f3b92d954c43860c32cd251d5bc55.tar.gz
pardes-f922f8b5db1f3b92d954c43860c32cd251d5bc55.zip
kinds #20, their tests and docs: T1's sessions are a terminal without graphics, so a PDF's key test is the base's text-layer one again beside the strip's (Session.graphics gives a frontend pictures), /addons says 2.2; pane cases for the hand over a link and a touchpad's fraction; reference.typ and the changelog say what a PDF does with and without graphics and what 2.2 added
Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
-rw-r--r--docs/typ/reference.typ16
-rw-r--r--src/CHANGELOG.md5
-rw-r--r--test/behaviour/addons.zig8
-rw-r--r--test/behaviour/addons_pdf.zig7
-rw-r--r--test/behaviour/keys.zig25
-rw-r--r--test/panes.zig86
-rw-r--r--test/session.zig8
7 files changed, 142 insertions, 13 deletions
diff --git a/docs/typ/reference.typ b/docs/typ/reference.typ
index 44b3bed9..abf2964f 100644
--- a/docs/typ/reference.typ
+++ b/docs/typ/reference.typ
@@ -987,11 +987,17 @@ TGA through stb_image, at most 1280 pixels a side), which the build
installs as `<prefix>/lib/pardes/addons/image.so`, and so are PDFs,
`addons/pdf/pdf.c` over MuPDF (its pages rendered on jobs, two at once),
installed as `<prefix>/lib/pardes/addons/pdf.so` (none with
-`-Dmupdf=false`); without them an image file and a PDF open as text. The
-header is ABI 2.1: an addon built against another major is refused, and
-one of 2.0 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`).
+`-Dmupdf=false`); without them an image file and a PDF open as text. A
+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).
- `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
diff --git a/src/CHANGELOG.md b/src/CHANGELOG.md
index 766004d5..96f9b735 100644
--- a/src/CHANGELOG.md
+++ b/src/CHANGELOG.md
@@ -6,8 +6,9 @@
which left the binaries), installed beside them and loaded at start; a
pardes without it shows a PDF as text. A PDF's tag starts with its page,
`[1/12]`, then the art words its pictures take and its path. Addons
- speak ABI 2.1: a heap, the pane's view, `exec`, `select`, their own
- `search` for `/`, Esc first, a rail's thumb.
+ speak ABI 2.2: a heap, the pane's view, `exec`, `select`, their own
+ `search` for `/`, Esc first, a rail's thumb, a wheel's fraction, the
+ pointer they ask for, a tick told a frame was drawn.
- Pictures are an addon: `lib/pardes/addons/image.so` (addons/image),
installed beside the binaries and loaded at start; a pardes without it
diff --git a/test/behaviour/addons.zig b/test/behaviour/addons.zig
index 8d780c98..4a624c22 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.1 0 /"));
+ try std.testing.expect(std.mem.startsWith(u8, listed, "fake 1 2.2 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.1 1 /"));
+ try std.testing.expect(std.mem.startsWith(u8, try s.read("/addons"), "fake 1 2.2 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");
@@ -68,7 +68,7 @@ test "addons: a library of another ABI, one with no pardes_addon, and one whose
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(has(listed, " refused: it has no pardes_addon\n"));
- try std.testing.expect(has(listed, "\nfakeword 1 2.1 0 /"));
+ try std.testing.expect(has(listed, "\nfakeword 1 2.2 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(.{});
@@ -120,7 +120,7 @@ test "addons: the image addon opens the pictures a Look names, fitted, with the
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.1 0 /") and has(listed, " loaded\n"));
+ try std.testing.expect(std.mem.startsWith(u8, listed, "image 1 2.2 0 /") and has(listed, " loaded\n"));
var tmp = std.testing.tmpDir(.{});
defer tmp.cleanup();
var buf: [4096]u8 = undefined;
diff --git a/test/behaviour/addons_pdf.zig b/test/behaviour/addons_pdf.zig
index f3c2d872..60379457 100644
--- a/test/behaviour/addons_pdf.zig
+++ b/test/behaviour/addons_pdf.zig
@@ -35,9 +35,10 @@ fn ctlOf(s: *Session, n: u32) ![]const u8 {
test "addons: a PDF is the pdf addon's pane, its pages pictures, its page in its tag, its fit and tint in its ctl and stepped by its words, all of it back from a Dump" {
var s = try Session.initFile(std.testing.allocator, "x\n");
defer s.deinit();
+ 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.1 1 /"));
+ try std.testing.expect(std.mem.startsWith(u8, try s.read("/addons"), "pdf 1 2.2 1 /"));
const pages = (try s.pdfPage(n))[1];
try std.testing.expectEqual(@as(u32, 16), pages);
// Its first page, a picture over its body.
@@ -46,7 +47,7 @@ test "addons: a PDF is the pdf addon's pane, its pages pictures, its page in its
// Its tag: its page, then the core's art words (it placed a picture),
// its path and its kind's words.
const tag = try s.read(s.at("/pane/{d}/tag", .{n}));
- try std.testing.expect(std.mem.startsWith(u8, tag, "[1/16] petscii:on palette:commodore ascii:on /"));
+ try std.testing.expect(std.mem.startsWith(u8, tag, "[1/16] petscii:off palette:commodore ascii:on /"));
try std.testing.expect(has(tag, "/docs/design.pdf Term PdfSections PdfTint PdfFit Collapse Del"));
try std.testing.expect(has(try ctlOf(&s, n), " fit:width tint:filtered mode:normal "));
// The words: bare they step, given a value they take it, any other
@@ -134,6 +135,7 @@ test "addons: a PDF's / lists its hits as file.pdf:P:H rows in a +Search, n walk
test "addons: a PDF's f is its PdfSections, its outline as places a Look in it goes to (none once the PDF is gone), and a jump back over a far one is Ctrl-o's, Forward's on, two places on a page a window apart two" {
var s = try Session.initFile(std.testing.allocator, "x\n");
defer s.deinit();
+ s.graphics();
const n = try s.lookFile("test/pdf-fixtures/outline.pdf");
try s.keys("f");
var list: u32 = 0;
@@ -190,6 +192,7 @@ test "addons: a PDF's f is its PdfSections, its outline as places a Look in it g
test "addons: a closed PDF is in Recent and its jumps, and a jump back to it opens it at its page; a tall page is shown a band of it at a time" {
var s = try Session.initFile(std.testing.allocator, "x\n");
defer s.deinit();
+ s.graphics();
const n = try s.lookFile("docs/design.pdf");
try s.write(s.at("/pane/{d}/look", .{n}), ":5\n");
const name = std.mem.trimEnd(u8, try s.read(s.at("/pane/{d}/name", .{n})), "\n");
diff --git a/test/behaviour/keys.zig b/test/behaviour/keys.zig
index 879ff441..118681cd 100644
--- a/test/behaviour/keys.zig
+++ b/test/behaviour/keys.zig
@@ -136,9 +136,34 @@ test "keys: a count or a prefix a click or a change of pane cancels leaves nothi
}
}
+test "keys: a PDF shown as text turns pages for the moving keys, counted, and the editing keys do nothing" {
+ var s = try Session.initFile(std.testing.allocator, "x\n");
+ defer s.deinit();
+ const n = try s.lookFile("docs/design.pdf");
+ const pages = (try s.pdfPage(n))[1];
+ try std.testing.expect(pages > 3);
+ // j k, Ctrl-d Ctrl-u, Ctrl-f Ctrl-b: a page each, counted.
+ for ([_][]const u8{ "2j", "2k", "2\x04", "2\x15", "2\x06", "2\x02" }, 0..) |keys, i| {
+ try s.keys(keys);
+ try std.testing.expectEqual(@as(u32, if (i % 2 == 0) 3 else 1), (try s.pdfPage(n))[0]);
+ }
+ for ([_]struct { []const u8, u32 }{ .{ "ge", pages }, .{ "gg", 1 }, .{ "3gg", 3 }, .{ "2G", 2 } }) |step| {
+ try s.keys(step[0]);
+ try std.testing.expectEqual(step[1], (try s.pdfPage(n))[0]);
+ }
+ // Consumed, with their count: the page stays, no selection begins, and
+ // the next j is one page.
+ try s.keys("4dv|");
+ try std.testing.expectEqual(@as(u32, 2), (try s.pdfPage(n))[0]);
+ try std.testing.expect(std.mem.endsWith(u8, try s.read(s.at("/pane/{d}/ctl", .{n})), " mode:normal "));
+ try s.keys("j");
+ try std.testing.expectEqual(@as(u32, 3), (try s.pdfPage(n))[0]);
+}
+
test "keys: a PDF's moving keys scroll its strip, counted, gg G and ge go to pages, and the editing keys do nothing" {
var s = try Session.initFile(std.testing.allocator, "x\n");
defer s.deinit();
+ s.graphics();
const n = try s.lookFile("docs/design.pdf");
const pages = (try s.pdfPage(n))[1];
try std.testing.expect(pages > 3);
diff --git a/test/panes.zig b/test/panes.zig
index a19af1a6..7592742c 100644
--- a/test/panes.zig
+++ b/test/panes.zig
@@ -3780,6 +3780,9 @@ const PdfAddon = struct {
var why: pardes.Kind.Buf(160) = .{};
const lib = pardes.Addon.readLoaded(pdf_lib, &words, &why);
try land.step(.{ .addon = .{ .op = .load, .pane = 0, .kind = &lib } });
+ // A frontend with pictures (a terminal without them is shown the
+ // page's text layer).
+ try land.step(.{ .frontend = .{ .windowed = false, .native_images = true } });
try std.testing.expect(r.core().kinds.ops[r.core().kinds.n - 1] == null);
var buf: [4096]u8 = undefined;
const real = try std.Io.Dir.cwd().realPathFile(std.testing.io, "docs/design.pdf", &buf);
@@ -3866,6 +3869,89 @@ const PdfAddon = struct {
var fields: [256]u8 = undefined;
try std.testing.expect(std.mem.indexOf(u8, pardes.Kind.ctlRead(p.panes[id].?, &fields), "fit:height") != null);
}
+
+ /// A core showing `path` as the addon's pane with pictures, its first
+ /// pages landed: its id.
+ fn landed(p: *Pardes, path: []const u8, arena: *std.heap.ArenaAllocator, now: *u64) !usize {
+ p.view().frontend.native_images = true;
+ pardes.Addon.perform(p, .load, 0, pdf_lib);
+ var buf: [4096]u8 = undefined;
+ const real = try std.Io.Dir.cwd().realPathFile(std.testing.io, path, &buf);
+ var line: [4200]u8 = undefined;
+ try std.testing.expect(p.executeBuiltinLine(p.view().active, try std.fmt.bufPrint(&line, "Look {s}", .{buf[0..real]})));
+ const Self = struct {
+ core: *Pardes,
+ fn step(l: @This(), ev: pardes.Event) !void {
+ l.core.update(ev);
+ }
+ };
+ for (0..4) |_| {
+ now.* += std.time.ns_per_ms;
+ p.advance(now.*);
+ p.update(.tick);
+ try jobs(p, Self{ .core = p });
+ _ = try p.render(arena.allocator());
+ }
+ return p.view().active;
+ }
+
+ test "a PDF's pointer is a hand over a link once the pointer rests there, and the arrow off it" {
+ if (!addons.has_pdf) return error.SkipZigTest;
+ const gpa = std.testing.allocator;
+ const p = try Pardes.init(gpa, .{ .cols = 80, .rows = 24, .tty_only = true });
+ defer p.deinit();
+ var arena: std.heap.ArenaAllocator = .init(gpa);
+ defer arena.deinit();
+ var now: u64 = std.time.ns_per_s;
+ const id = try landed(p, "test/pdf-fixtures/links.pdf", &arena, &now);
+ const r = p.view().rects[id];
+ const pane = p.panes[id].?;
+ // Rested on each cell in turn until one is a link's.
+ const found = scan: {
+ var row: u16 = r.y + pane.tag_rows;
+ while (row < r.y + r.h) : (row += 1) {
+ var col: u16 = r.x + 2;
+ while (col < r.x + r.w) : (col += 3) {
+ p.update(.{ .mouse = .{ .button = .none, .kind = .motion, .col = col, .row = row } });
+ now += 40 * std.time.ns_per_ms;
+ p.advance(now);
+ p.update(.tick);
+ _ = try p.render(arena.allocator());
+ _ = try p.render(arena.allocator());
+ if (p.surface.pointer_shape == .link) break :scan true;
+ }
+ }
+ break :scan false;
+ };
+ try std.testing.expect(found);
+ // Off the pane's body (its tag): the arrow again.
+ p.update(.{ .mouse = .{ .button = .none, .kind = .motion, .col = r.x + 2, .row = r.y } });
+ _ = try p.render(arena.allocator());
+ _ = try p.render(arena.allocator());
+ try std.testing.expect(p.surface.pointer_shape != .link);
+ }
+
+ test "a touchpad's fraction of a turn moves a PDF's strip by that fraction of a notch's" {
+ if (!addons.has_pdf) return error.SkipZigTest;
+ const gpa = std.testing.allocator;
+ const p = try Pardes.init(gpa, .{ .cols = 80, .rows = 24, .tty_only = true });
+ defer p.deinit();
+ var arena: std.heap.ArenaAllocator = .init(gpa);
+ defer arena.deinit();
+ var now: u64 = std.time.ns_per_s;
+ const id = try landed(p, "docs/design.pdf", &arena, &now);
+ const r = p.view().rects[id];
+ const slot = p.panes[id].?.addon.?;
+ var at: [3]f32 = undefined;
+ for (&at, [_]f32{ 0, 1, 0.25 }) |*a, turn| {
+ if (turn > 0) p.update(.{ .mouse = .{ .button = .wheel_down, .kind = .press, .col = r.x + 4, .row = r.y + r.h - 2, .amount = turn } });
+ _ = try p.render(arena.allocator());
+ a.* = slot.thumb_at;
+ }
+ const notch = at[1] - at[0];
+ try std.testing.expect(notch > 0);
+ try std.testing.expectApproxEqRel(notch / 4, at[2] - at[1], 0.05);
+ }
};
test {
diff --git a/test/session.zig b/test/session.zig
index 8b8ec17f..d5f5cae8 100644
--- a/test/session.zig
+++ b/test/session.zig
@@ -416,6 +416,14 @@ pub const Session = struct {
try s.write("/ctl", s.at("Addon load {s}\n", .{real}));
}
+ /// A frontend that shows pictures (a window's, a terminal's with kitty
+ /// graphics): a PDF's pages, not its text layer.
+ pub fn graphics(s: *Session) void {
+ const p: *Pardes = @ptrCast(@alignCast(s.core));
+ p.update(.{ .frontend = .{ .windowed = false, .native_images = true } });
+ s.drain();
+ }
+
/// A Look of `path` at the root (one relative to the working directory
/// made absolute first); the serial of the pane with the keyboard after.
/// A PDF loads the pdf addon first.