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/look.zig | 40 ++++++++++++++++++---------------------- 1 file changed, 18 insertions(+), 22 deletions(-) (limited to 'src/look.zig') diff --git a/src/look.zig b/src/look.zig index ab1407ee..870209a3 100644 --- a/src/look.zig +++ b/src/look.zig @@ -1,4 +1,5 @@ const std = @import("std"); +const Kind = @import("Kind.zig"); const builtin = @import("builtin"); const libc = std.c; const pardes = @import("pardes.zig"); @@ -185,18 +186,12 @@ pub const Target = union(enum) { none, dir: []const u8, // resolved absolute path, in caller's buf file: FileTarget, - image: struct { path: []const u8 }, + /// A file a kind opens (Kind.forPath): a picture. + kind: struct { path: []const u8, ops: *const Kind.Ops }, url: []const u8, pane: struct { id: usize, at: Spot }, }; -pub fn isImagePath(path: []const u8) bool { - for (config.image_exts) |ext| { - if (std.ascii.endsWithIgnoreCase(path, ext)) return true; - } - return false; -} - pub fn isPdfPath(path: []const u8) bool { if (comptime !pdf_enabled) return false; return std.ascii.endsWithIgnoreCase(path, ".pdf"); @@ -279,7 +274,7 @@ pub fn lineSpan(p: ?*pardes.Pardes, line: []const u8, cwd: []const u8, realbuf: while (b > a and std.mem.indexOfScalar(u8, trail_trim, line[b - 1]) != null) b -= 1; const cand = line[a..b]; if (cand.len > 0 and parsePathLine(cand).end == cand.len) switch (resolve(p, cand, cwd, realbuf)) { - .dir, .file, .image => return .{ .start = a, .end = b }, + .dir, .file, .kind => return .{ .start = a, .end = b }, .url, .pane => if (std.mem.indexOfAny(u8, cand, " \t") == null) return .{ .start = a, .end = b }, .none => {}, @@ -376,7 +371,7 @@ pub fn resolve(p: ?*pardes.Pardes, word_raw: []const u8, cwd: []const u8, realbu .at = pl.at, .kind = .pdf, } }; - if (isImagePath(found.path)) return .{ .image = .{ .path = found.path } }; + if (Kind.forPath(found.path)) |ops| return .{ .kind = .{ .path = found.path, .ops = ops } }; return .{ .file = .{ .path = found.path, .at = pl.at } }; } @@ -1038,7 +1033,7 @@ fn selectSpan(p: *Pardes, pane: *Pane, at: Spot) void { fn openPaneTarget(p: *const Pardes, path: []const u8, at: Spot) ?Target { for (p.panes, 0..) |slot, i| { const tt = slot orelse continue; - if (tt.image) |iv| if (std.mem.eql(u8, iv.path, path)) { + if (tt.addon) |k| if (std.mem.eql(u8, k.path, path)) { return .{ .pane = .{ .id = i, .at = .{} } }; }; if (comptime pdf_enabled) if (tt.pdf) |pv| if (std.mem.eql(u8, pv.path, path)) { @@ -1137,14 +1132,14 @@ fn canonicalLookLocation(p: *Pardes, id: usize, text: []const u8) ?[]const u8 { return p.scratch.allocator().dupe(u8, url) catch null; }, .file => |file| return locationText(p, file.path, file.at), - .image => |iv| return locationText(p, iv.path, .{}), + .kind => |k| return locationText(p, k.path, .{}), .dir => |dir| return locationText(p, dir, .{}), .pane => |target| { if (target.id >= p.panes.len) return null; const pane = p.panes[target.id] orelse return null; if (pane.file) |file| return locationText(p, file.path, target.at); if (comptime pdf_enabled) if (pane.pdf) |doc| return locationText(p, doc.path, target.at); - if (pane.image) |iv| return locationText(p, iv.path, target.at); + if (pane.addon) |k| if (k.path.len > 0) return locationText(p, k.path, target.at); var path: [32]u8 = undefined; return locationText(p, std.fmt.bufPrint(&path, config.pane_addr ++ "{d}", .{pane.serial}) catch return null, target.at); }, @@ -1380,7 +1375,7 @@ fn lookUnresolved(p: *Pardes, id: usize, pane: *Pane, trimmed: []const u8, text: } // A raw terminal's clicks are its program's; a look written over // 9P is no keyboard input, and searches whatever the key mode. - if (pane.image != null or (pane.body.mode == .tty and !p.fs.serving)) return; + if (pane.addon != null or (pane.body.mode == .tty and !p.fs.serving)) return; if (text.len == 0) return; if (lookCommit(p, id, pane, trimmed)) return; if (pane.file != null) return lookWord(p, id, pane, text); @@ -1485,7 +1480,7 @@ fn lookAddress(p: *Pardes, id: usize, path: []const u8, expr: []const u8) void { if ((by_serial or path.len == 0) and pane.isTerminal()) return lookTerminalAddress(p, id, target, expr); // Named as the pane is, the bare `:addr` (path empty) included. var serial_name: [32]u8 = undefined; - const subject = if (pane.image) |iv| iv.path else if (path.len > 0) path else std.fmt.bufPrint(&serial_name, config.pane_addr ++ "{d}", .{pane.serial}) catch "the pane"; + const subject = if (pane.addon) |k| k.path else if (path.len > 0) path else std.fmt.bufPrint(&serial_name, config.pane_addr ++ "{d}", .{pane.serial}) catch "the pane"; var cut: [miss_path_cap + "…".len]u8 = undefined; return missed(p, id, "{s} is no text to address", .{missText(subject, &cut)}); }; @@ -1882,20 +1877,21 @@ pub fn lookAt(p: *Pardes, id: usize, operand_raw: []const u8) void { } settleLine(p, id, target.path, target.at, before, opened); }, - .image => |target| { + .kind => |target| { if (focusPaneByPath(p, target.path, .{})) return; const free = p.freeSlot() orelse return p.reportError(id, "look", error.NoPaneSlots); - const made = panes.Image.create(p, free, target.path, &.{}) catch |err| + const made = Kind.openFile(p, free, target.ops, target.path) catch |err| return lookOpenFailed(p, id, target.path, err); - // One it cannot read (corrupt, truncated, not what its name says) - // is said, a failure, rather than shown as a blank pane. - if (!@import("image.zig").readable(made.image.?.raw)) { + // One its kind refuses (an image corrupt, truncated, not what + // its name says) is said, a failure, rather than shown blank. + if (made.addon.?.refused.len > 0) { made.vweight = 0; p.unplaced.set(free); - var said: [miss_path_cap + 64]u8 = undefined; + var said: [miss_path_cap + 160]u8 = undefined; var cut: [miss_path_cap + "…".len]u8 = undefined; - return p.reportFailure(id, std.fmt.bufPrint(&said, "look: {s}: not an image pardes can read", .{missText(target.path, &cut)}) catch "look: not an image pardes can read"); + return p.reportFailure(id, std.fmt.bufPrint(&said, "look: {s}: {s}", .{ missText(target.path, &cut), made.addon.?.refused.slice() }) catch "look: refused"); } + Kind.startTicking(p, made); exec.placeNew(p, id, id, free, .doc); }, } -- cgit v1.3