summaryrefslogtreecommitdiff
path: root/core/look.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-26 03:03:20 -0300
committerGabriel Schneider <[email protected]>2026-11-26 03:03:25 -0300
commit280306ed779368d7e20e9678eca45e4b81e0ccbf (patch)
tree9278534f32a3724b289761594ca658cb6549b227 /core/look.zig
parent1ce3bcb6178b720058518a12e45f25769be7d39c (diff)
downloadpardes-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/look.zig')
-rw-r--r--core/look.zig54
1 files changed, 36 insertions, 18 deletions
diff --git a/core/look.zig b/core/look.zig
index 41c59cf3..c7e0feb9 100644
--- a/core/look.zig
+++ b/core/look.zig
@@ -1522,6 +1522,9 @@ pub const Landed = union(enum) { none, shown, opened: usize };
/// `Jumps new-pane` as before the walk: a pane showing the file focused,
/// else a new one.
pub fn open(p: *Pardes, from: usize, path: []const u8, at: Spot, how: How) Landed {
+ // A file a kind takes (an addon's: a picture, a PDF) is its kind's
+ // pane, as a Look of it opens (resolve), never its bytes as a text.
+ if (p.kinds.forPath(path)) |k| return openKind(p, from, path, k, at);
if (how == .replace and p.settings.jumps == .walk and path.len <= Trail.max_text and p.panes[from] != null) return walk(p, from, path, at);
if (how == .replace and focusPaneByPath(p, path, at)) return .shown;
return if (openNew(p, from, path, at, .doc)) |free| .{ .opened = free } else .none;
@@ -1557,6 +1560,38 @@ fn walk(p: *Pardes, from: usize, path: []const u8, at: Spot) Landed {
return .shown;
}
+/// The file at `path`, of kind `kind`, looked at from pane `id`: the pane
+/// of it there is focused, else one of its kind opened as a document is
+/// placed (layout.placeNew), at `at` when it says a place.
+fn openKind(p: *Pardes, id: usize, path: []const u8, kind: u8, at: Spot) Landed {
+ var place: [41]u8 = undefined;
+ if (focusPaneByPath(p, path, .{})) {
+ if (at.line > 0) lookKind(p, id, p.view().active, spotText(at, &place), false);
+ return .shown;
+ }
+ const free = p.freeSlot() orelse {
+ p.reportError(.at(id), "look", error.NoPaneSlots);
+ return .none;
+ };
+ const made = Kind.openFile(p, free, kind, path) catch |err| {
+ lookOpenFailed(p, id, path, err);
+ return .none;
+ };
+ // 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: Kind.Buf(miss_path_cap + 160) = .{};
+ var cut: [miss_path_cap + "…".len]u8 = undefined;
+ p.reportFailure(id, said.print("look: {s}: {s}", .{ missText(path, &cut), made.addon.?.refused.slice() }));
+ return .none;
+ }
+ layout.placeNew(p, id, id, free, .doc);
+ if (at.line > 0) lookKind(p, id, free, spotText(at, &place), true);
+ return .{ .opened = free };
+}
+
/// `path` opened at `at` in a new pane placed as `kind` places one from
/// `from`, its line half its body's rows down; null when it is not
/// (refused, said).
@@ -1808,24 +1843,7 @@ pub fn lookAt(p: *Pardes, id: usize, operand_raw: []const u8) void {
};
return missed(p, id, "{s}: the pane its list is of is gone", .{target.path});
}
- if (focusPaneByPath(p, target.path, .{})) {
- if (target.at.line > 0) lookKind(p, id, v.active, spotText(target.at, &place), false);
- return;
- }
- const free = p.freeSlot() orelse return p.reportError(.at(id), "look", error.NoPaneSlots);
- const made = Kind.openFile(p, free, target.kind, target.path) catch |err|
- return lookOpenFailed(p, id, target.path, err);
- // 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: Kind.Buf(miss_path_cap + 160) = .{};
- var cut: [miss_path_cap + "…".len]u8 = undefined;
- return p.reportFailure(id, said.print("look: {s}: {s}", .{ missText(target.path, &cut), made.addon.?.refused.slice() }));
- }
- layout.placeNew(p, id, id, free, .doc);
- if (target.at.line > 0) lookKind(p, id, free, spotText(target.at, &place), true);
+ _ = openKind(p, id, target.path, target.kind, target.at);
},
}
}