summaryrefslogtreecommitdiff
path: root/src/look.zig
diff options
context:
space:
mode:
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)) {