summaryrefslogtreecommitdiff
path: root/src/look.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-09-30 23:12:58 -0300
committerGabriel Schneider <[email protected]>2026-10-01 00:12:17 -0300
commit9dc93a8d31f08f5aec81e7c076220b598db37cbb (patch)
tree4508f75d61b398da363beb31fc10b771a884c3a1 /src/look.zig
parentbcd8388d74e29398cb528206b05fd9491a4d4153 (diff)
downloadpardes-9dc93a8d31f08f5aec81e7c076220b598db37cbb.tar.gz
pardes-9dc93a8d31f08f5aec81e7c076220b598db37cbb.zip
A look at a file it may not read says which: "look: <path>: permission denied"
The refusal said "look: permission denied", leaving the script to guess which of the paths it looked at was locked. A file or image that will not open is now named in the failure, its path cut in the middle when long. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Diffstat (limited to 'src/look.zig')
-rw-r--r--src/look.zig13
1 files changed, 11 insertions, 2 deletions
diff --git a/src/look.zig b/src/look.zig
index 238e479f..922504c0 100644
--- a/src/look.zig
+++ b/src/look.zig
@@ -1238,6 +1238,15 @@ test "a miss names a long path by its start and its end, its middle given up to
try std.testing.expectEqualStrings("short/path.txt", missText("short/path.txt", &cut));
}
+/// A file that is there but would not open: said with its path, `look:
+/// <path>: permission denied`, the path cut in its middle when long.
+fn lookOpenFailed(p: *Pardes, id: usize, path: []const u8, err: anyerror) void {
+ if (@import("Messages.zig").dialReason(err) != null) return p.reportError(id, path, err);
+ var cut: [miss_path_cap + "…".len]u8 = undefined;
+ var said: [miss_path_cap + 16]u8 = undefined;
+ p.reportError(id, std.fmt.bufPrint(&said, "look: {s}", .{missText(path, &cut)}) catch "look", err);
+}
+
fn missedPage(p: *Pardes, id: usize, path: []const u8, page: usize) void {
var cut: [miss_path_cap + "…".len]u8 = undefined;
missed(p, id, "{s} has no page {d}", .{ missText(path, &cut), page });
@@ -1761,7 +1770,7 @@ pub fn lookAt(p: *Pardes, id: usize, operand_raw: []const u8) void {
if (!focusPaneByPath(p, target.path, target.at)) {
const free = p.freeSlot() orelse return p.reportError(id, "look", error.NoPaneSlots);
const nt = panes.File.open(p, free, target.path, target.at.line) catch |err|
- return p.reportError(id, if (@import("Messages.zig").dialReason(err) != null) target.path else "look", err);
+ return lookOpenFailed(p, id, target.path, err);
if (target.at.col > 0) nt.body.cur_col = @intCast(target.at.col - 1);
const failures = p.fs.failures;
exec.placeNew(p, id, id, free, .doc);
@@ -1783,7 +1792,7 @@ pub fn lookAt(p: *Pardes, id: usize, operand_raw: []const u8) void {
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|
- return p.reportError(id, if (@import("Messages.zig").dialReason(err) != null) target.path else "look", 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)) {