summaryrefslogtreecommitdiff
path: root/addons
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-06 21:36:56 -0300
committerGabriel Schneider <[email protected]>2026-11-06 21:37:08 -0300
commit20d79644b6283a425ad0daed869afed8e706b8c2 (patch)
tree87a6208199632a9b11e910f0030d7f84cfcfaf24 /addons
parent5a42ad8d8033c589231e81afdc6f9cb1279b5c22 (diff)
downloadpardes-20d79644b6283a425ad0daed869afed8e706b8c2.tar.gz
pardes-20d79644b6283a425ad0daed869afed8e706b8c2.zip
kinds #44, what kinds 5 could not restore: as text the place names a line of the page (L:F, F its share of the page's lines), the wheel, gj, gk, Ctrl-e and Ctrl-y move a line and a page at the window's edge (j, k and the window keys still turn a page, as the keys test pins); with pictures a wheel's whole notch glides there, half the way each frame drawn and the rest by its fourth tick, a touchpad's fraction moving at once; pdf.script shows the lines, and the touchpad pane case waits out a notch's glide
Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
Diffstat (limited to 'addons')
-rw-r--r--addons/pdf/pdf.out36
-rw-r--r--addons/pdf/pdf.script5
-rw-r--r--addons/pdf/pdf.zig69
3 files changed, 90 insertions, 20 deletions
diff --git a/addons/pdf/pdf.out b/addons/pdf/pdf.out
index a6ea68b3..49ba2a88 100644
--- a/addons/pdf/pdf.out
+++ b/addons/pdf/pdf.out
@@ -165,3 +165,39 @@ tag [2/16] petscii:on palette:commodore ascii:on docs/design.pdf
|nextEffect() → perform(e)
|single-threaded by construction
|native input
+> key 3gj
+tag [2/16] petscii:on palette:commodore ascii:on docs/design.pdf
+|emit(e) → fixed ring, limits.effect_cap
+|nextEffect() → perform(e)
+|single-threaded by construction
+|native input
+|termios+vaxis / SDL / DOM /
+|AppKit / a byte sink on a UART
+|Event
+> key gk
+tag [2/16] petscii:on palette:commodore ascii:on docs/design.pdf
+|render(arena) → *Surface
+|emit(e) → fixed ring, limits.effect_cap
+|nextEffect() → perform(e)
+|single-threaded by construction
+|native input
+|termios+vaxis / SDL / DOM /
+|AppKit / a byte sink on a UART
+> key 999gj
+tag [2/16] petscii:on palette:commodore ascii:on docs/design.pdf
+|detach is served only by a detached core’s host, and the n
+|is the point rather than an oversight — a local tty or SDL
+|has no session to leave, so perform reports that on the pa
+|message row instead of quietly quitting something (the .de
+|arm of Pardes.perform).
+|2
+|
+> key gj
+tag [3/16] petscii:on palette:commodore ascii:on docs/design.pdf
+|The watch path, in full, because it is the ask with the mo
+|machinery behind it. The tty and SDL hosts and the detache
+|daemon implement it in src/file_watch.zig, with Linux in­
+|otify or a macOS kqueue behind one mark/reconcile transact
+|the native macOS host watches with debounced DispatchSourc
+|instead, then restats the exact path under a pane-generati
+|guard. All three macOS watchers mark the same two things f
diff --git a/addons/pdf/pdf.script b/addons/pdf/pdf.script
index be76f3a3..60e4bfca 100644
--- a/addons/pdf/pdf.script
+++ b/addons/pdf/pdf.script
@@ -18,3 +18,8 @@ dump
graphics off
key j
key 2k
+# and as text, gj and gk a line, and a page at the window's edge
+key 3gj
+key gk
+key 999gj
+key gj
diff --git a/addons/pdf/pdf.zig b/addons/pdf/pdf.zig
index d10407e0..4704e7c7 100644
--- a/addons/pdf/pdf.zig
+++ b/addons/pdf/pdf.zig
@@ -7,7 +7,8 @@
//! pictures lays out a strip of the pages at its pixels, each fitted to its
//! width or height (PdfFit), a gap between two, tinted to the theme or not
//! (PdfTint), and asks for the rasters it shows; a view of glyphs (a
-//! terminal without graphics) shows the page's text layer. Pages render off the loop on jobs, two at once: a
+//! terminal without graphics) shows the page's text layer from the line
+//! the place names. Pages render off the loop on jobs, two at once: a
//! pane's document has two lanes (a context and a document of their own
//! each, MuPDF's threading rule), found by the jobs in a table of the open
//! documents under its own lock, and a cookie stops a job nobody waits
@@ -18,8 +19,9 @@
//! over the page's clean rows, repainted on the loop and said as rows
//! (`from`, `dirty_*`). The body is the text of the page shown; `/` lists
//! hits as `file.pdf:P:H`; PdfSections lists the outline; a click on a
-//! link follows it. A fling (a window's travel or more between frames)
-//! renders only the rows each page shows until it rests. The record in a dump is its fit, tint
+//! link follows it. A wheel's whole notches glide there over four ticks; a
+//! fling (a window's travel or more between frames) renders only the rows
+//! each page shows until it rests. The record in a dump is its fit, tint
//! and place.
const std = @import("std");
const addon = @import("addon");
@@ -43,6 +45,7 @@ const chunk = 512; // a tall page's bands start on these
const overlap = 32; // rows rendered past a band's edges
const hover_ns = 32 * std.time.ns_per_ms; // the pointer's rest before its word shows
const fling_ns = 100 * std.time.ns_per_ms; // a fling's end: this long with no turn
+const frame_ns = 16 * std.time.ns_per_ms; // a glide's next step
const grain = 64; // a fling's band starts and ends on these rows
const marks_n = 1024; // highlights on a page
const record_version = 1;
@@ -224,8 +227,9 @@ pub const Pdf = struct {
hover: struct { quad: Quad = std.mem.zeroes(Quad), page: ?u32 = null, link: bool = false, wait: u2 = 0, col: u16 = 0, row: u16 = 0, view: u8 = 0, at: u64 = 0 } = .{},
/// A fling: the strip's travel since the last tick and since the last
/// frame drawn, a window or more of it a frame renders only the rows
- /// each page shows, the whole page once it rests.
- go: struct { since_tick: f64 = 0, travel: f64 = 0, framed: bool = false, landed: bool = false, fling: bool = false } = .{},
+ /// each page shows, the whole page once it rests. A glide: a wheel's
+ /// pixels still to go in a view, half each frame, all by its 4th tick.
+ go: struct { since_tick: f64 = 0, travel: f64 = 0, framed: bool = false, landed: bool = false, fling: bool = false, glide: f64 = 0, glide_n: u8 = 0, glide_view: u8 = 0 } = .{},
count: u32 = 0, // a key's count, typed before it
g: bool = false,
@@ -292,6 +296,14 @@ pub const Pdf = struct {
pub fn tick(st: *Pdf, now: u64, flags: addon.Flags) u64 {
if (st.d == null) return 0;
const go = &st.go;
+ if (go.glide != 0) if (pixels(st, go.glide_view)) |l| {
+ go.glide_n += 1;
+ const step = if (go.glide_n >= 4) go.glide else if (flags.framed) go.glide / 2 else 0;
+ go.glide -= step;
+ scrollBy(st, l, step);
+ } else {
+ go.glide = 0;
+ };
// A fling is a window's travel or more between frames; a tick a
// page's landing made (no turn since) neither starts nor ends one.
go.framed = go.framed or flags.framed;
@@ -329,6 +341,7 @@ pub const Pdf = struct {
if (f.due and ask(st, .{ .op = .search, .page = st.pages, .n = f.len }, query, st.name) != 0) f.due = false;
for (&st.views, 1..) |*l, id| if (l.laid and !l.v.glyphs) reconcile(st, l, @intCast(id));
var next: u64 = if (hv.wait == 2) hv.at else 0;
+ if (go.glide != 0) next = now + frame_ns;
// flinging: a tick when it rests, for the whole pages
if (go.fling and (next == 0 or now + fling_ns < next)) next = now + fling_ns;
return next;
@@ -360,12 +373,13 @@ pub const Pdf = struct {
if (st.d == null or win.view < 1 or win.view > views_n) return;
const out = into.out;
out.pointer = if (st.hover.page != null and st.hover.link) c.PA_POINTER_LINK else c.PA_POINTER_DEFAULT;
- if (win.glyphs) { // the page's text layer, from its top (read on a tick)
+ if (win.glyphs) { // the page's text layer, from the place's line (read on a tick)
out.at = @floatCast((f64Of(st.page) + std.math.clamp(st.frac, 0, 1)) / f64Of(st.pages));
out.span = @floatCast(1 / f64Of(st.pages));
if (st.text.page != st.page) return;
const t = st.text.bytes;
var at: usize = 0;
+ for (0..lineOf(st)) |_| at = if (std.mem.indexOfScalarPos(u8, t, at, '\n')) |nl| nl + 1 else t.len;
for (0..win.rows) |row| {
var col: usize = 0;
while (at < t.len and t[at] != '\n') {
@@ -435,9 +449,9 @@ pub const Pdf = struct {
if (ctrl) {
const n = counted(st);
switch (cp) {
- 'd', 'u' => move(st, l, if (cp == 'd') 1 else -1, @max(1, @floor(vh / 2)), n),
- 'f', 'b' => move(st, l, if (cp == 'f') 1 else -1, vh, n),
- 'e', 'y' => move(st, l, if (cp == 'e') 1 else -1, cell, 1),
+ 'd', 'u' => move(st, l, if (cp == 'd') 1 else -1, @max(1, @floor(vh / 2)), n, false),
+ 'f', 'b' => move(st, l, if (cp == 'f') 1 else -1, vh, n, false),
+ 'e', 'y' => move(st, l, if (cp == 'e') 1 else -1, cell, 1, true),
else => return false, // the editor's: windows, jumps
}
return true;
@@ -449,7 +463,7 @@ pub const Pdf = struct {
switch (cp) {
'g' => goPage(st, n -| 1),
'e' => goPage(st, st.pages - 1),
- 'j', 'k' => move(st, l, if (cp == 'j') 1 else -1, cell, @max(n, 1)),
+ 'j', 'k' => move(st, l, if (cp == 'j') 1 else -1, cell, @max(n, 1), true),
'h', 's', 'l' => edge(st, cp == 'l'),
else => {},
}
@@ -469,10 +483,10 @@ pub const Pdf = struct {
'g' => st.g = true,
'G' => goPage(st, if (st.count > 0) st.count - 1 else st.pages - 1),
'f' => addon.exec("PdfSections"),
- 'j', @backingInt(K.down) => move(st, l, 1, cell, counted(st)),
- 'k', @backingInt(K.up) => move(st, l, -1, cell, counted(st)),
- @backingInt(K.page_down) => move(st, l, 1, vh, counted(st)),
- @backingInt(K.page_up) => move(st, l, -1, vh, counted(st)),
+ 'j', @backingInt(K.down) => move(st, l, 1, cell, counted(st), false),
+ 'k', @backingInt(K.up) => move(st, l, -1, cell, counted(st), false),
+ @backingInt(K.page_down) => move(st, l, 1, vh, counted(st), false),
+ @backingInt(K.page_up) => move(st, l, -1, vh, counted(st), false),
'h', @backingInt(K.left) => panBy(st, -1, across * f64Of(counted(st))),
'l', @backingInt(K.right) => panBy(st, 1, across * f64Of(counted(st))),
'0', '^', @backingInt(K.home) => edge(st, false),
@@ -490,11 +504,14 @@ pub const Pdf = struct {
const dir: f64 = if (ev.button == .wheel_up or ev.button == .wheel_left) -1 else 1;
switch (ev.button) {
.wheel_up, .wheel_down => {
- // a notch a row, a touchpad's fraction of one its fraction;
- // as text a page a turn
+ // a notch a row, gliding there; a touchpad's fraction its
+ // fraction at once; as text a line, a page at the edge
const notches: f64 = if (ev.amount > 0) ev.amount else 1;
const cell: f64 = if (l.v.cell_h != 0) f64Of(l.v.cell_h) else 16;
- move(st, l, dir, notches * cell, 1);
+ if (l.v.glyphs) move(st, l, dir, 0, @intFromFloat(@max(1, @round(notches))), true) else if (notches != @floor(notches)) scrollBy(st, l, dir * notches * cell) else {
+ st.go.glide += dir * notches * cell;
+ st.go.glide_n, st.go.glide_view = .{ 0, id };
+ }
return true;
},
.wheel_left, .wheel_right => {
@@ -994,11 +1011,23 @@ fn goPage(st: *Pdf, p: u32) void {
goTo(st, @min(p, st.pages - 1), 0);
}
+/// The line of the page's text the place names.
+fn lineOf(st: *const Pdf) usize {
+ return @min(@as(usize, @intFromFloat(@round(std.math.clamp(st.frac, 0, 1) * f64Of(st.text.lines)))), st.text.lines -| 1);
+}
+
/// Down (dir 1) or up `n` steps of `px` pixels in view `l`; as text, a
-/// page a step.
-fn move(st: *Pdf, l: *Layout, dir: f64, px: f64, n: u32) void {
+/// page a step, or with `line` a line, and a page at the window's edge.
+fn move(st: *Pdf, l: *Layout, dir: f64, px: f64, n: u32, line: bool) void {
if (!l.v.glyphs) return scrollBy(st, l, dir * px * f64Of(n));
- goPage(st, @intCast(std.math.clamp(@as(i64, st.page) + @as(i64, @intFromFloat(dir)) * n, 0, st.pages - 1)));
+ const page = @as(i64, st.page) + @as(i64, @intFromFloat(dir)) * @as(i64, if (line) 1 else n);
+ const at: i64 = @intCast(lineOf(st));
+ const last = @as(i64, st.text.lines) - l.v.rows;
+ if (!line or st.text.page != st.page or (dir > 0 and at >= last) or (dir < 0 and at == 0)) {
+ if (page >= 0 and page < st.pages or !line) goPage(st, @intCast(std.math.clamp(page, 0, st.pages - 1)));
+ return;
+ }
+ goTo(st, st.page, f64Of(std.math.clamp(at + @as(i64, @intFromFloat(dir)) * n, 0, @max(last, 0))) / f64Of(st.text.lines));
}
fn visible(st: *const Pdf, l: *const Layout) struct { usize, usize } {