diff options
| author | Gabriel Schneider <[email protected]> | 2026-09-30 19:46:24 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-10-01 00:12:17 -0300 |
| commit | d5c6563c95b942f1d2dade817e11ae38fc99e880 (patch) | |
| tree | ce61f37dce9cb1f7450551ea9f9148842d09dd01 /src/look.zig | |
| parent | 9ba51f2fb70a47dc218a864f8fd188f2585fd6fe (diff) | |
| download | pardes-d5c6563c95b942f1d2dade817e11ae38fc99e880.tar.gz pardes-d5c6563c95b942f1d2dade817e11ae38fc99e880.zip | |
A look's miss cuts a long path in its middle with the Rerror cutter, keeping the file's name, never mid-word at 64 bytes
"is no text to address" cut the path at 64 bytes, often mid-word and
losing the file's name, and the other misses cut theirs at 256 from
the end, losing it too. Every miss now goes through fitErr, the cutter
an Rerror uses, which gives up the middle of the longest path so the
start and the name at the end both stay.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Diffstat (limited to 'src/look.zig')
| -rw-r--r-- | src/look.zig | 26 |
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 }; |
