From 423440f25b4b23b56162008bba35218d438767fe Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Fri, 6 Nov 2026 00:02:06 -0300 Subject: kinds #2, a pane of a kind is one slot and image is a kind compiled in: src/kinds/pardes_addon.h is the kinds' C ABI (the cell, the window a kind paints, placements and the tag prefix it hands back, keys, the mouse, pa_api of six functions over the pane's arena, words, the head and pa_ops of paint and sixteen optional functions), translated once by the build into the core's records, never mirrored; src/Kind.zig is the core's side: the kinds this process has (a registry with the checks a load makes: the head's size and abi major, a paint, a name, words, leaders and extensions none else has), a pane's Slot (the kind's state and arena, its path, the art bytes Petscii, Palette and Ascii set, its tick deadline and jobs) and the addon arm at the sites: Look and the initial file by extension, draw (cells into the grid, placements keyed by serial and the kind's key), the tag prefix from a paint over no cells, nextWake and the step (ticks, jobs' answers landing on the loop), close, Recent, paneDir, /index's kind word; a dump writes a slot by hand (kind name and version, path, where, art, the kind's own record) and loads it through the kind's open and load, or as a placeholder that keeps the record when the kind is not here; image.zig's pane is now a static pa_ops (open refuses what it cannot read, the decode a job whose answer lands at a step instead of a thread polled by draw, one placement fitted by the frontend, its record the file's bytes), Pane.image is Pane.addon, and the three art words act on the slot; no golden changes (images.snap and tagbottomimage.snap pass, the tag prefix and the placement key are the same bytes); tests: the image dump test, the Petscii/Palette/Ascii ctl tests, the image tag-prefix test and fs_namespace's decode test rewritten on the slot (the decode now lands at the step after the open), plus a registry test; gates: core-test 960/960 on both, unit-test 1487/1488 tui and 1531/1532 gui, behaviour-test 244/244, pane-test 171/172, snap all ok, process-test 0 of 37 failed on both Co-Authored-By: Claude Fable 5.1 Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge --- src/Core.zig | 53 ++++++++++++++++++++++++++++------------------------- 1 file changed, 28 insertions(+), 25 deletions(-) (limited to 'src/Core.zig') diff --git a/src/Core.zig b/src/Core.zig index 76f59247..54f0233e 100644 --- a/src/Core.zig +++ b/src/Core.zig @@ -508,8 +508,8 @@ fn initSession(gpa: std.mem.Allocator, opts: Options) !*Pardes { const opened = initial_doc: { if (comptime pdf_enabled) if (look.isPdfPath(path)) break :initial_doc pardes.panes.Pdf.openPane(p, 0, path, opts.file_line, .last); - if (look.isImagePath(path)) - break :initial_doc pardes.panes.Image.create(p, 0, path, &.{}); + if (pardes.Kind.forPath(path)) |kind| + break :initial_doc pardes.Kind.openFile(p, 0, kind, path); break :initial_doc pardes.panes.File.open(p, 0, path, opts.file_line); }; if (opened) |_| {} else |err| { @@ -660,11 +660,11 @@ pub fn noteClosed(p: *Pardes, pane: *const Pane) void { pub const RecentPlace = struct { path: []const u8, line: u32, col: u32, aline: u32 = 0, acol: u32 = 0 }; /// Where a pane is, as Recent keeps it: a file's dot, a PDF's page -/// (`:page:1`), an image's path alone (line 0). Null for any other. +/// (`:page:1`), a kind's pane's path alone (line 0). Null for any other. pub fn recentPlace(pane: *const Pane) ?RecentPlace { if (recentDot(pane)) |d| return .{ .path = d.path, .line = d.line, .col = d.col, .aline = d.aline, .acol = d.acol }; if (pane.pdfPath()) |path| return .{ .path = path, .line = @intCast(pane.pdfPage().? + 1), .col = 1 }; - if (pane.image) |iv| return .{ .path = iv.path, .line = 0, .col = 0 }; + if (pane.addon) |k| if (k.path.len > 0) return .{ .path = k.path, .line = 0, .col = 0 }; return null; } @@ -1635,6 +1635,8 @@ pub fn update(p: *Pardes, ev: Event) void { look.advanceLookHover(p); }, } + // Each kind's pane whose time has come steps, and its jobs' answers land. + pardes.Kind.step(p); // Each pane's places find a frame's more on a tick, and on any other // step the ones an edit or a scroll left unfound in the view. for (p.panes) |slot| if (slot) |pane| pane.places.settle(p, pane, ev == .tick); @@ -1924,7 +1926,8 @@ pub fn nextWake(p: *const Pardes) ?u64 { // Places still to find resume on the next frame; a picture being // decoded is looked for. for (p.panes) |slot| if (slot) |pane| if (pane.places.busy(pane)) return next; - for (p.panes) |slot| if (slot) |pane| if (pane.image) |iv| if (iv.decoder != null) return next; + const kinds = pardes.Kind.wake(p); + if (kinds) |due| if (due <= next) return next; // A PDF page being rendered on a lane lands on the frame after it is done. if (comptime pdf_enabled) for (p.panes) |slot| if (slot) |pane| if (pane.pdf) |st| if (pardes.panes.Pdf.rendering(st)) return next; // A markdown text's tables still being read from the top (Tables.zig). @@ -1965,6 +1968,11 @@ pub fn nextWake(p: *const Pardes) ?u64 { frames = if (frames) |soonest| @min(soonest, wait) else wait; } }; + // A kind's next tick (Kind.zig). + if (kinds) |due| { + const wait = @max(1, (due -| p.clock.stepped_ns + frame_ns - 1) / frame_ns); + frames = if (frames) |soonest| @min(soonest, wait) else wait; + } return if (frames) |n| p.clock.stepped_ns + n * frame_ns else null; } @@ -2461,7 +2469,7 @@ test "Filter is ordered after Del and toggles only its terminal or +Pager pane" try testing.expect(!first.tty_filter); const doc_id = p.freeSlot().?; - const doc = try pardes.panes.Image.create(p, doc_id, "/tmp/filter-inert.ppm", &.{}); + const doc = try pardes.Kind.open(p, doc_id, &image.kind, "/tmp/filter-inert.ppm", ""); try testing.expect(!doc.tty_filter); try testing.expect(p.executeBuiltinLine(doc_id, "Filter")); try testing.expect(!doc.tty_filter); @@ -2631,8 +2639,7 @@ test "unknown Exec from a document runs as a command pane in its directory, type // A terminal free at a prompt in the same directory is not borrowed. p.setCwd(0, "/tmp/pardes-image-dir"); - const image_doc = try p.newDocPane(1); - image_doc.image = .{ .path = try gpa.dupe(u8, "/tmp/pardes-image-dir/pic.ppm") }; + const image_doc = try pardes.Kind.open(p, 1, &image.kind, "/tmp/pardes-image-dir/pic.ppm", null); try std.testing.expectEqualStrings("/tmp/pardes-image-dir", Pardes.paneDir(image_doc)); const dst = exec.execute(p, 1, "echo image-fallback") orelse return error.ExecFoundNowhereToRun; try std.testing.expect(dst != 0 and dst != 1); @@ -2686,8 +2693,7 @@ test "a command of several lines keeps its tag one row, and its echo does not st const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 100, .rows = 30 }); defer p.deinit(); while (p.nextEffect()) |_| {} - const doc = try p.newDocPane(1); - doc.image = .{ .path = try gpa.dupe(u8, "/tmp/pic.ppm") }; + _ = try pardes.Kind.open(p, 1, &image.kind, "/tmp/pic.ppm", null); const two = "def greet(name):\n return name\n\nprint(greet(\"x\"))\n"; const dst = exec.execute(p, 1, two) orelse return error.NoCommandPane; while (p.nextEffect()) |_| {} @@ -3035,8 +3041,7 @@ test "a command pane shows how its command ended, and the next command there run defer p.deinit(); while (p.nextEffect()) |_| {} p.setCwd(0, "/tmp/pardes-cmd"); - const doc = try p.newDocPane(1); - doc.image = .{ .path = try gpa.dupe(u8, "/tmp/pardes-cmd/pic.ppm") }; + _ = try pardes.Kind.open(p, 1, &image.kind, "/tmp/pardes-cmd/pic.ppm", null); const dst = exec.execute(p, 1, "make -j8") orelse return error.NoCommandPane; while (p.nextEffect()) |_| {} @@ -3136,14 +3141,8 @@ test "image dump restores source bytes renderer choices and exact custom tail" { p.panes[0] = null; const source = "\x00embedded image bytes\xff"; - const raw = try p.image_gpa.dupe(u8, source); - const pane = pardes.panes.Image.create(p, 0, "/missing/restored-image.ppm", raw) catch |err| { - p.image_gpa.free(raw); - return err; - }; - pane.image.?.glyph_art = true; - pane.image.?.pmode = .terminal; - pane.image.?.ascii = false; + const pane = try pardes.Kind.open(p, 0, &image.kind, "/missing/restored-image.ppm", 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"); try dump.dumpState(p); @@ -3151,18 +3150,22 @@ test "image dump restores source bytes renderer choices and exact custom tail" { const restored = try dump.initFromDump(gpa, .{ .tty_only = true }, p.dump_out.?); defer restored.deinit(); const restored_pane = restored.panes[0].?; - try std.testing.expect(restored_pane.image.?.glyph_art); - try std.testing.expectEqual(image.PaletteMode.terminal, restored_pane.image.?.pmode); - try std.testing.expect(!restored_pane.image.?.ascii); + const art = restored_pane.addon.?.art; + try std.testing.expect(art.glyph); + try std.testing.expectEqual(image.PaletteMode.terminal, art.palette); + try std.testing.expect(!art.ascii); try std.testing.expect(restored_pane.tag.own != null); try std.testing.expectEqualStrings(" Keep Del", tagline.curTail(restored_pane)); - try std.testing.expectEqualSlices(u8, source, restored_pane.image.?.raw); + var kept: [64]u8 = undefined; + const slot = restored_pane.addon.?; + try std.testing.expectEqualSlices(u8, source, kept[0..image.kind.dump.?(slot.st, &kept, kept.len)]); // 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(); - try std.testing.expectEqualSlices(u8, source, again.panes[0].?.image.?.raw); + const again_slot = again.panes[0].?.addon.?; + try std.testing.expectEqualSlices(u8, source, kept[0..image.kind.dump.?(again_slot.st, &kept, kept.len)]); } test "a terminal its program gave back takes command lines again" { -- cgit v1.3