diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-26 10:44:54 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-26 10:44:54 -0300 |
| commit | 8723462d8e02bc9d78b5004de38b910e83540575 (patch) | |
| tree | f264bf364d41f3b334416618e973ec12cba0ddc9 | |
| parent | 7911c53d5f08c7d8df3eb59061841daddb1d0e83 (diff) | |
| parent | f11b123a8f4c38b6582c03d2acf84143ed1e7fd3 (diff) | |
| download | pardes-8723462d8e02bc9d78b5004de38b910e83540575.tar.gz pardes-8723462d8e02bc9d78b5004de38b910e83540575.zip | |
merge: M2's fix (dump.load resolves the chrome) + FP (PDF preview leaks, the spawn stop, PDF hits ABI 3.4)
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNBFhdevVu48bvL9kCE
| -rw-r--r-- | abi/addon.zig | 12 | ||||
| -rw-r--r-- | abi/pardes_addon.h | 7 | ||||
| -rw-r--r-- | addons/fake/fake.c | 13 | ||||
| -rw-r--r-- | addons/fake/fake.out | 22 | ||||
| -rw-r--r-- | addons/pdf/pdf.zig | 41 | ||||
| -rw-r--r-- | build/tests.zig | 8 | ||||
| -rw-r--r-- | core/Core.zig | 7 | ||||
| -rw-r--r-- | core/Kind.zig | 50 | ||||
| -rw-r--r-- | core/Term.zig | 8 | ||||
| -rw-r--r-- | core/dump.zig | 4 | ||||
| -rw-r--r-- | core/exec.zig | 4 | ||||
| -rw-r--r-- | core/replica.zig | 152 | ||||
| -rw-r--r-- | docs/typ/reference.typ | 4 | ||||
| -rw-r--r-- | test/behaviour/addons.zig | 31 | ||||
| -rw-r--r-- | test/behaviour/addons_pdf.zig | 2 | ||||
| -rw-r--r-- | test/session.zig | 1 |
16 files changed, 314 insertions, 52 deletions
diff --git a/abi/addon.zig b/abi/addon.zig index 53227fbb..dfbac270 100644 --- a/abi/addon.zig +++ b/abi/addon.zig @@ -37,9 +37,9 @@ pub const c = @import("pardes_addon"); const Allocator = std.mem.Allocator; /// The ABI this file speaks: a header of another needs it brought along. -pub const abi = 0x30003; +pub const abi = 0x30004; comptime { - if (c.PA_ABI != abi) @compileError("addon.zig speaks ABI 3.3 and the header another"); + if (c.PA_ABI != abi) @compileError("addon.zig speaks ABI 3.4 and the header another"); } /// A word the kind brings: `opens` a pane of it, else goes to the pane's @@ -160,6 +160,10 @@ pub const Window = struct { /// The view painted (View.id), and whether it shows pictures as glyph art. view: u8, glyphs: bool, + /// The theme's search hits and the current one (a pardes older than + /// ABI 3.4: the amber its PDFs drew them in). + hit: Color, + hit_current: Color, /// `text` (UTF-8) from column x of row y on, a character a cell, cut at /// the edge: column first, where the header's pa_put is row first. @@ -315,7 +319,9 @@ pub fn ops(comptime T: type) c.pa_ops { if (@hasDecl(T, "prefix")) t.*.prefix_len = write(T.prefix, s, &t.*.prefix, t.*.prefix.len); } fn paint(st: ?*anyopaque, w: [*c]const c.pa_window, out: [*c]c.pa_paint) callconv(.c) void { - T.paint(self(st) orelse return, .{ .cells = w.*.cells, .stride = w.*.stride, .cols = w.*.cols, .rows = w.*.rows, .cell_w = w.*.cell_w, .cell_h = w.*.cell_h, .focused = w.*.focused != 0, .view = w.*.view, .glyphs = w.*.glyphs != 0 }, .{ .out = out }); + const amber: Color = .rgb(0xff, 0xd5, 0x4f); + const hits = api.abi >= 0x30004; + T.paint(self(st) orelse return, .{ .cells = w.*.cells, .stride = w.*.stride, .cols = w.*.cols, .rows = w.*.rows, .cell_w = w.*.cell_w, .cell_h = w.*.cell_h, .focused = w.*.focused != 0, .view = w.*.view, .glyphs = w.*.glyphs != 0, .hit = if (hits) @fromBackingInt(w.*.hit) else amber, .hit_current = if (hits) @fromBackingInt(w.*.hit_current) else amber }, .{ .out = out }); } fn view(st: ?*anyopaque, v: [*c]const c.pa_view) callconv(.c) void { T.view(self(st) orelse return, @as(*const View, @ptrCast(v)).*); diff --git a/abi/pardes_addon.h b/abi/pardes_addon.h index d8257a0b..e467a239 100644 --- a/abi/pardes_addon.h +++ b/abi/pardes_addon.h @@ -37,7 +37,7 @@ /* Major in the high half: an addon of another major is refused. */ #define PA_ABI_MAJOR 3u -#define PA_ABI_MINOR 3u +#define PA_ABI_MINOR 4u #define PA_ABI ((PA_ABI_MAJOR << 16) | PA_ABI_MINOR) #define PA_OK 0 #define PA_RASTER_MAX (32u << 20) /* a placement's w*h*4 above this is dropped, said once */ @@ -83,6 +83,9 @@ typedef struct pa_window { * `view`: the id of the view painted (pa_view's), whose layout paint * draws; `glyphs`: it shows pictures as glyph art. */ uint8_t focused, view, glyphs, pad; + /* Since 3.4 (check api->abi): the theme's search hits, and the current + * one, as the body draws them (PA_RGB). */ + uint32_t hit, hit_current; } pa_window; typedef struct pa_rect { uint32_t x, y, w, h; } pa_rect; /* pixels */ @@ -390,7 +393,7 @@ typedef struct pa_ops { * copy of this header that disagrees does not compile. */ #if UINTPTR_MAX == 0xffffffffffffffffu _Static_assert(sizeof(pa_cell) == 20, "pa_cell"); -_Static_assert(sizeof(pa_window) == 24, "pa_window"); +_Static_assert(sizeof(pa_window) == 32, "pa_window"); _Static_assert(sizeof(pa_rect) == 16 && sizeof(pa_cells) == 8, "pa_rect"); _Static_assert(sizeof(pa_placement) == 80, "pa_placement"); _Static_assert(sizeof(pa_paint) == 48 && sizeof(pa_view) == 32 && sizeof(pa_tick) == 128, "pa_paint"); diff --git a/addons/fake/fake.c b/addons/fake/fake.c index b3f6b288..b5423317 100644 --- a/addons/fake/fake.c +++ b/addons/fake/fake.c @@ -6,7 +6,8 @@ * * A pane of it counts: keys and clicks and ticks and words each add to a * count it paints, dumps and answers `where` with; `:N` sets it. It paints - * which view it is painted for and that view's size as `view` told it. */ + * which view it is painted for and that view's size as `view` told it, + * and the theme's hit colours its window has (since 3.4). */ #include "pardes_addon.h" /* The loader's tests build it wrong on purpose: another ABI, no export, @@ -60,6 +61,10 @@ static void view(void *st, const pa_view *v) { f->cols[v->id - 1] = v->cols, f->rows[v->id - 1] = v->rows; } +static void hex(char *out, uint32_t rgb) { + for (int i = 0; i < 6; i++) out[i] = "0123456789abcdef"[rgb >> (20 - 4 * i) & 0xf]; +} + static void num(char *out, unsigned n) { char t[12]; int k = 0; @@ -84,6 +89,12 @@ static void paint(void *st, const pa_window *w, pa_paint *out) { if (w->glyphs) memcpy(v + strlen(v), " glyphs", 8); pa_put(w, 3, 0, v, PA_DEFAULT, PA_DEFAULT, 0); } + if (api->abi >= 0x30004u) { + char h[] = "hits rrggbb rrggbb"; + hex(h + 5, w->hit); + hex(h + 12, w->hit_current); + pa_put(w, 4, 0, h, PA_DEFAULT, PA_DEFAULT, 0); + } if (f && out->cap > 0 && w->rows > 2) { pa_placement *pl = &out->placements[out->n++]; *pl = (pa_placement){.rgba = f->pixels, .w = 2, .h = 2, .src = {0, 0, 2, 2}, .dst = {0, 2, 2, 1}, .key = f->count}; diff --git a/addons/fake/fake.out b/addons/fake/fake.out index 8f92d24e..ef4c200b 100644 --- a/addons/fake/fake.out +++ b/addons/fake/fake.out @@ -6,7 +6,7 @@ tag fake petscii:on palette:commodore ascii:on | | |view 1 58x7 glyphs -| +|hits 5e4923 917a53 | | placement 2x2 src 0,0 2x2 over 0,2 2x1 key 4b3cd99b86ea3486 @@ -16,7 +16,7 @@ tag fake petscii:on palette:commodore ascii:on |kb | |view 1 58x7 glyphs -| +|hits 5e4923 917a53 | | placement 2x2 src 0,0 2x2 over 0,2 2x1 key fdcaab9076ad067e @@ -26,7 +26,7 @@ tag fake petscii:on palette:commodore ascii:on |m3 | |view 1 58x7 glyphs -| +|hits 5e4923 917a53 | | placement 2x2 src 0,0 2x2 over 0,2 2x1 key 71e39225f0cec2a5 @@ -36,7 +36,7 @@ tag fake petscii:on palette:commodore ascii:on |m3 | |view 1 58x7 glyphs -| +|hits 5e4923 917a53 | | placement 2x2 src 0,0 2x2 over 0,2 2x1 key 54740e23065232cf @@ -46,7 +46,7 @@ tag fake petscii:on palette:commodore ascii:on |m3 | |view 1 58x7 glyphs -| +|hits 5e4923 917a53 | | placement 2x2 src 0,0 2x2 over 0,2 2x1 key 540d6c1b4eee5716 @@ -56,7 +56,7 @@ tag fake petscii:on palette:commodore ascii:on |m3 | |view 1 58x7 glyphs -| +|hits 5e4923 917a53 | | placement 2x2 src 0,0 2x2 over 0,2 2x1 key 540d6c1b4eee5716 @@ -66,7 +66,7 @@ tag fake petscii:on palette:commodore ascii:on |m3 | |view 2 58x7 -| +|hits 5e4923 917a53 | | placement 2x2 src 0,0 2x2 over 0,2 2x1 key 540d6c1b4eee5716 @@ -77,7 +77,7 @@ tag fake petscii:on palette:commodore ascii:on |m3 | |view 2 68x13 -| +|hits 5e4923 917a53 | | | @@ -93,7 +93,7 @@ tag fake petscii:on palette:commodore ascii:on |m3 | |view 1 58x7 glyphs -| +|hits 5e4923 917a53 | | placement 2x2 src 0,0 2x2 over 0,2 2x1 key 540d6c1b4eee5716 @@ -103,7 +103,7 @@ tag fake petscii:on palette:commodore ascii:on |m3 | |view 1 58x7 glyphs -| +|hits 5e4923 917a53 | | placement 2x2 src 0,0 2x2 over 0,2 2x1 key 540d6c1b4eee5716 @@ -113,7 +113,7 @@ tag fake petscii:on palette:commodore ascii:on |m3 | |view 1 58x7 glyphs -| +|hits 5e4923 917a53 | | placement 2x2 src 0,0 2x2 over 0,2 2x1 key 540d6c1b4eee5716 diff --git a/addons/pdf/pdf.zig b/addons/pdf/pdf.zig index 7ee3400a..a401c979 100644 --- a/addons/pdf/pdf.zig +++ b/addons/pdf/pdf.zig @@ -405,7 +405,7 @@ pub const Pdf = extern struct { // white tinted is the theme's paper const paper: u32 = if (st.tint == .disabled) 0xffffff else if (pixels(st, st.active)) |a| @backingInt(a.v.bg) else 0xffffff; o.blank = .{ @truncate(paper >> 16), @truncate(paper >> 8), @truncate(paper), 255 }; - reconcile(st, o, l, sp, win.view); + reconcile(st, o, l, sp, win); const vh = @min(@as(u32, win.rows) * win.cell_h, l.vh); const first, const count = visible(st, l, sp); for (first..first + count) |p| { @@ -1377,9 +1377,10 @@ fn rasterOf(st: *const Pdf, o: *Own, p: usize, q: Request) [2]u32 { // ---- highlights ---- -/// Page `p`'s highlights in view `l`, as painted: the pointer's, the -/// search's, the selection's. -fn marksOf(st: *const Pdf, o: *Own, l: *const Layout, p: u32, out: []Mark) []Mark { +/// Page `p`'s highlights in view `l`, as painted in `win`: the pointer's, +/// the search's (in the theme's hit colours, the current hit apart), the +/// selection's. +fn marksOf(st: *const Pdf, o: *Own, l: *const Layout, p: u32, out: []Mark, win: addon.Window) []Mark { const f = struct { fn mark(q: Quad, rgb: u32, a: u8, kind: c_int) Mark { return .{ .quad = q, .rgba = .{ @truncate(rgb >> 16), @truncate(rgb >> 8), @truncate(rgb), a }, .kind = kind }; @@ -1393,7 +1394,7 @@ fn marksOf(st: *const Pdf, o: *Own, l: *const Layout, p: u32, out: []Mark) []Mar if (st.find.hits_page == p) { const hits = hitsOf(st, o); for (hits[0..@min(hits.len, out.len - n)]) |h| { - out[n] = f.mark(h.quad, 0xffd54f, 0x70, m.PARDES_PDF_HIGHLIGHT_SEARCH); + out[n] = f.mark(h.quad, @backingInt(if (h.hit == st.find.hit) win.hit_current else win.hit), 0x70, m.PARDES_PDF_HIGHLIGHT_SEARCH); n += 1; } } @@ -1528,10 +1529,11 @@ fn repaint(o: *Own, s: *Slot, now: []const Mark) bool { return keepMarks(&s.shown, now); } -/// What view `id`'s window shows (and the page past it) made so, as it is -/// painted: pages gone dropped, highlights moved repainted, the rest asked -/// of the lanes as draws. -fn reconcile(st: *const Pdf, o: *Own, l: *const Layout, sp: *const Strip, id: u8) void { +/// What view `win.view`'s window shows (and the page past it) made so, as +/// it is painted: pages gone dropped, highlights moved repainted, the rest +/// asked of the lanes as draws. +fn reconcile(st: *const Pdf, o: *Own, l: *const Layout, sp: *const Strip, win: addon.Window) void { + const id = win.view; const first, var n = visible(st, l, sp); if (n > 0 and first + n < st.pages and !st.go.fling) n += 1; // the page ahead, at rest for (&o.s) |*s| if (s.view == id and (s.page < first or s.page >= first + n)) { @@ -1556,7 +1558,7 @@ fn reconcile(st: *const Pdf, o: *Own, l: *const Layout, sp: *const Strip, id: u8 const same = s.rgba.len > 0 and std.meta.eql(s.is.req, q); const wh = if (same) [2]u32{ s.is.w, s.is.h } else rasterOf(st, o, p, q); const y, const bh = bandOf(st, l, sp, p, wh[0], wh[1]); - const marks = marksOf(st, o, l, p, &now.at); + const marks = marksOf(st, o, l, p, &now.at, win); if (same and s.is.tint == st.tint and s.is.ink == @backingInt(l.v.fg) and s.is.paper == @backingInt(l.v.bg) and s.is.band_y <= y and s.is.band_y + s.is.band_h >= y + bh) { if (now.eq(s.shown, marks) or repaint(o, s, marks)) continue; } @@ -1860,3 +1862,22 @@ test "every pointer the bridge's structs hand back is read through addon.cSlice: }; } } + +test "a search's hits are marked in the theme's hit colours its window is painted with, the current hit in the current hit's (ABI 3.4)" { + var st: Pdf = .{}; + st.find.query[0] = 'x'; + st.find.len = 1; + st.find.hits_page = 0; + st.find.hit = 1; + // The page's hits as its search found them: the second, in two quads, current. + const q = std.mem.zeroes(Quad); + var quads = [_]m.pardes_pdf_search_quad{ .{ .quad = q, .hit = 0 }, .{ .quad = q, .hit = 1 }, .{ .quad = q, .hit = 1 } }; + var o: Own = .{ .hits = &quads, .hits_of = .{ .page = 0, .query = st.find.query } }; + var cells: [1]c.pa_cell = undefined; + const win: addon.Window = .{ .cells = &cells, .stride = 1, .cols = 1, .rows = 1, .cell_w = 8, .cell_h = 16, .focused = false, .view = 1, .glyphs = false, .hit = .rgb(0x4c, 0x30, 0x1a), .hit_current = .rgb(0xe5, 0x9d, 0x3c) }; + var out: [8]Mark = undefined; + const marks = marksOf(&st, &o, &st.views[0], 0, &out, win); + try std.testing.expectEqual(@as(usize, 3), marks.len); + try std.testing.expectEqual([4]u8{ 0x4c, 0x30, 0x1a, 0x70 }, marks[0].rgba); + for (marks[1..]) |mk| try std.testing.expectEqual([4]u8{ 0xe5, 0x9d, 0x3c, 0x70 }, mk.rgba); +} diff --git a/build/tests.zig b/build/tests.zig index c35857f7..05bdc2b6 100644 --- a/build/tests.zig +++ b/build/tests.zig @@ -111,18 +111,20 @@ pub fn add(b: *std.Build, c: struct { const session_options = b.addOptions(); session_options.addOptionPath("lspmock", c.lspmock.getEmittedBin()); var fake_addon_lib: ?*std.Build.Step.Compile = null; - // The fake addon (addons/fake/fake.c) and three copies of it built - // wrong, which the loader must refuse (test/behaviour/addons.zig). + // The fake addon (addons/fake/fake.c), copies of it built wrong, which + // the loader must refuse, and one whose head says ABI 3.3, which it + // takes (test/behaviour/addons.zig). for ([_]struct { []const u8, []const u8 }{ .{ "fake_addon", "-DFAKE_PLAIN" }, .{ "fake_addon_abi", "-DFAKE_ABI=0x20002" }, .{ "fake_addon_no_export", "-DFAKE_NO_EXPORT" }, .{ "fake_addon_core_word", "-DFAKE_WORD=\"Save\"" }, .{ "fake_addon_no_dump", "-DFAKE_NO_DUMP" }, + .{ "fake_addon_old", "-DFAKE_ABI=0x30003" }, }) |variant| { const lib = b.addLibrary(.{ .name = variant[0], .linkage = .dynamic, .root_module = b.createModule(.{ .target = c.target, .optimize = c.optimize, .link_libc = true }) }); lib.root_module.addIncludePath(b.path("abi")); - const name_flag = if (std.mem.eql(u8, variant[0], "fake_addon_abi")) "-DFAKE_NAME=\"fakeabi\"" else if (std.mem.eql(u8, variant[0], "fake_addon_core_word")) "-DFAKE_NAME=\"fakeword\"" else "-DFAKE_PLAIN"; + const name_flag = if (std.mem.eql(u8, variant[0], "fake_addon_abi")) "-DFAKE_NAME=\"fakeabi\"" else if (std.mem.eql(u8, variant[0], "fake_addon_core_word")) "-DFAKE_NAME=\"fakeword\"" else if (std.mem.eql(u8, variant[0], "fake_addon_old")) "-DFAKE_NAME=\"fakeold\"" else "-DFAKE_PLAIN"; // The header is the whole contract: it compiles clean under every warning. lib.root_module.addCSourceFile(.{ .file = b.path("addons/fake/fake.c"), .flags = &.{ "-std=c11", "-Wall", "-Wextra", "-Werror", "-Wno-override-init", variant[1], name_flag } }); session_options.addOptionPath(variant[0], lib.getEmittedBin()); diff --git a/core/Core.zig b/core/Core.zig index 3a2e1f51..b80fec2b 100644 --- a/core/Core.zig +++ b/core/Core.zig @@ -304,9 +304,10 @@ n_look_src: usize = 0, look_walk_owner: ?u32 = null, /// hands out Pane.serial; monotonic, never reused next_serial: u32 = 0, -/// The writes of its terminals' emulators, which no rollback copy holds -/// (Term.Outside): digested, dumped and copied as any field, so the same on -/// every side; the replica engine's one question of a unit reads it. +/// The writes of its terminals' emulators, and the opens and closes of its +/// plain kinds' states (Kind.reopen, Kind.close), which no rollback copy +/// holds (Term.Outside): digested, dumped and copied as any field, so the +/// same on every side; the replica engine's one question of a unit reads it. outside: pardes.Term.Outside = .{}, /// The column whose tag the running command came from, while it runs: /// the column acme's commands take from their Text's col. diff --git a/core/Kind.zig b/core/Kind.zig index 4841a55c..c8420c8a 100644 --- a/core/Kind.zig +++ b/core/Kind.zig @@ -39,7 +39,7 @@ pub const abi: u32 = c.PA_ABI; // records the core reads are the ones addons are built to. comptime { if (@sizeOf(usize) == 8) for (.{ - .{ c.pa_cell, 20 }, .{ c.pa_window, 24 }, .{ c.pa_rect, 16 }, .{ c.pa_cells, 8 }, + .{ c.pa_cell, 20 }, .{ c.pa_window, 32 }, .{ c.pa_rect, 16 }, .{ c.pa_cells, 8 }, .{ c.pa_placement, 80 }, .{ c.pa_paint, 48 }, .{ c.pa_key, 8 }, .{ c.pa_mouse, 16 }, .{ c.pa_api, 128 }, .{ c.pa_out, 16 }, .{ c.pa_word, 32 }, .{ c.pa_head, 56 }, .{ c.pa_ops, 208 }, .{ c.pa_view, 32 }, .{ c.pa_tick, 128 }, @@ -320,10 +320,16 @@ pub fn reopen(p: *Pardes, id: usize, s: *Slot, bytes: ?[]const u8) bool { if (p.kinds.byName(s.nameOf())) |k| { // Its code: its library loaded at the first pane of its kind. if (s.ops == null) s.ops = Addon.need(&p.kinds, p.tape, k, &cl.refused, p.opts.distrusted); - // Its block made afresh by this open. + // Its block made afresh by this open. And what a plain kind keeps + // beside it (a PDF's document), made in every core that runs it, is + // no rollback copy's: a write outside the copy (Pardes.outside), + // counted by the registry's word on every side alike, the kind's + // code here or not. A client that kept this step to replay over its + // copy would make that state again and never close the first. if (p.kinds.kinds[k].caps.plain) { if (s.plain) |b| if (b.len > 0) s.gpa.free(b); s.plain = &.{}; + p.outside.n +%= 1; } // Its tag's computed words (UX K'3): its words, then Del. var w: std.Io.Writer = .fixed(&s.tail.bytes); @@ -416,6 +422,11 @@ pub fn close(p: *Pardes, pane: *Pane) void { // own memory (its pictures) is left be, as the rollback brings the pane // back; the session's order closes it. const kept = s.plain != null and s.ops != null and s.ops.?.close != null and p.tape.authorityOnly("a kind's close"); + // What a plain kind keeps beside its block let go: outside the copy, as + // its open was (reopen). + if (p.kinds.byName(s.nameOf())) |k| if (p.kinds.kinds[k].caps.plain) { + p.outside.n +%= 1; + }; if (!kept) { var i: usize = 0; while (i < ready.items.len) if (ready.items[i].draw == p and ready.items[i].serial == pane.serial) ready.orderedRemove(i).drop() else { @@ -518,7 +529,8 @@ pub fn paint(p: *const Pardes, slot: *Slot, id: usize, arena: std.mem.Allocator, var gpu: GpuPaint = .{ .arena = arena, .frame = frame }; var out: c.pa_paint = std.mem.zeroInit(c.pa_paint, .{ .placements = &frame.buf, .cap = frame.buf.len, .gpu = GpuPaint.emit, .gpu_ctx = &gpu }); const px = p.view().cell_pixels; - const win = std.mem.zeroInit(c.pa_window, .{ .cells = cells.ptr, .stride = cols, .rows = rows, .cols = cols, .cell_w = px.w, .cell_h = px.h, .focused = @intFromBool(focusedAnywhere(p, id)), .view = p.live + 1, .glyphs = @intFromBool(!p.view().frontend.native_images) }); + const chrome = p.chrome(); + const win = std.mem.zeroInit(c.pa_window, .{ .cells = cells.ptr, .stride = cols, .rows = rows, .cols = cols, .cell_w = px.w, .cell_h = px.h, .focused = @intFromBool(focusedAnywhere(p, id)), .view = p.live + 1, .glyphs = @intFromBool(!p.view().frontend.native_images), .hit = rgb(chrome.hit), .hit_current = rgb(chrome.hit_current) }); var cl: Call = .{ .p = null, .id = id, .slot = slot, .quiet = true, .core = p }; const prev = cl.begin("paint"); const before = if (checked) usedHash(slot) else {}; @@ -792,11 +804,6 @@ pub fn viewOf(p: *const Pardes, k: u8, id: usize) c.pa_view { // derived, so a client joined from a dump has none. const notices = pardes.Messages.bands(p, pane, tag_rows, r).span(); const th = p.theme(); - const rgb = struct { - fn f(x: [3]u8) u32 { - return @as(u32, x[0]) << 16 | @as(u32, x[1]) << 8 | x[2]; - } - }.f; const policy = rasterPolicy(v.frontend.windowed); return .{ .cols = r.w -| pardes.config.GUTTER, @@ -816,6 +823,11 @@ pub fn viewOf(p: *const Pardes, k: u8, id: usize) c.pa_view { }; } +/// A theme's colour as the header's PA_RGB. +fn rgb(x: [3]u8) u32 { + return @as(u32, x[0]) << 16 | @as(u32, x[1]) << 8 | x[2]; +} + /// Whether pane `id` has the keyboard in some view (its window focused). fn focusedAnywhere(p: *const Pardes, id: usize) bool { for (&p.views) |*v| if (v.*) |*vw| if (vw.active == id and vw.window_focused) return true; @@ -1298,8 +1310,11 @@ var drawn: u32 = 0; /// its own. pub fn landDraw(p: *Pardes, j: *host_io.KindJob) void { if (j.draw != p) return j.drop(); - // Its pane closed meanwhile: no paint of it would ever take it. - if (if (p.panes[j.pane]) |pane| pane.serial != j.serial else true) return j.drop(); + // Its pane closed meanwhile, or showing no kind now (a picker's preview + // closed, the pane its own text again): no paint of it would ever take + // it, nor would the pane's close (Kind.close: a slot's draws). + const pane = p.panes[j.pane] orelse return j.drop(); + if (pane.serial != j.serial or pane.addon == null) return j.drop(); ready.append(heap, j) catch return j.drop(); p.needs_frame = true; } @@ -1415,3 +1430,18 @@ const GpuPaint = struct { return 0; } }; + +test "a picture drawn for a pane that shows no kind's slot when it lands (a picker's preview closed meanwhile) is dropped, never kept for a paint that never comes" { + const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 80, .rows = 24 }); + defer p.deinit(); + _ = try p.setTestFile("the notes\n"); + const id = p.view().active; + try std.testing.expect(p.panes[id].?.addon == null); + // A draw of the preview's, back from its worker after Esc gave the pane + // its own text again. + const j = try heap.create(host_io.KindJob); + j.* = .{ .gpa = heap, .pane = @intCast(id), .serial = p.panes[id].?.serial, .token = c.PA_DRAWN | 1, .gen = 0, .ops = &test_kind.ops, .in = try heap.dupe(u8, "draw"), .arena = .init(heap), .draw = p }; + Addon.holdJob(j.ops, true); + landDraw(p, j); + try std.testing.expectEqual(@as(usize, 0), ready.items.len); +} diff --git a/core/Term.zig b/core/Term.zig index 509da6d9..2f0a0f3f 100644 --- a/core/Term.zig +++ b/core/Term.zig @@ -19,9 +19,11 @@ const iface = plain.term; /// digested and dumped, a function of the tape, the same on every side (one /// side's emulator written where the others' are not is a digest that says /// `outside`). Every write below takes it and counts, and so does a write a -/// speculation owes (`resize`): over an input's apply, the count moved is -/// "this input wrote, or owes, state outside the copy", the one question -/// core/replica.zig `confirm` asks a unit. A load sets it from the dump. +/// speculation owes (`resize`), and a plain kind's state opened or closed +/// (Kind.reopen, Kind.close: what it keeps beside its block, a PDF's +/// document): over an input's apply, the count moved is "this input wrote, +/// or owes, state outside the copy", the one question core/replica.zig +/// `confirm` asks a unit. A load sets it from the dump. pub const Outside = struct { n: u64 = 0 }; /// The reloads this process made (a join's, on every side) and their time, /// for the soak's join line (test/replicas.zig `--bytes`). diff --git a/core/dump.zig b/core/dump.zig index a2b22cef..b1fad70e 100644 --- a/core/dump.zig +++ b/core/dump.zig @@ -1013,6 +1013,10 @@ pub fn plainHere(p: *Pardes, id: usize, old: *Kind.Slot, ops: *const Kind.Ops) ! s.selection = try p.gpa.dupe(u8, old.selection); // (and its place: the open's own `where` is of a block not yet the session's) const kept = .{ old.next_tick, old.views, old.focused, old.state, old.where_text }; + // The count of writes outside the copy stays the session's, as dumped: + // this open is the join's, no step the session took (Kind.reopen). + const outside = p.outside; + defer p.outside = outside; if (!Kind.reopen(p, id, s, old.file)) return error.KindRefused; // Its block the session's, byte for byte (its record), never through // the kind's load, which may tidy it. diff --git a/core/exec.zig b/core/exec.zig index 44cfea64..47fea012 100644 --- a/core/exec.zig +++ b/core/exec.zig @@ -751,6 +751,10 @@ pub fn runCommand(p: *Pardes, from: usize, line: []const u8) ?usize { if (other.command != null and other.command_done and !other.command_pty and std.mem.eql(u8, other.cwdSlice(), dir) and !leased(p, other.serial)) break i; } else null; if (reuse) |id| { + // A process started and its emulator written, as a new command + // pane's (panes.newCommand): the session's, which a speculation + // waits for, nothing of the pane changed first. + if (p.tape.authorityOnly("run a command")) return null; const pane = p.panes[id].?; const owned = p.gpa.dupe(u8, line) catch |err| { p.reportError(.at(from), "exec", err); diff --git a/core/replica.zig b/core/replica.zig index 49ccd85b..a19340bd 100644 --- a/core/replica.zig +++ b/core/replica.zig @@ -7318,7 +7318,10 @@ test "a client's n in a kind's pane is a motion: it steps to the next place a re /// `addon`: a kind whose state is its own on the session (a PDF's), which /// the walk does not stand in (its Still has no search, place or word): /// the soak's (test/replicas.zig) PDF and pictures are, judged by name. -const On = enum { any, file, kind, shell, shell_normal, addon, dir }; +/// `command`: a pane in a directory with a finished command pane, which a +/// line run there runs in again (exec.runCommand); the walk stands in none: +/// the soak's are, judged by name, and the test after the walk. +const On = enum { any, file, kind, shell, shell_normal, addon, dir, command }; /// What a far client may wait a round trip for (the user's line, P14: a /// side effect on the system may be slow; motions, edits and layout are @@ -7352,6 +7355,7 @@ const may_wait = [_]Wait{ .{ .what = "Find *", .on = .any, .stop = "kind", .why = "the work tree it lists from, a `.jj` or `.git` above the pane's directory asked of the session's disk (Pick.workTree), as the listing itself is the session's" }, .{ .what = "Grep *", .on = .any, .stop = "kind", .why = "the work tree it searches, a `.jj` or `.git` above the pane's directory asked of the session's disk (Pick.workTree), as the search itself is the session's" }, .{ .what = "Exec *", .on = .any, .stop = "tty_taken", .why = "a program run in a shell: whether one has it, the session's" }, + .{ .what = "Exec *", .on = .command, .stop = "run a command", .why = "a line run again in its directory's finished command pane: its process and its emulator are the session's" }, .{ .what = "Term", .on = .any, .stop = "kind", .why = "a shell opened: its name asked of the disk first" }, .{ .what = "A-n", .on = .any, .stop = "open a terminal", .why = "a shell opened" }, .{ .what = "* A-n", .on = .any, .stop = "open a terminal", .why = "a shell opened (Alt-n after a prefix is still the global key)" }, @@ -7715,6 +7719,40 @@ test "a far client's every word and key, on a file's pane, a kind's and a shell' try std.testing.expectEqual(@as(u32, 0), stale); } +test "a far client's line run again in its directory's finished command pane waits for the session's order, at a stop may_wait lists: its process and its emulator are the session's" { + // The soak's (test/replicas.zig, seed 3 rtt 80): a client's key stopped + // at `spawn`, which may_wait does not list. Its speculation ran the + // reused pane's whole run (exec.runCommand): the emulator's writes + // refused (`a terminal's output`), then the spawn effect (a host entry + // that keeps stopping), the last one naming the stop. + if (pardes.Term.ops == null) return error.SkipZigTest; // a command pane's terminal + const gpa = std.testing.allocator; + const a = try Authority.init(gpa, .{ .cols = 80, .rows = 24, .file = "mise.toml" }, TestHost.host()); + defer a.deinit(); + const file = a.core.view().active; + _ = try a.local(.{ .command = "Exec true" }); + const cmd = for (a.core.panes, 0..) |slot, id| { + if (slot) |pane| if (pane.command != null) break id; + } else return error.NoCommandPane; + _ = try a.local(.{ .exited = .{ .pane = .at(cmd), .status = 0 } }); + _ = try a.local(.{ .eof = .{ .pane = .at(cmd) } }); + try std.testing.expect(a.core.panes[cmd].?.command_done); + a.core.view().active = file; + const r = try joinedFresh(a); + defer r.deinit(); + // The same line from the file's pane: its directory's finished pane runs it. + const stopped = r.stats.stopped; + const msg = try gpa.dupe(u8, try r.input(.{ .command = "Exec true" })); + defer gpa.free(msg); + try std.testing.expectEqual(stopped + 1, r.stats.stopped); + if (!mayWait(r.t.poisoned_by)) std.debug.print("stopped at `{s}`\n", .{r.t.poisoned_by}); + try std.testing.expect(mayWait(r.t.poisoned_by)); + r.confirm(try a.take(msg)); + r.settle(); + try agrees(a, r); + try std.testing.expect(!a.core.panes[cmd].?.command_done); +} + test "a far client's click into a shell whose program asked for focus events is instant: the session's step tells the program, a round trip later, and the client's guess is confirmed" { if (pardes.Term.ops == null) return error.SkipZigTest; // a shell const gpa = std.testing.allocator; @@ -9201,3 +9239,115 @@ test "a client joined after its session's shell was found to have no prompt mark _ = try n.serve(.{ .tag = 4, .op = .release, .node = run, .handle = h, .opened = true }, true); try n.agree(); } + +test "a picker's preview opens and closes a plain kind's state in the pane it lands in, no pane opened or closed: a client with a copy ahead never replays it over the copy, and every state the kind opens is closed once" { + // The soak's (test/replicas.zig with the pdf addon): `allocator leaks + // detected` at seed 0 rtt 80, the documents of PDFs a picker previewed + // (Pick.showKind) on a client, opened by a unit it kept to replay over + // its copy and opened again by the replay, the first never closed. + // A plain kind that holds something of its own outside its block for + // each state it opens, as the pdf addon holds a document (its `Own`): + // each open notes its block, each close lets it go, so a state opened + // and never closed stays noted. Its files are `.own`. + const Owned = struct { + const pa = pardes.Kind.c; + var noted: [8]?*anyopaque = @splat(null); + fn open(_: [*c]const u8, _: [*c]const u8, _: u64) callconv(.c) ?*anyopaque { + const st = pardes.Kind.api.alloc.?(4); + for (¬ed) |*n| if (n.* == null) { + n.* = st; + break; + }; + return st; + } + fn close(st: ?*anyopaque) callconv(.c) void { + for (¬ed) |*n| if (n.* == st) { + n.* = null; + return; + }; + } + fn paint(_: ?*anyopaque, _: [*c]const pa.pa_window, _: [*c]pa.pa_paint) callconv(.c) void {} + fn held() usize { + var n: usize = 0; + for (noted) |st| n += @intFromBool(st != null); + return n; + } + const ops = std.mem.zeroInit(pardes.Kind.Ops, .{ + .head = std.mem.zeroInit(pa.pa_head, .{ .size = @sizeOf(pa.pa_head), .abi = pardes.Kind.abi, .name = "owned".* ++ @as([11]u8, @splat(0)), .version = 1, .exts = ".own", .flags = pa.PA_PLAIN }), + .open = open, + .close = close, + .paint = paint, + }); + }; + const gpa = std.testing.allocator; + var tmp = std.testing.tmpDir(.{}); + defer tmp.cleanup(); + try tmp.dir.createDir(std.testing.io, ".git", .default_dir); + try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "notes.txt", .data = "the notes\n" }); + try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "paper.own", .data = "own" }); + var dir_buf: [std.Io.Dir.max_path_bytes]u8 = undefined; + const dir = dir_buf[0..try tmp.dir.realPath(std.testing.io, &dir_buf)]; + var line: [std.Io.Dir.max_path_bytes + 32]u8 = undefined; + { + const a = try Authority.init(gpa, .{ .cols = 80, .rows = 24, .file = "mise.toml" }, TestHost.host()); + defer a.deinit(); + var words: [64]pardes.Kind.LoadedWord = undefined; + const owned = pardes.Kind.loadedOf(&Owned.ops, "/x/owned.so", @splat(7), &words); + _ = try a.local(.{ .addon = .{ .op = .load, .pane = .at(0), .kind = &owned } }); + _ = try a.local(.{ .command = try std.fmt.bufPrint(&line, "Look {s}/notes.txt", .{dir}) }); + // A client in a view of its own, running the kind's code. + const joined = (try a.join(1, null)).?; + defer gpa.free(joined.dump); + const r = try Replica.initDump(gpa, 1, joined.view, joined.dump, .{ .cols = 80, .rows = 24 }); + defer r.deinit(); + r.core().kinds.ops[r.core().kinds.byName("owned").?] = &Owned.ops; + // SPC f f p at the session, in its view: its picker lists the tree, + // and paper.own, the one row, shows through the kind in the pane it + // lands in. The client idle meanwhile: its copy taken ahead, each + // unit replayed on top of it. + const At = struct { + fn sessionView(au: *Authority) void { + const was = Stepping.begin(&au.t, null); + au.core.toView(.at(0)); + was.end(); + } + }; + At.sessionView(a); + for (" ffp") |c| { + r.ready(); + r.confirm(try a.local(.{ .key = .{ .cp = c, .text = &.{c} } })); + r.ready(); + r.confirm(try a.local(.tick)); + } + const landing = for (a.core.panes, 0..) |slot, id| { + if (slot) |pane| if (pane.addon != null) break id; + } else return error.NoPreview; + try std.testing.expect(r.core().panes[landing].?.addon != null); + // A key of the client's own on top, and the session's own key + // first: the client back to its copy, the units since replayed. + var sent: std.ArrayListUnmanaged([]u8) = .empty; + defer { + for (sent.items) |m| gpa.free(m); + sent.deinit(gpa); + } + try key(r, 'j', &sent); + try std.testing.expectEqual(@as(usize, 1), r.applied); + const foreign = r.stats.foreign; + r.confirm(try a.local(.{ .key = .{ .cp = 'q', .text = "q" } })); + r.settle(); + try std.testing.expectEqual(foreign + 1, r.stats.foreign); + for (sent.items) |m| { + r.confirm(try a.take(m)); + r.settle(); + } + try agrees(a, r); + // Esc in the picker's view: the preview's state closed, the pane's + // own text back. + At.sessionView(a); + r.confirm(try a.local(.{ .key = .{ .cp = pardes.Key.escape } })); + r.settle(); + try agrees(a, r); + try std.testing.expect(r.core().panes[landing].?.addon == null); + } + try std.testing.expectEqual(@as(usize, 0), Owned.held()); +} diff --git a/docs/typ/reference.typ b/docs/typ/reference.typ index 126330fa..2b0f31c0 100644 --- a/docs/typ/reference.typ +++ b/docs/typ/reference.typ @@ -1171,6 +1171,10 @@ of it is laid out by `view` and drawn by `paint`. 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. + Since ABI 3.4 the window holds the theme's search hit colours, + `win->hit` and the current hit's `win->hit_current` (`PA_RGB`), which an + addon reads once `api->abi >= 0x30004`: a PDF's search draws its hits + in them, as the body draws a file's. - 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. diff --git a/test/behaviour/addons.zig b/test/behaviour/addons.zig index 0b0555c2..88c477ea 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 3.3 0 /")); + try std.testing.expect(std.mem.startsWith(u8, listed, "fake 1 3.4 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 3.3 1 /")); + try std.testing.expect(std.mem.startsWith(u8, try s.read("/addons"), "fake 1 3.4 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 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 3.3 0 /")); + try std.testing.expect(has(listed, "\nfakeword 1 3.4 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 3.3 0 /") and has(listed, " loaded\n")); + try std.testing.expect(std.mem.startsWith(u8, listed, "image 1 3.4 0 /") and has(listed, " loaded\n")); var tmp = std.testing.tmpDir(.{}); defer tmp.cleanup(); var buf: [4096]u8 = undefined; @@ -530,3 +530,26 @@ test "addons: Enter on a picture in a picker opens its kind's pane, never its by try std.testing.expect(has(screen, s.at("\"serial\":{d},", .{image})) and has(screen, "\"src\":[0,0,2,1]")); try std.testing.expect(!has(try s.screen(), "1 P6")); } + +test "addons: a kind's pane is painted with the theme's search hit colours, the current hit's apart (ABI 3.4), and a library whose head says 3.3 still loads, opens and paints" { + { + var s = try Session.initFile(std.testing.allocator, "x\n"); + defer s.deinit(); + try load(&s, fake.ok); + defer unload(&s, "fake"); + try s.write("/ctl", "Theme acme\n"); + try s.write("/ctl", "Fake\n"); + // acme's: its hit ground, and its amber held for its page's ink. + try std.testing.expect(has(try s.screen(), "hits ffc790 a05200")); + try s.write("/ctl", "Theme neonotte84\n"); + try std.testing.expect(has(try s.screen(), "hits 4c301a e59d3c")); + } + var s = try Session.initFile(std.testing.allocator, "x\n"); + defer s.deinit(); + try load(&s, fake.old); + defer unload(&s, "fakeold"); + const listed = try s.read("/addons"); + try std.testing.expect(std.mem.startsWith(u8, listed, "fakeold 1 3.3 0 /") and has(listed, " loaded\n")); + try s.write("/ctl", "Fake\n"); + try std.testing.expect(has(try s.screen(), "count 0")); +} diff --git a/test/behaviour/addons_pdf.zig b/test/behaviour/addons_pdf.zig index 7df5d5ee..c59b4a93 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 3.3 1 /")); + try std.testing.expect(std.mem.startsWith(u8, try s.read("/addons"), "pdf 1 3.4 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/session.zig b/test/session.zig index 9285c13b..91cca3e5 100644 --- a/test/session.zig +++ b/test/session.zig @@ -23,6 +23,7 @@ pub const Session = struct { pub const no_export = o.fake_addon_no_export; pub const core_word = o.fake_addon_core_word; pub const no_dump = o.fake_addon_no_dump; + pub const old = o.fake_addon_old; }; core: *anyopaque, |
