diff options
Diffstat (limited to 'src/look.zig')
| -rw-r--r-- | src/look.zig | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/src/look.zig b/src/look.zig index 454074c8..2e8a4b39 100644 --- a/src/look.zig +++ b/src/look.zig @@ -1238,6 +1238,11 @@ 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)); } +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 }); +} + fn missedLine(p: *Pardes, id: usize, path: []const u8, line: anytype) void { var cut: [miss_path_cap + "…".len]u8 = undefined; missed(p, id, "{s} has no line {d}", .{ missText(path, &cut), line }); @@ -1688,6 +1693,11 @@ pub fn lookAt(p: *Pardes, id: usize, operand_raw: []const u8) void { // `@p<serial>` names no open pane: a miss, said. if (t.id >= MAX_PANES or p.panes[t.id] == null) return missed(p, id, "no pane {s}", .{pl.path[0..@min(pl.path.len, 32)]}); const target = p.panes[t.id].?; + // A PDF's page past its last is a miss, as a line past a file's + // end is: never the last page in its place (opening one, the + // same: Pdf.openPane's .refuse). + if (comptime pdf_enabled) if (target.pdf) |pv| if (t.at.line > pv.page_count) + return missedPage(p, id, pv.path, t.at.line); const before = p.active; clearNavigationSelection(p, target); focusPaneLine(p, t.id, t.at, .center); @@ -1718,8 +1728,10 @@ pub fn lookAt(p: *Pardes, id: usize, operand_raw: []const u8) void { if (comptime pdf_enabled) if (target.kind == .pdf) { if (focusPaneByPath(p, target.path, target.at)) return; const free = p.freeSlot() orelse return p.reportError(id, "look", error.NoPaneSlots); - // Said with its path and why, as an image that cannot be read is. - _ = panes.Pdf.openPane(p, free, target.path, target.at.line) catch |err| { + // Said with its path and why, as an image that cannot be read + // is; a page past its last is a miss, as for an open one. + _ = panes.Pdf.openPane(p, free, target.path, target.at.line, .refuse) catch |err| { + if (err == error.NoSuchPage) return missedPage(p, id, target.path, target.at.line); var said: [miss_path_cap + 64]u8 = undefined; var cut: [miss_path_cap + "…".len]u8 = undefined; return p.reportError(id, std.fmt.bufPrint(&said, "look: {s}: not a PDF pardes can read", .{missText(target.path, &cut)}) catch "look: not a PDF pardes can read", err); |
