summaryrefslogtreecommitdiff
path: root/src/look.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/look.zig')
-rw-r--r--src/look.zig26
1 files changed, 17 insertions, 9 deletions
diff --git a/src/look.zig b/src/look.zig
index afb5b760..454074c8 100644
--- a/src/look.zig
+++ b/src/look.zig
@@ -1218,17 +1218,24 @@ pub fn followPdfLink(p: *Pardes, id: usize, probe: *const panes.Pdf.WordProbe) v
/// A look that found nothing: said on the message row, logged as an `err`
/// record, and marked so that /look reads back nothing (ninep/ctl.zig run).
-/// The most of a looked-at path or text a miss repeats; past it, cut on a
-/// character boundary and ended with `…`.
+/// The most of a looked-at path or text a miss repeats; past it, its
+/// middle gives up to `…` (the Rerror cutter's rule), so the file's name at
+/// the end stays.
const miss_path_cap = 256;
fn missText(text: []const u8, buf: *[miss_path_cap + "…".len]u8) []const u8 {
- if (text.len <= miss_path_cap) return text;
- var n: usize = miss_path_cap;
- while (n > 0 and text[n] & 0xC0 == 0x80) n -= 1;
- @memcpy(buf[0..n], text[0..n]);
- @memcpy(buf[n..][0.."…".len], "…");
- return buf[0 .. n + "…".len];
+ return pardes.ctlfs.fitErr(text, buf[0..miss_path_cap]);
+}
+
+test "a miss names a long path by its start and its end, its middle given up to …" {
+ var cut: [miss_path_cap + "…".len]u8 = undefined;
+ const long = "/home/someone/" ++ "deep/" ** 80 ++ "the-file.zig";
+ const said = missText(long, &cut);
+ try std.testing.expect(said.len <= miss_path_cap);
+ try std.testing.expect(std.mem.startsWith(u8, said, "/home/someone/"));
+ try std.testing.expect(std.mem.endsWith(u8, said, "/the-file.zig"));
+ try std.testing.expect(std.mem.indexOf(u8, said, "…") != null);
+ try std.testing.expectEqualStrings("short/path.txt", missText("short/path.txt", &cut));
}
fn missedLine(p: *Pardes, id: usize, path: []const u8, line: anytype) void {
@@ -1402,7 +1409,8 @@ fn lookAddress(p: *Pardes, id: usize, path: []const u8, expr: []const u8) void {
const pane = p.panes[target] orelse return;
const f = pane.file orelse {
if (by_serial and pane.isTerminal()) return lookTerminalAddress(p, id, target, expr);
- return missed(p, id, "{s} is no text to address", .{path[0..@min(path.len, 64)]});
+ var cut: [miss_path_cap + "…".len]u8 = undefined;
+ return missed(p, id, "{s} is no text to address", .{missText(path, &cut)});
};
if (!by_serial and path.len > 0 and (f.output != null or !std.mem.endsWith(u8, f.path, std.fs.path.basename(path)))) return;
var a: Addr = .{ .text = f.content, .lim = null, .expr = expr };