diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-26 03:03:20 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-26 03:03:25 -0300 |
| commit | 280306ed779368d7e20e9678eca45e4b81e0ccbf (patch) | |
| tree | 9278534f32a3724b289761594ca658cb6549b227 /core/Kind.zig | |
| parent | 1ce3bcb6178b720058518a12e45f25769be7d39c (diff) | |
| download | pardes-280306ed779368d7e20e9678eca45e4b81e0ccbf.tar.gz pardes-280306ed779368d7e20e9678eca45e4b81e0ccbf.zip | |
Pick, Kind, look, draw, mouse: a picker previews a file an addon's kind takes through that kind in the pane it lands in, a binary no kind takes as one line naming it, and Enter on such a row lands as a Look does, never the file's bytes as text (the user: "the file preview wasn't working for images (maybe pdfs too? Didn't test)", "It should be a generic logic for addons btw, and I saw the bytes rendered as ascii"; the coordinator's W7 under SPEC principle 2); REPRODUCED with the installed build (install74, the S kit, 26 px): SPC f f from a reading main.zig, the cursor on photo.png left main.zig in the body (the previous row's file), on paper.pdf showed `%PDF-1.7 %âãÏÓ 1 0 obj …` as text (a PDF has no NUL in its first 8000 bytes, so Pick.preview's binary guard let it through), and Enter on photo.png put `�PNG … IHDR …` in the reading pane: THE BYTES-AS-TEXT PATH the user saw: Pick.land → look.open → walk → Trail.step → Trail.show → File.open, which reads any path as a text (look.resolve sends a typed or clicked `photo.png` to Kind.openFile, but look.open, every jump's way, had no kind route); THE FIX: look.open routes a path a kind takes (`kinds.forPath`, the routing resolve uses) to openKind, lookAt's kind branch made a function (the pane of it focused, else opened and placed as a Look places it), so a picker's Enter, the Walk queue and a held pane's step land as a Look; Find's row of a kind's file is the file whole (a place in it is its kind's address: line 1 made the image refuse it); Pick.preview: a file a kind takes is shown by a slot of that kind over the landing pane's text (Kind.newSlot, split from Kind.open; Pick.showKind), which stays under it unseen until the next row or the roll-up closes the slot (putBack, restore: Esc exact, nothing left), no per-kind code; any other file with a NUL is one read-only line, `blob.bin · binary · 3.0 kB` (Pick.nameLine); until the kind draws (its paint places nothing yet) the body shows `photo.png · image · 24.8 kB` (draw.zig; Kind.draw says whether it painted); a refused one is that line with its kind's why; the kind does its own work as for its pane (the image decoded on a worker); only the row the cursor rests on at a frame opens (the preview's existing tick rule), and a draw of a row passed by is dropped when it lands (Kind.Slot.drawn_from: this process's draw count when the slot was made; Kind.deliver drops older answers, which went to the next slot of the same kind on the same pane); a previewed kind says, looks at, runs and lists nothing (Kind.Call.end returns before them while Pick.previewing) and takes no mouse (mouse.kindMouse); RUN (TEST FIRST): test/behaviour/addons.zig, four tests through 9P with the fake addon (addons/fake: no kind code in Pick) and the image addon, and addons_pdf.zig one with the pdf addon: a `.fake` file previews as the fake's paint (`count 7`) and not its bytes, Esc puts the screen and /index back, Enter opens the fake's pane with the reading pane's text kept; blob.bin's one line, never other.txt's text after it, a kind's paint after the binary's; three pictures, two rows down with no frame between: one draw held per rested row (2, not 3), and the rested picture shown after the passed one's answer came last; Enter on a picture opens the image pane, the reading pane `the notes`; a PDF's pages as pictures in the landing pane, none after Esc; Session.tick (a host frame) added, as previews wait for the frame after the key; on the base they fail (the bytes `1234567` shown, no line, no image pane, `%PDF` on the screen): core-test 1128/1301 (173 skipped; the kept_out list names Kind.Slot's drawn_from and size), shell-test 1349/1352 (3 skipped), pane-test 183/184, behaviour-test 285/285 (+5) and --replay 285/285, process-test 0 of 147 failed (3 skipped), term-test 17/17, kitty-test 45/45; the gui unit-test on the stack's top (W8); no dump change (the two Slot fields are local, out of the digest and the dump); the S kit with this change's Debug gui at 26 px: the PNG and 9p.pdf previewing in the landing pane, blob.bin's line, Enter on photo.png an `img` pane with main.zig kept (.scratch/walkui/W78/png a02-a05, before r03 r05); no frame or perf gate (the user's rule of 2026-11-26); load 3.7 to 10
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNBFhdevVu48bvL9kCE
Diffstat (limited to 'core/Kind.zig')
| -rw-r--r-- | core/Kind.zig | 55 |
1 files changed, 41 insertions, 14 deletions
diff --git a/core/Kind.zig b/core/Kind.zig index 4e1aa469..e220ead7 100644 --- a/core/Kind.zig +++ b/core/Kind.zig @@ -137,7 +137,7 @@ pub const Slot = struct { // jobs' inputs, its file's hash, a placeholder's record), and what // a frame makes (the thumb, the pointer, whether one was drawn: a // view's, never a step's). - .local = .{ "ops", "st", "gpa", "arena", "plain", "file", "opened", "reloads", "jobs", "record", "thumb_at", "thumb_span", "pointer", "painted", "over", "used" }, + .local = .{ "ops", "st", "gpa", "arena", "plain", "file", "opened", "reloads", "jobs", "record", "thumb_at", "thumb_span", "pointer", "painted", "over", "used", "drawn_from", "size" }, }; /// Its kind's code here; null in a placeholder (`live` false: its kind /// not in the registry, its record kept for the day it comes) or a @@ -215,6 +215,13 @@ pub const Slot = struct { /// A client's join: its plain kind's file, until the pane is opened /// from it (dump.plainHere). file: ?[]u8 = null, + /// This process's draws made before it (`drawn` then): an answer to + /// one of them is another slot's, of a pane that showed something + /// else (a picker's preview of the row before), and is dropped. + drawn_from: u32 = 0, + /// Its file's bytes, as a picker's line naming it says them until its + /// kind's picture is drawn (Pick.preview). + size: u64 = 0, /// Debug: the kind's allocations, which paint must leave as they are. /// The slot's allocator's, as the slot is: a client's rollback puts /// the list back with the slot that holds it (on the page allocator, @@ -259,16 +266,12 @@ fn caps(p: *const Pardes, s: *const Slot) Caps { /// word opened) from `bytes`: made whatever the kind says, with what it /// refused in `slot.refused` for the caller to say. pub fn open(p: *Pardes, id: usize, k: u8, path: ?[]const u8, bytes: ?[]const u8) !*Pane { - const e = &p.kinds.kinds[k]; - // A plain kind's slot and block are the core's (a client's epoch). - const gpa = if (e.caps.plain) p.gpa else p.image_gpa; - const s = try gpa.create(Slot); - s.* = .{ .ops = p.kinds.ops[k], .live = true, .gpa = gpa, .arena = .init(gpa), .version = e.version, .gen = e.gen, .name = e.name }; + const s = try newSlot(p, k, path orelse ""); errdefer { + const gpa = s.gpa; s.free(); gpa.destroy(s); } - s.path = try gpa.dupe(u8, path orelse ""); const pane = try p.newDocPane(id); pane.addon = s; _ = reopen(p, id, s, bytes); @@ -278,6 +281,23 @@ pub fn open(p: *Pardes, id: usize, k: u8, path: ?[]const u8, bytes: ?[]const u8) return pane; } +/// A slot of kind `k` for `path`, its kind's state not made yet (`reopen` +/// makes it): a pane's, or a picker's preview's in the pane it lands in +/// (Pick.preview), that pane's own text set aside meanwhile. +pub fn newSlot(p: *Pardes, k: u8, path: []const u8) !*Slot { + const e = &p.kinds.kinds[k]; + // A plain kind's slot and block are the core's (a client's epoch). + const gpa = if (e.caps.plain) p.gpa else p.image_gpa; + const s = try gpa.create(Slot); + s.* = .{ .ops = p.kinds.ops[k], .live = true, .gpa = gpa, .arena = .init(gpa), .version = e.version, .gen = e.gen, .name = e.name, .drawn_from = drawn }; + errdefer { + s.free(); + gpa.destroy(s); + } + s.path = try gpa.dupe(u8, path); + return s; +} + /// `open` of the file at `path`, read here (a file that cannot be read /// is no bytes: its kind may refuse it). The slot stays ours across the /// read: another request may make a pane meanwhile. @@ -418,9 +438,10 @@ pub fn close(p: *Pardes, pane: *Pane) void { /// The pane's body painted over the `cols` x `rows` cells at (x, y): /// its cells into `s`, its placements after the frame's others. A pane /// whose kind has no code here, or a placeholder, says why in a line. -pub fn draw(p: *Pardes, s: *surface.Surface, arena: std.mem.Allocator, pane: *Pane, id: usize, x: u16, y: u16, cols: u16, rows: u16) void { - const slot = pane.addon orelse return; - if (cols == 0 or rows == 0) return; +/// False when its kind painted nothing (its picture not drawn yet). +pub fn draw(p: *Pardes, s: *surface.Surface, arena: std.mem.Allocator, pane: *Pane, id: usize, x: u16, y: u16, cols: u16, rows: u16) bool { + const slot = pane.addon orelse return true; + if (cols == 0 or rows == 0) return true; const th = p.theme(); const fg: surface.Color = if (th.fg) |f| .{ .rgb = f } else .default; const bg: surface.Color = if (th.bg) |b| .{ .rgb = b } else .default; @@ -431,17 +452,17 @@ pub fn draw(p: *Pardes, s: *surface.Surface, arena: std.mem.Allocator, pane: *Pa const why = if (caps(p, slot).plain) "it is not in its addons nor the session's library at its path here, or it broke its promise here" else "its state is not plain (PA_PLAIN), so it runs in the session alone"; var line: [200]u8 = undefined; _ = s.print(x, y, cols, std.fmt.bufPrint(&line, "addon {s} {d} does not run in this client: {s}", .{ slot.nameOf(), slot.version, why }) catch &line, .{ .fg = fg, .bg = bg }); - return; + return true; } else if (slot.ops == null) { var line: [160]u8 = undefined; const why = if (slot.refused.len > 0) slot.refused.slice() else "Addon load <path>"; // Its kind here, it waits for its file (`<path> is not here`). const text = if (p.kinds.byName(slot.nameOf()) != null) why else std.fmt.bufPrint(&line, "addon {s} {d} is not loaded: {s}", .{ slot.nameOf(), slot.version, why }) catch &line; _ = s.print(x, y, cols, text, .{ .fg = fg, .bg = bg }); - return; + return true; } else for (0..8) |_| { if (ready.items.len > 0) deliver(p, slot, pane, id); - frame.cells = (paint(p, slot, id, arena, cols, rows, &frame) orelse return); + frame.cells = (paint(p, slot, id, arena, cols, rows, &frame) orelse return true); // No workers here (a test's, a bench's core): a draw that paint // asked was done at once, and is this frame's, painted again. if (drawer != null) break; @@ -450,9 +471,11 @@ pub fn draw(p: *Pardes, s: *surface.Surface, arena: std.mem.Allocator, pane: *Pa } else break; } if (frame.gpu.len != 0) s.gpu_frames[id] = .{ .bytes = frame.gpu, .serial = pane.serial, .dst = .{ .x = x, .y = y, .w = cols, .h = rows } }; + var painted = frame.gpu.len != 0 or frame.n > 0; for (0..@min(rows, frame.rows)) |r| for (0..@min(cols, frame.cols)) |col| { const cell = &frame.cells[r * frame.cols + col]; if (cell.flags & c.PA_PAINTED == 0) continue; + painted = true; const len = @min(cell.len, 7); s.set(x + @as(u16, @intCast(col)), y + @as(u16, @intCast(r)), if (len == 0) " " else cell.text[0..len], styleOf(cell, fg, bg)); }; @@ -471,6 +494,7 @@ pub fn draw(p: *Pardes, s: *surface.Surface, arena: std.mem.Allocator, pane: *Pa .art = slot.art, }); } + return painted; } /// A frame of a kind's pane: its cells, `cols` a row, and its placements. @@ -1012,6 +1036,9 @@ const Call = struct { return o; }; const p = cl.p orelse return o; + // A picker's preview shows its file and does nothing more: what its + // kind says, looks at or runs meanwhile is dropped (Pick.showKind). + if (pardes.Pick.previewing(p, cl.id)) return o; if (o.said.len > 0) if (o.err) p.reportFailure(cl.id, o.said) else p.setMessage(.at(cl.id), o.said); if (o.pane_name.len > 0) textPane(p, cl.id, cl.slot, o.pane_name, o.pane_text); if (o.look.len > 0) @import("look.zig").lookAt(p, cl.id, o.look); @@ -1289,7 +1316,7 @@ fn deliver(p: *const Pardes, slot: *Slot, pane: *const Pane, id: usize) void { } _ = ready.orderedRemove(i); defer j.drop(); - if (pane.serial != j.serial or slot.gen != j.gen or slot.ops != j.ops) continue; + if (pane.serial != j.serial or slot.gen != j.gen or slot.ops != j.ops or j.token & ~c.PA_DRAWN <= slot.drawn_from) continue; var cl: Call = .{ .p = null, .id = id, .slot = slot, .quiet = true, .core = p }; const prev = cl.begin("job_done"); const before = if (checked) usedHash(slot); |
