summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-25 18:35:03 -0300
committerGabriel Schneider <[email protected]>2026-11-27 13:41:20 -0300
commit56f49018ffb9d5b29989d349aefaf6f9e65cf25e (patch)
tree3c6b0df4a96329a20a1bbd5aba6105b8a8d49895 /core
parent95dbd10e51797283c13e47a01201898bf4174463 (diff)
downloadpardes-main.tar.gz
pardes-main.zip
Look: a path its program cut off to fit (ending in `…`, as codex ends a line too long for it) opens the one entry of its directory it begins, else that directory, whose listing shows the candidates; and a path that names nothing, looked at in a terminal in tty mode, is said (`…: no such file`) instead of a click that did nothing: the user's report of 2026-11-27 ("It was doing nothing in a path"), reproduced in a pardes GUI window of codex's session (`/home/goblin/.local/share/driftwm-earth-galler…`: no pane, no notice, no log line); THE CAUSE: the cut-off word names no file, and lookUnresolved returned silently for a raw terminal ("a raw terminal's clicks are its program's"), though B3 there is pardes's; THE CHANGE: look.cutOffName (Dir.read, the dir_listing site a directory pane reads), tried when a look resolves nothing; lookUnresolved says a miss for a word with a `/` in a raw terminal (a word without one stays the program's affair); NOT A PARDES FAULT, FOUND ON THE WAY: codex's blue file links in its fullscreen view carry no OSC 8 and show the label alone (its terminal_destination is None for Document links; its inline mode prints the path after the label); RUN (TEST FIRST): look.zig "a look at a name its program cut off (`…`) opens the one entry it begins, else that directory; ..." (driftwm-earth-galler… → the directory, galle… → gallery.py, earth-glo… with two → their directory, nowhere/galle… a miss) and "a look at a path that names nothing, in a terminal in tty mode, is said ..." (/no/such/place/file.rs missed, a bare word not): both fail with the change off, pass now; GATES (Debug tui): core-test 1166/1346 (180 skipped), shell-test 1395/1398 (3 skipped), term-test 17/17, kitty-test 45/45, process-test rc 0, behaviour-test 293/293HEADmain
Diffstat (limited to 'core')
-rw-r--r--core/look.zig93
1 files changed, 92 insertions, 1 deletions
diff --git a/core/look.zig b/core/look.zig
index 7a488b0c..582998c2 100644
--- a/core/look.zig
+++ b/core/look.zig
@@ -11,6 +11,7 @@ const layout = @import("layout.zig");
const modal = @import("modal.zig");
const tagline = @import("tagline.zig");
const filesystem = @import("fs.zig");
+const Dir = @import("Dir.zig");
const panes = @import("panes.zig");
const mouse = @import("mouse.zig");
const normal = @import("normal.zig");
@@ -1115,6 +1116,35 @@ pub fn searchStep(p: *Pardes, id: usize, delta: i32) bool {
/// file, anything else a search for the text as written.
/// `text` is what a word search looks for: the look as written, its blanks
/// kept; `trimmed` what a name is read from.
+/// The whole name a cut-off one (ending in `…`, with a `/` before it)
+/// begins: the one entry of its directory whose name starts with what is
+/// left of its last part, else that directory, whose listing shows the
+/// candidates; null when it is no cut-off name or no directory is there.
+fn cutOffName(p: *Pardes, id: usize, text: []const u8, buf: *[4096]u8) ?[]const u8 {
+ const ellipsis = "…";
+ if (!std.mem.endsWith(u8, text, ellipsis)) return null;
+ const stem = text[0 .. text.len - ellipsis.len];
+ const slash = std.mem.lastIndexOfScalar(u8, stem, '/') orelse return null;
+ const prefix = stem[slash + 1 ..];
+ var realbuf: [4096]u8 = undefined;
+ const dir = switch (resolveLookTarget(p, id, if (slash == 0) "/" else stem[0..slash], &realbuf)) {
+ .dir => |d| d,
+ else => return null,
+ };
+ const names = Dir.read(p.tape, p.gpa, dir) catch return null;
+ defer p.gpa.free(names);
+ var one: ?[]const u8 = null;
+ var count: usize = 0;
+ var it = std.mem.splitScalar(u8, names, '\n');
+ while (it.next()) |name| if (name.len > 0 and std.mem.startsWith(u8, name, prefix)) {
+ one = name;
+ count += 1;
+ };
+ const entry = if (count == 1) std.mem.trimEnd(u8, one.?, "/") else "";
+ const sep = if (entry.len > 0 and !std.mem.endsWith(u8, dir, "/")) "/" else "";
+ return std.fmt.bufPrint(buf, "{s}{s}{s}", .{ dir, sep, entry }) catch null;
+}
+
fn lookUnresolved(p: *Pardes, id: usize, pane: *Pane, trimmed: []const u8, text: []const u8) void {
// A `./` or `../` name opened nothing: said, ENOENT, not searched
// for as a word. What is missing is the pane's directory when
@@ -1130,7 +1160,13 @@ fn lookUnresolved(p: *Pardes, id: usize, pane: *Pane, trimmed: []const u8, text:
return missed(p, id, "{s}: no such file", .{missText(trimmed, &cut)});
}
// A raw terminal's clicks are its program's; a look written over
- // 9P is no keyboard input, and searches whatever the key mode.
+ // 9P is no keyboard input, and searches whatever the key mode. B3 is
+ // pardes's even there: a name with a `/` that opened nothing is said,
+ // as anywhere, never a click that did nothing.
+ if (pane.addon == null and pane.body.mode == .tty and !p.fs.serving and std.mem.indexOfScalar(u8, trimmed, '/') != null) {
+ var cut: [miss_path_cap + "…".len]u8 = undefined;
+ return missed(p, id, "{s}: no such file", .{missText(trimmed, &cut)});
+ }
if (pane.addon != null or (pane.body.mode == .tty and !p.fs.serving)) return;
if (text.len == 0) return;
// A jj change id (eight of its letters or more, k to z, as jj log
@@ -1718,6 +1754,10 @@ pub fn lookAt(p: *Pardes, id: usize, operand_raw: []const u8) void {
// What is looked for is the place without its trailing `:`, `@p33:`
// and `a.txt:` as much as `a.txt:2:`.
const found = resolveLookTarget(p, id, trimmed, &realbuf);
+ // A name its program cut off to fit (`…/driftwm-earth-galler…`, as
+ // codex ends a line too long for it): the name it begins.
+ var whole_buf: [4096]u8 = undefined;
+ if (found == .none) if (cutOffName(p, id, trimmed, &whole_buf)) |whole| return lookAt(p, id, whole);
// `path@rev`, `path@rev:12`: no file, a file at a revision (jj.zig).
if (found == .none and @import("jj.zig").looked(p, id, Pardes.paneDir(pane), pl.path, pl.at)) return;
// A line past the end of an open pane is a miss (the target's line is
@@ -3018,3 +3058,54 @@ test "a Look at a question's answer word in its pane answers it, as an Exec does
try std.testing.expect(p.messages.waiting(pane) == null);
try std.testing.expectEqualStrings(disk, p.panes[id].?.file.?.content);
}
+
+test "a look at a name its program cut off (`…`) opens the one entry it begins, else that directory; a path in a raw terminal that names nothing is said" {
+ const io = std.testing.io;
+ var tmp = std.testing.tmpDir(.{});
+ defer tmp.cleanup();
+ try tmp.dir.createDirPath(io, "driftwm-earth-gallery");
+ try tmp.dir.writeFile(io, .{ .sub_path = "driftwm-earth-gallery/gallery.py", .data = "print(1)\n" });
+ try tmp.dir.writeFile(io, .{ .sub_path = "driftwm-earth-gallery/earth-globes", .data = "x\n" });
+ try tmp.dir.writeFile(io, .{ .sub_path = "driftwm-earth-gallery/earth-globes.xitdb", .data = "y\n" });
+ var root_buf: [4096]u8 = undefined;
+ const root = root_buf[0..try tmp.dir.realPathFile(io, ".", &root_buf)];
+ const p = try Pardes.init(std.testing.allocator, .{ .cols = 100, .rows = 30 });
+ defer p.deinit();
+ p.settings.jumps = .@"new-pane";
+ _ = try p.setTestFile("cut-off names\n");
+ var text_buf: [4096 + 64]u8 = undefined;
+ const Want = struct { cut: []const u8, opened: []const u8 };
+ for ([_]Want{
+ // One entry begins it: that entry, a directory's as a directory.
+ .{ .cut = "/driftwm-earth-galler…", .opened = "/driftwm-earth-gallery/" },
+ .{ .cut = "/driftwm-earth-gallery/galle…", .opened = "/driftwm-earth-gallery/gallery.py" },
+ // Two do: their directory, which lists them.
+ .{ .cut = "/driftwm-earth-gallery/earth-glo…", .opened = "/driftwm-earth-gallery/" },
+ }) |w| {
+ p.look_missed = false;
+ lookAt(p, 0, try std.fmt.bufPrint(&text_buf, "{s}{s}", .{ root, w.cut }));
+ try std.testing.expect(!p.look_missed);
+ const shown = p.panes[p.view().active].?;
+ const name = if (shown.file) |f| f.path else return error.NoFilePane;
+ try std.testing.expect(std.mem.startsWith(u8, name, root));
+ try std.testing.expectEqualStrings(w.opened, name[root.len..]);
+ }
+ // No such directory: no cut-off name, a miss as any.
+ p.look_missed = false;
+ lookAt(p, 0, try std.fmt.bufPrint(&text_buf, "{s}/nowhere/galle…", .{root}));
+ try std.testing.expect(p.look_missed);
+}
+
+test "a look at a path that names nothing, in a terminal in tty mode, is said, not a click that did nothing" {
+ if (pardes.Term.ops == null) return error.SkipZigTest; // a shell
+ const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 60, .rows = 12 });
+ defer p.deinit();
+ while (p.nextEffect()) |_| {}
+ try std.testing.expectEqual(.tty, p.panes[0].?.body.mode);
+ lookAt(p, 0, "/no/such/place/file.rs");
+ try std.testing.expect(p.look_missed);
+ // A word with no `/` stays the program's affair, as before.
+ p.look_missed = false;
+ lookAt(p, 0, "nothingtoseehere");
+ try std.testing.expect(!p.look_missed);
+}