summaryrefslogtreecommitdiff
path: root/core/look.zig
diff options
context:
space:
mode:
Diffstat (limited to 'core/look.zig')
-rw-r--r--core/look.zig2712
1 files changed, 2712 insertions, 0 deletions
diff --git a/core/look.zig b/core/look.zig
new file mode 100644
index 00000000..79880476
--- /dev/null
+++ b/core/look.zig
@@ -0,0 +1,2712 @@
+const std = @import("std");
+const Kind = @import("Kind.zig");
+const builtin = @import("builtin");
+const libc = std.c;
+const pardes = @import("root.zig");
+const exec = @import("exec.zig");
+const Plumb = @import("Plumb.zig");
+const config = @import("config.zig");
+const diff = @import("diff.zig");
+const platform_has_fs = filesystem.platform_has_fs;
+const layout = @import("layout.zig");
+const modal = @import("modal.zig");
+const tagline = @import("tagline.zig");
+const filesystem = @import("fs.zig");
+const panes = @import("panes.zig");
+const mouse = @import("mouse.zig");
+const normal = @import("normal.zig");
+const edit = @import("edit.zig");
+const colors = @import("colors.zig");
+const Color = @import("surface.zig").Color;
+const Pane = panes.Pane;
+const MAX_PANES = pardes.MAX_PANES;
+const Layer = @import("Layer.zig");
+const TagHit = pardes.TagHit;
+const BOX_H = pardes.BOX_H;
+const TAG_TEXT_INSET = pardes.TAG_TEXT_INSET;
+const Mouse = pardes.Mouse;
+const Key = pardes.Key;
+const Event = pardes.Event;
+const Pardes = pardes.Pardes;
+
+extern "c" fn execv(path: [*:0]const u8, argv: [*:null]const ?[*:0]const u8) c_int;
+
+const opener_path: ?[*:0]const u8 = switch (builtin.os.tag) {
+ .linux => "/usr/bin/xdg-open",
+ .macos => "/usr/bin/open",
+ else => null,
+};
+
+pub fn openLink(url: []const u8) void {
+ const opener = opener_path orelse return;
+ var buf: [1024]u8 = undefined;
+ const url_z = std.fmt.bufPrintSentinel(&buf, "{s}", .{url}, 0) catch return;
+ const pid = libc.fork();
+ if (pid < 0) return;
+ if (pid == 0) {
+ if (libc.fork() == 0) {
+ @import("dev").host_io.resetChildSignals();
+ const argv: [3:null]?[*:0]const u8 = .{ opener, url_z.ptr, null };
+ _ = execv(opener, &argv);
+ }
+ libc._exit(0);
+ }
+ _ = libc.waitpid(pid, null, 0);
+}
+
+pub const Spot = struct {
+ line: usize = 0,
+ col: usize = 0,
+ end_line: usize = 0,
+ end_col: usize = 0,
+};
+
+fn num(tok: []const u8, i: usize) struct { v: usize, end: usize } {
+ var v: usize = 0;
+ var j = i;
+ while (j < tok.len and std.ascii.isDigit(tok[j])) : (j += 1) v = v *| 10 +| (tok[j] - '0');
+ return .{ .v = v, .end = j };
+}
+
+pub fn parsePathLine(tok: []const u8) struct { path: []const u8, at: Spot, end: usize } {
+ var sep: usize = 0;
+ while (sep < tok.len) : (sep += 1) {
+ if (tok[sep] != config.line_col_sep) continue;
+ const l = num(tok, sep + 1);
+ if (l.end == sep + 1) continue; // no digits after ':'
+ const path = tok[0..sep];
+ var i = l.end;
+ if (i < tok.len and tok[i] == config.range_sep) {
+ const e = num(tok, i + 1);
+ if (e.end == i + 1) continue; // a dash with no number is not a range
+ if (e.end < tok.len and tok[e.end] != config.line_col_sep) continue; // junk after it
+ return .{ .path = path, .at = .{ .line = l.v, .end_line = e.v }, .end = e.end };
+ }
+ if (i < tok.len and tok[i] != config.line_col_sep) continue; // junk after the number
+ var at: Spot = .{ .line = l.v };
+ if (i == tok.len) return .{ .path = path, .at = at, .end = i };
+ const c = num(tok, i + 1);
+ if (c.end == i + 1) return .{ .path = path, .at = at, .end = i };
+ if (c.end < tok.len and tok[c.end] != config.line_col_sep and tok[c.end] != config.range_sep)
+ return .{ .path = path, .at = at, .end = i };
+ at.col = c.v;
+ i = c.end;
+ if (i == tok.len or tok[i] != config.range_sep) return .{ .path = path, .at = at, .end = i };
+ const e = num(tok, i + 1);
+ if (e.end == i + 1) return .{ .path = path, .at = at, .end = i };
+ at.end_line = at.line;
+ at.end_col = e.v;
+ var end = e.end;
+ if (e.end < tok.len and tok[e.end] == config.line_col_sep) {
+ const e2 = num(tok, e.end + 1);
+ if (e2.end > e.end + 1) {
+ at.end_line = at.end_col;
+ at.end_col = e2.v;
+ end = e2.end;
+ }
+ }
+ return .{ .path = path, .at = at, .end = end };
+ }
+ return .{ .path = tok, .at = .{}, .end = tok.len };
+}
+
+pub const FileTarget = struct {
+ path: []const u8,
+ at: Spot,
+};
+
+pub const Target = union(enum) {
+ none,
+ dir: []const u8, // resolved absolute path, in caller's buf
+ file: FileTarget,
+ /// A file a kind opens (Kind.forPath): a picture, a PDF; `at` the place
+ /// written after it (`book.pdf:12:3`), the kind's to take.
+ kind: struct { path: []const u8, kind: u8, at: Spot = .{} },
+ url: []const u8,
+ pane: struct { id: usize, at: Spot },
+};
+
+pub const Span = struct { start: usize, end: usize };
+
+const lead_trim = "([{<\"'`*";
+const trail_trim = ")]}>\"'`*,;:.!?";
+
+pub fn lineSpan(p: ?*pardes.Pardes, line: []const u8, cwd: []const u8, realbuf: *[4096]u8) ?Span {
+ var lo: usize = 0;
+ while (lo < line.len and (line[lo] == ' ' or line[lo] == '\t')) lo += 1;
+ var hi = std.mem.trimEnd(u8, line, " \t\r").len;
+ while (hi > lo) {
+ var a = lo;
+ var b = hi;
+ while (a < b and std.mem.indexOfScalar(u8, lead_trim, line[a]) != null) a += 1;
+ while (b > a and std.mem.indexOfScalar(u8, trail_trim, line[b - 1]) != null) b -= 1;
+ const cand = line[a..b];
+ if (cand.len > 0 and parsePathLine(cand).end == cand.len) switch (resolve(p, cand, cwd, realbuf)) {
+ .dir, .file, .kind => return .{ .start = a, .end = b },
+ .url, .pane => if (std.mem.indexOfAny(u8, cand, " \t") == null)
+ return .{ .start = a, .end = b },
+ .none => {},
+ };
+ while (hi > lo and line[hi - 1] != ' ' and line[hi - 1] != '\t') hi -= 1;
+ while (hi > lo and (line[hi - 1] == ' ' or line[hi - 1] == '\t')) hi -= 1;
+ }
+ return null;
+}
+
+pub fn resolve(p: ?*pardes.Pardes, word_raw: []const u8, cwd: []const u8, realbuf: *[4096]u8) Target {
+ const trimmed = std.mem.trim(u8, word_raw, " \t\r\n");
+ const pl = parsePathLine(trimmed);
+ const word = pl.path;
+ if (word.len == 0) return .none;
+ // POSIX resolves repeated slashes to the root directory, but bare // and
+ // /// in text are comment markers. A single / remains a valid target.
+ if (word.len > 1 and std.mem.indexOfNone(u8, word, "/") == null) return .none;
+
+ if (word.len > config.pane_addr.len and std.mem.startsWith(u8, word, config.pane_addr)) {
+ var id: usize = 0;
+ for (word[config.pane_addr.len..]) |c| {
+ if (!std.ascii.isDigit(c)) break;
+ id = id *| 10 +| (c - '0');
+ } else {
+ // `@p<serial>`: the pane's serial, as /index and the log name
+ // it, not its slot; one that is not open names none.
+ const slot = if (p) |pp| (pp.paneBySerial(@intCast(@min(id, std.math.maxInt(u32)))) orelse MAX_PANES) else id;
+ return .{ .pane = .{ .id = slot, .at = pl.at } };
+ }
+ }
+
+ for (config.url_schemes) |scheme| {
+ if (std.mem.startsWith(u8, trimmed, scheme)) return .{ .url = trimmed };
+ }
+
+ const found = filesystem.resolve(p, word, cwd, realbuf) orelse return .none;
+ if (found.dir) return .{ .dir = found.path };
+ if (p) |pp| if (pp.kinds.forPath(found.path)) |k| return .{ .kind = .{ .path = found.path, .kind = k, .at = pl.at } };
+ return .{ .file = .{ .path = found.path, .at = pl.at } };
+}
+
+// ---- looking inside the editor: expanding the word under a click, the n/N
+// walk over look-able text, search results, the hover preview, and lookAt,
+// which opens or focuses what a word names ----
+
+pub const LookHoverWait = struct {
+ col: u16,
+ row: u16,
+ pane: usize,
+ serial: u32,
+ frames: u16 = 0,
+ body_hit: ?Mouse.BodyHit = null,
+ tag_hit: ?TagHit = null,
+};
+
+pub const LookHoverPreview = struct {
+ col: u16,
+ row: u16,
+ pane: usize,
+ serial: u32,
+ sel: ?Pane.Sel,
+ file_word: ?FileWordSpan = null,
+ body_hit: ?Mouse.BodyHit = null,
+ tag_hit: ?TagHit = null,
+};
+
+pub const FileWordSpan = struct {
+ row: i32,
+ lo: i32,
+ hi: i32, // exclusive
+};
+
+pub fn armLookWalk(p: *Pardes, id: usize) void {
+ const pane = p.panes[id] orelse return;
+ if (pane.file) |file| if (file.content.len == 0) return;
+ p.look_walk_owner = pane.serial;
+}
+
+pub fn invalidateLookHover(p: *Pardes, id: usize) void {
+ if (lookHoverPane(p) != id) return;
+ p.view().raw_hover_intent = false;
+ cancelLookHover(p);
+}
+
+pub const ExpandedWord = struct { lo: usize, hi: usize };
+
+pub fn expandedWord(line: []const u8, col: usize) ?ExpandedWord {
+ if (col >= line.len) return null;
+ const b = config.wordBounds(line, col);
+ const command_run = b.hi > b.lo and config.commandWord(line[b.lo..b.hi]) != null;
+ if (!config.isFileChar(line[col]) and !command_run) return null;
+ if (b.hi <= b.lo) return null;
+ return .{ .lo = b.lo, .hi = b.hi };
+}
+
+/// acme: a no-drag middle/right click expands to the word under it —
+/// file-ish, or a whole `` @`...` `` run (config.wordBounds is the spelling)
+pub fn expandedSel(p: *Pardes, pane: *Pane, at: Pane.Sel) ?Pane.Sel {
+ var sl = at;
+ if (sl.c0 != sl.c1 or sl.r0 != sl.r1) return sl;
+ if (sl.r0 >= 0 and sl.r0 < pane.tag_rows) return tagWordSel(p, pane, sl);
+ const text = edit.paneText(p, pane) catch return null;
+ var it = std.mem.splitAny(u8, text, "\n");
+ var v: i32 = 0;
+ while (it.next()) |line| : (v += 1) {
+ if (v != sl.r0) continue;
+ const display_col: usize = @intCast(@max(0, sl.c0));
+ const col = panes.File.renderedLineByteCol(pane, v, line, display_col);
+ const b = expandedWord(line, col) orelse return null;
+ sl.c0 = @intCast(panes.File.renderedLineDisplayCol(pane, v, line, b.lo));
+ sl.c1 = @intCast(panes.File.renderedLineDisplayCol(pane, v, line, b.hi) - 1);
+ return sl;
+ }
+ return null;
+}
+
+/// A tag word is expanded in the tag's own text, so a word the wrapping
+/// broke across rows is still one word, as acme's frame wraps a tag
+/// without breaking its text.
+fn tagWordSel(p: *Pardes, pane: *Pane, at: Pane.Sel) ?Pane.Sel {
+ const arena = p.scratch.allocator();
+ const shown = tagline.shownTag(p, arena, pane) catch return null;
+ const whole = tagline.tagText(p, arena, pane) catch return null;
+ const row: usize = @as(usize, @intCast(at.r0)) + pane.tag_top;
+ const shown_line = modal.lineSlice(shown.text, row);
+ const real = shown.toReal(modal.lineStartOffset(shown.text, row) + panes.File.rawAtDisplay(shown_line, @intCast(@max(0, at.c0))));
+ const start = if (std.mem.lastIndexOfScalar(u8, whole[0..@min(real, whole.len)], '\n')) |nl| nl + 1 else 0;
+ const end = std.mem.indexOfScalarPos(u8, whole, start, '\n') orelse whole.len;
+ const b = expandedWord(whole[start..end], real - start) orelse return null;
+ const lo = shownCell(shown.text, shown.fromReal(start + b.lo), pane.tag_top);
+ const hi = shownCell(shown.text, shown.fromReal(start + b.hi - 1), pane.tag_top);
+ return .{ .state = at.state, .r0 = lo.row, .c0 = lo.col, .r1 = hi.row, .c1 = hi.col };
+}
+
+fn shownCell(text: []const u8, off: usize, top: usize) struct { row: i32, col: i32 } {
+ const before = text[0..@min(off, text.len)];
+ const row = std.mem.count(u8, before, "\n");
+ const line_start = if (std.mem.lastIndexOfScalar(u8, before, '\n')) |nl| nl + 1 else 0;
+ return .{
+ .row = @as(i32, @intCast(row)) - @as(i32, @intCast(top)),
+ .col = @intCast(panes.File.rawDisplayCol(text[line_start..], off - line_start)),
+ };
+}
+
+/// the word under the modal cursor as a pane-local selection (paneText
+/// coords: row 0 is the tag; file panes carry the line-number prefix)
+pub fn cursorWordSel(p: *Pardes, pane: *Pane) Pane.Sel {
+ const w = pane.wrapRow(pane.body.cur_row, pane.body.cur_col);
+ const vrow = w.row + @as(i32, pane.tag_rows);
+ const vcol = if (pane.file != null)
+ w.pad + panes.File.displayOffset(pane, pane.body.cur_row, w.at, pane.body.cur_col) + @as(i32, panes.File.gutterWidth(pane))
+ else blk: {
+ const lines = edit.paneCursorLines(p.editor(), &pane.body) catch break :blk pane.body.cur_col;
+ const local = pane.body.cur_row;
+ if (local < 0 or @as(usize, @intCast(local)) >= lines.len) break :blk pane.body.cur_col;
+ break :blk panes.File.lineDisplayOffset(lines[@intCast(local)], @intCast(@max(0, w.at)), @intCast(@max(0, pane.body.cur_col)));
+ };
+ return .{ .state = .done, .c0 = vcol, .c1 = vcol, .r0 = vrow, .r1 = vrow };
+}
+
+const SearchStart = enum { top, cursor };
+
+pub fn submitSearch(p: *Pardes, id: usize) void {
+ const pane = p.panes[id] orelse return;
+ if (normal.selRegexArmed(pane)) |a| {
+ // helix keeps the pattern in `/`
+ if (a.pat.len > 0) {
+ p.registers.put(p.gpa, '/', a.pat, 0, 1, true) catch |err| return p.reportError(id, "search", err);
+ p.registers.last_search = '/';
+ }
+ return if (panes.promptTarget(p, pane)) |t| normal.applySelRegex(p, pane, t, a.pat, a.mode);
+ }
+ const armed = pane.promptText() orelse return;
+ const slash = std.mem.indexOfScalar(u8, armed, '/') orelse return;
+ if (std.mem.startsWith(u8, armed, config.rename_marker)) return p.lspRequest(id, .rename, armed[slash + 1 ..]);
+ if (std.mem.startsWith(u8, armed, config.symbol_marker)) return p.lspRequest(id, .workspace_symbols, armed[slash + 1 ..]);
+ // A PDF's `/` and a terminal's: a text's is its query pane (Query.zig).
+ _ = runSearch(p, id, armed[slash + 1 ..], .top, true) catch |err| return p.reportError(id, "search", err);
+ var pattern: std.ArrayList(u8) = .empty;
+ normal.appendSearchLiteral(&pattern, p.scratch.allocator(), armed[slash + 1 ..]) catch |err| return p.reportError(id, "search", err);
+ p.registers.put(p.gpa, '/', pattern.items, 0, 1, true) catch |err| return p.reportError(id, "search", err);
+ p.registers.last_search = '/';
+ lookFirstHit(p, id);
+}
+
+fn lookFirstHit(p: *Pardes, id: usize) void {
+ const pane = p.panes[id] orelse return;
+ const rid = pane.search_pane orelse return;
+ const rp = p.panes[rid] orelse return;
+ if ((rp.file orelse return).content.len == 0) return;
+ p.view().active = rid;
+ lookWalk(p, 1);
+ if (p.view().active != rid) return; // walked out of the list; leave it there
+ const txt = edit.currentSelText(p, rp) orelse return;
+ // spent, exactly as the look chord spends it (handleKey)
+ rp.body.vsel.active = false;
+ rp.body.select = false;
+ exec.runBuiltin(p, config.look_cmd, rid, "", txt);
+}
+
+/// Fills the results buffer, and answers how many rows a text or PDF
+/// search found. With `open_empty` false a text search that found nothing
+/// opens no buffer. A search of one pane's text (or its PDF) writes at
+/// most this many bytes of rows: past it, the rows stop and say where.
+pub const search_text_output_bytes = 16 << 20;
+
+pub fn runSearch(p: *Pardes, id: usize, pat_raw: []const u8, start: SearchStart, open_empty: bool) !usize {
+ const pane = p.panes[id] orelse return 0;
+ // Blanks at either end are the pattern's (a look of an indented line);
+ // a builtin's argument comes trimmed already.
+ const pat = std.mem.trimEnd(u8, pat_raw, "\r\n");
+ if (std.mem.trim(u8, pat, " \t").len == 0) return 0;
+ const arena = p.scratch.allocator();
+ // where the pane lives: a file's directory, a shell's cwd — the
+ // directory the results buffer is named in. From a column's or the
+ // workspace's tag, the session's.
+ const dir = if (p.exec_header) p.sessionDir() else Pardes.paneDir(pane);
+ const out = try @import("memory.zig").unfilled(arena, search_text_output_bytes);
+ var out_len: usize = 0;
+ var nrows: usize = 0;
+ var anchor: ?usize = null;
+ if (pane.addon != null) {
+ // A kind's own rows, if it has a search.
+ const rows = Kind.search(p, id, pat) orelse "";
+ out_len = @min(rows.len, out.len);
+ @memcpy(out[0..out_len], rows[0..out_len]);
+ nrows = std.mem.count(u8, rows, "\n");
+ } else {
+ const lines = try edit.paneCursorLines(p.editor(), &pane.body);
+ // a real file names itself; a terminal or an output buffer has no path
+ const has_path = if (pane.file) |f| f.output == null else false;
+ var idbuf: [16]u8 = undefined;
+ // relative to `dir`, like Find's rows — and `dir` IS this file's
+ // own directory, so that is exactly its basename
+ const loc: []const u8 = if (has_path)
+ std.Io.Dir.path.basename(pane.file.?.path)
+ else
+ std.fmt.bufPrint(&idbuf, config.pane_addr ++ "{d}", .{pane.serial}) catch unreachable; // `@p` and a u32 fit 16
+ const cl: usize = @intCast(@max(0, pane.body.cur_row));
+ const cc: usize = @intCast(@max(0, pane.body.cur_col));
+ for (lines, 0..) |ln, i| {
+ const at = std.ascii.findIgnoreCase(ln, pat) orelse continue;
+ const row = std.fmt.bufPrint(out[out_len..], "{s}:{d}:{d}{c}{d} {s}\n", .{
+ loc, i + 1, at + 1, config.range_sep, at + pat.len, std.mem.trimEnd(u8, ln, " \t"),
+ }) catch {
+ // Past what it may write: the rows stop, and say where.
+ if (nrows > 0) {
+ const note = std.fmt.bufPrint(out[out_len..], "cut at {d} lines\n", .{nrows}) catch "";
+ out_len += note.len;
+ nrows += @intFromBool(note.len > 0);
+ }
+ break;
+ };
+ if (start == .cursor and (i < cl or (i == cl and at <= cc))) anchor = nrows;
+ out_len += row.len;
+ nrows += 1;
+ }
+ }
+ // A word looked for that is nowhere opens nothing.
+ if (!open_empty and nrows == 0) return 0;
+ const content = try p.gpa.dupe(u8, out[0..out_len]);
+ try panes.Output.fillResults(p, id, dir, .search, pat, content, anchor);
+ return nrows;
+}
+
+pub fn jumpResult(p: *Pardes, id: usize, row: usize) bool {
+ const pane = p.panes[id] orelse return false;
+ const rid = pane.search_pane orelse return false;
+ const rp = p.panes[rid] orelse return false;
+ const rf = if (rp.file) |*f| f else return false;
+ const tr = panes.Output.fileTraits(rf.output);
+ const ln = modal.lineSlice(rf.content, row);
+ if (ln.len == 0) return false;
+ const r: i32 = @intCast(row);
+ pane.search_row = row;
+ // the visited result, selected back from its line's end
+ rp.body.vsel = .{ .active = true, .row = r, .col = @intCast(ln.len), .explicit = true };
+ rp.body.nsel = 0;
+ rp.body.cur_row = r;
+ rp.body.cur_pinned = true;
+ const off = rp.scroll();
+ const last = off + @as(i32, rp.rows) - 1;
+ if (r < off) rp.scrollBy(r - off) else if (r > last) rp.scrollBy(r - last);
+ var realbuf: [4096]u8 = undefined;
+ const span = if (tr.commands)
+ wholeRowSpan(ln)
+ else
+ lineSpan(p, ln, Pardes.paneDir(rp), &realbuf) orelse blk: {
+ const target = panes.Output.location(ln);
+ break :blk if (target.at.line > 0)
+ Span{ .start = 0, .end = target.end }
+ else
+ null;
+ };
+ if (span) |selected| {
+ rp.body.cur_col = @intCast(selected.start);
+ rp.look_at = .{
+ .row = r,
+ .col0 = @intCast(selected.start),
+ .col1 = @intCast(selected.end - 1),
+ };
+ } else {
+ rp.body.cur_col = 0;
+ rp.look_at = null;
+ }
+ if (tr.commands) {
+ exec.runBuiltin(p, config.exec_cmd, rid, "", std.mem.trim(u8, ln, " \t\r"));
+ } else if (span) |selected| {
+ lookAt(p, rid, ln[selected.start..selected.end]);
+ // This is the newly visited result, not a selection carried into
+ // the destination. Look cleared the previous source selection.
+ rp.body.vsel = .{ .active = true, .row = r, .col = @intCast(ln.len), .explicit = true };
+ }
+ armLookWalk(p, rid);
+ return true;
+}
+
+const LookFrom = struct { row: i32, col: ?i32, strict: bool = false };
+
+fn lookEdge(delta: i32) LookFrom {
+ return .{ .row = if (delta > 0) 0 else std.math.maxInt(i32), .col = null };
+}
+
+fn lookStand(pane: *Pane) LookFrom {
+ if (pane.look_at) |s| if (s.row == pane.body.cur_row and s.col0 == pane.body.cur_col)
+ return .{ .row = s.row, .col = s.col0, .strict = true };
+ // A selection on one row (a Restore brings the dot back as one, with no
+ // walk remembered) is where the walk stands: from its start, past it
+ // either way, as from a spot the walk landed on.
+ const v = pane.body.vsel;
+ if (v.active and v.explicit and v.row == pane.body.cur_row and v.col != pane.body.cur_col)
+ return .{ .row = v.row, .col = @min(v.col, pane.body.cur_col), .strict = true };
+ return .{ .row = pane.body.cur_row, .col = pane.body.cur_col };
+}
+
+fn lookWalkPanes(p: *Pardes, out: *[MAX_PANES]usize) []const usize {
+ const v = p.view();
+ var n: usize = 0;
+ // A command pane walked from (`make`'s errors): its own places first.
+ if (commandPaneActive(p)) {
+ out[0] = v.active;
+ n = 1;
+ }
+ var i = p.n_look_src;
+ while (i > 0) {
+ i -= 1;
+ const id = p.paneBySerial(p.look_src[i]) orelse continue;
+ if (n > 0 and out[0] == id) continue;
+ out[n] = id;
+ n += 1;
+ }
+ const looked = n;
+ for (p.panes, 0..) |slot, id| {
+ const pane = slot orelse continue;
+ const f = pane.file orelse continue;
+ if (f.output == null) continue;
+ for (out[0..looked]) |k| {
+ if (k == id) break;
+ } else {
+ // insertion by serial descending — at most MAX_PANES
+ // comparisons, which is not a sort worth naming
+ var at = n;
+ while (at > looked and p.panes[out[at - 1]].?.serial < pane.serial) : (at -= 1)
+ out[at] = out[at - 1];
+ out[at] = id;
+ n += 1;
+ }
+ }
+ if (n == 0) {
+ if (p.panes[v.active] == null) return out[0..0];
+ out[0] = v.active;
+ n = 1;
+ }
+ return out[0..n];
+}
+
+fn lookPast(col0: i32, from: LookFrom, on_start_row: bool, delta: i32) bool {
+ if (!on_start_row) return true;
+ const c = from.col orelse return true;
+ if (delta > 0) return if (from.strict) col0 > c else col0 >= c;
+ return if (from.strict) col0 < c else col0 <= c;
+}
+
+fn wholeRowSpan(ln: []const u8) ?Span {
+ var lo: usize = 0;
+ while (lo < ln.len and (ln[lo] == ' ' or ln[lo] == '\t')) lo += 1;
+ const hi = std.mem.trimEnd(u8, ln, " \t\r").len;
+ return if (hi > lo) .{ .start = lo, .end = hi } else null;
+}
+
+pub fn wordSpan(p: ?*pardes.Pardes, word: []const u8, cwd: []const u8, realbuf: *[4096]u8) ?Span {
+ if (word.len == 0) return null;
+ var lo: usize = 0;
+ var hi: usize = word.len;
+ while (lo < hi and std.mem.indexOfScalar(u8, lead_trim, word[lo]) != null) lo += 1;
+ while (hi > lo and std.mem.indexOfScalar(u8, trail_trim, word[hi - 1]) != null) hi -= 1;
+ if (lo < hi and resolve(p, word[lo..hi], cwd, realbuf) != .none) return .{ .start = lo, .end = hi };
+ if (lo == 0 and hi == word.len) return null;
+ if (resolve(p, word, cwd, realbuf) == .none) return null;
+ return .{ .start = 0, .end = word.len };
+}
+
+fn lookSpanIn(p: *Pardes, pane: *Pane, from: LookFrom, delta: i32, budget: *usize) ?Pane.LookSpot {
+ const lines = edit.paneCursorLines(p.editor(), &pane.body) catch return null;
+ const nrows: i32 = @intCast(lines.len);
+ if (nrows == 0) return null;
+ const grain: panes.Output.Grain = if (pane.file) |*f| panes.Output.grain(f.output) else .word;
+ const dir = Pardes.paneDir(pane);
+ var realbuf: [4096]u8 = undefined;
+ const start = std.math.clamp(from.row, 0, nrows - 1);
+ var r = start;
+ while (r >= 0 and r < nrows) : (r += delta) {
+ if (budget.* == 0) return null;
+ budget.* -= 1;
+ const ln = lines[@intCast(r)];
+ if (pane.file) |*f| if (!panes.Output.isWalkRow(f, @intCast(r), ln)) continue;
+ const on_start = r == start;
+ switch (grain) {
+ .word => {
+ var best: ?Pane.LookSpot = null;
+ var i: usize = 0;
+ while (i < ln.len) {
+ while (i < ln.len and (ln[i] == ' ' or ln[i] == '\t')) i += 1;
+ const t0 = i;
+ while (i < ln.len and ln[i] != ' ' and ln[i] != '\t') i += 1;
+ if (i == t0) break;
+ const sp = wordSpan(p, ln[t0..i], dir, &realbuf) orelse continue;
+ const col0: i32 = @intCast(t0 + sp.start);
+ if (!lookPast(col0, from, on_start, delta)) continue;
+ best = .{ .row = r, .col0 = col0, .col1 = @intCast(t0 + sp.end - 1) };
+ if (delta > 0) break; // first one forward; keep the last one back
+ }
+ if (best) |b| return b;
+ },
+ // one span per row, so there is nothing to keep and nothing to
+ // scan past: the row either offers it or it does not
+ .line, .whole => {
+ const sp = span: {
+ if (grain == .whole) break :span wholeRowSpan(ln);
+ if (pane.file) |f| if (@as(usize, @intCast(r)) < f.location_rows.len) {
+ const end = f.location_rows[@intCast(r)].location_end;
+ if (end > 0) {
+ const start_byte = if (f.output != null and std.meta.eql(f.output.?.from, panes.Output.Origin{ .query = .callstack }))
+ @import("locations.zig").treePrefix(ln).end
+ else
+ 0;
+ break :span @as(?Span, .{ .start = start_byte, .end = end });
+ }
+ };
+ break :span lineSpan(p, ln, dir, &realbuf);
+ } orelse continue;
+ const col0: i32 = @intCast(sp.start);
+ if (lookPast(col0, from, on_start, delta))
+ return .{ .row = r, .col0 = col0, .col1 = @intCast(sp.end - 1) };
+ },
+ }
+ }
+ return null;
+}
+
+/// A command pane has the keyboard: `n` there walks its own output.
+fn commandPaneActive(p: *Pardes) bool {
+ const pane = p.panes[p.view().active] orelse return false;
+ return pane.command != null and pane.file == null and p.view().header == null;
+}
+
+pub fn lookWalk(p: *Pardes, delta: i32) void {
+ var buf: [MAX_PANES]usize = undefined;
+ const order = lookWalkPanes(p, &buf);
+ if (order.len == 0) return;
+ // From a command pane the walk starts there, whoever walked last.
+ const owner = if (commandPaneActive(p)) p.view().active else if (p.look_walk_owner) |serial| p.paneBySerial(serial) else null;
+ const active_at = std.mem.indexOfScalar(usize, order, p.view().active) orelse 0;
+ const at = if (owner) |wanted|
+ std.mem.indexOfScalar(usize, order, wanted) orelse active_at
+ else
+ active_at;
+ var from = lookStand(p.panes[order[at]] orelse return);
+ var budget: usize = max_look_rows;
+ var k: usize = 0;
+ while (k <= order.len) : (k += 1) {
+ // `+ 2 * len` only so the backward subtraction stays unsigned
+ const idx = (if (delta > 0) at + k else at + 2 * order.len - k) % order.len;
+ const pane = p.panes[order[idx]] orelse continue;
+ if (lookSpanIn(p, pane, from, delta, &budget)) |spot|
+ return landLookSpot(p, order[idx], pane, spot);
+ if (budget == 0) return; // gave up mid-pane: stay put, stay reversible
+ from = lookEdge(delta);
+ }
+}
+
+fn landLookSpot(p: *Pardes, id: usize, pane: *Pane, spot: Pane.LookSpot) void {
+ edit.pinPaneCursor(p.editor(), &pane.body); // fresh out of tty mode the cursor still tracks the shell
+ pane.body.vsel = .{ .active = true, .row = spot.row, .col = spot.col1, .explicit = true };
+ pane.body.nsel = 0;
+ pane.body.cur_row = spot.row;
+ pane.body.cur_col = spot.col0;
+ pane.body.cur_pinned = true;
+ pane.look_at = spot;
+ p.look_walk_owner = pane.serial;
+ p.view().active = id;
+ pane.ensureCursorVisible();
+}
+
+pub fn cancelLookHover(p: *Pardes) void {
+ p.look_hover_wait = null;
+ p.look_hover_preview = null;
+}
+
+pub fn lookHoverPane(p: *const Pardes) ?usize {
+ if (p.look_hover_preview) |preview| return preview.pane;
+ if (p.look_hover_wait) |waiting| return waiting.pane;
+ return null;
+}
+
+fn noteLookHover(p: *Pardes, col: u16, row: u16, body_hit: ?Mouse.BodyHit, tag_hit: ?TagHit) void {
+ const id = mouse.paneAt(p, col, row) orelse return cancelLookHover(p);
+ const pane = p.panes[id] orelse return cancelLookHover(p);
+ _ = edit.pointerTextSelection(p, id, col, row, body_hit, tag_hit) orelse return cancelLookHover(p);
+
+ if (p.look_hover_preview) |shown|
+ if (shown.col == col and shown.row == row and shown.pane == id and shown.serial == pane.serial and mouse.sameBodyCell(shown.body_hit, body_hit) and Layer.sameCell(shown.tag_hit, tag_hit)) return;
+ if (p.look_hover_wait) |waiting|
+ if (waiting.col == col and waiting.row == row and waiting.pane == id and waiting.serial == pane.serial and mouse.sameBodyCell(waiting.body_hit, body_hit) and Layer.sameCell(waiting.tag_hit, tag_hit)) return;
+
+ // Found nothing to open here a moment ago: the pointer resting on it
+ // does not start another wait (and another frame) every frame.
+ if (p.look_hover_refused) |refused|
+ if (refused.col == col and refused.row == row and refused.pane == id and refused.serial == pane.serial and mouse.sameBodyCell(refused.body_hit, body_hit) and Layer.sameCell(refused.tag_hit, tag_hit)) return;
+ p.look_hover_refused = null;
+
+ cancelLookHover(p);
+ p.look_hover_wait = .{ .col = col, .row = row, .pane = id, .serial = pane.serial, .body_hit = body_hit, .tag_hit = tag_hit };
+}
+
+pub fn refreshLookHoverFromRaw(p: *Pardes) void {
+ const v = p.view();
+ if (!v.pointer_inside or !v.raw_hover_intent) return;
+ const mapped: struct { col: u16, row: u16 } = .{ .col = v.pointer_raw_col, .row = v.pointer_raw_row };
+ v.hover_col = mapped.col;
+ v.hover_row = mapped.row;
+ const body_hit: ?Mouse.BodyHit = if (v.pointer_body_hit) |mapped_hit|
+ mouse.bodyHitForPane(p, mouse.paneAt(p, mapped.col, mapped.row) orelse return cancelLookHover(p), mapped_hit, false) orelse return cancelLookHover(p)
+ else
+ null;
+ noteLookHover(p, mapped.col, mapped.row, body_hit, v.pointer_tag_hit);
+}
+
+pub fn advanceLookHover(p: *Pardes) void {
+ const delay = config.look_preview_delay_frames;
+ const waiting = if (p.look_hover_wait) |*w| w else return;
+ waiting.frames +|= 1;
+ if (waiting.frames < delay) return;
+ const pane = p.panes[waiting.pane] orelse return cancelLookHover(p);
+ if (pane.serial != waiting.serial) return cancelLookHover(p);
+ const pointed = edit.pointerTextSelection(p, waiting.pane, waiting.col, waiting.row, waiting.body_hit, waiting.tag_hit) orelse {
+ p.look_hover_refused = waiting.*;
+ return cancelLookHover(p);
+ };
+ const operand = exec.operandAt(p, pane, pointed.sel, true, true);
+ if (operand.text == null or operand.text.?.len == 0) {
+ p.look_hover_refused = waiting.*;
+ return cancelLookHover(p);
+ }
+ var preview = operand.preview;
+ if (preview) |*sel| sel.state = .done;
+ p.look_hover_preview = .{
+ .col = waiting.col,
+ .row = waiting.row,
+ .pane = waiting.pane,
+ .serial = waiting.serial,
+ .sel = preview,
+ .file_word = operand.file_word,
+ .body_hit = waiting.body_hit,
+ .tag_hit = waiting.tag_hit,
+ };
+ p.look_hover_wait = null;
+}
+
+pub fn focusPaneLine(p: *Pardes, id: usize, at: Spot, landing: enum { center, keep }) void {
+ if (id >= MAX_PANES) return;
+ const pane = p.panes[id] orelse return;
+ p.view().active = id;
+ if (pane.collapsed) layout.toggleCollapse(p, id);
+ pane.body.normal.clear();
+ // A kind's place is its `address`'s (lookKind).
+ if (pane.addon != null) return;
+ if (at.line == 0) return;
+ if (pane.file) |*f| {
+ if (at.line > panes.File.nlines(p.gpa, f)) return;
+ if (landing == .center) {
+ // center, clamp at top; a text that fits is shown whole
+ const next = if (pane.textFits()) 0 else (at.line - 1) -| pane.rows / 2;
+ if (next != f.scroll) {
+ f.scroll = next;
+ f.syntax_dirty = true;
+ }
+ }
+ }
+ pane.body.cur_row = @intCast(at.line - 1);
+ pane.body.cur_col = if (at.col > 0) @intCast(at.col - 1) else 0;
+ pane.body.cur_pinned = true;
+ if (at.end_line != 0) return selectSpan(p, pane, at);
+ pane.ensureCursorVisible();
+}
+
+fn selectSpan(p: *Pardes, pane: *Pane, at: Spot) void {
+ const text = edit.flatSurface(p.editor(), &pane.body) catch |err| return p.reportError(p.view().active, "look", err);
+ // saturating, not `- 1`: `f.zig:0-5` is a legal thing to type and a
+ // 1-based zero is the same nothing an absent number is
+ const acol: i32 = @intCast(at.col -| 1);
+ const ecol: i32 = if (at.end_col > 0) @intCast(at.end_col - 1) else std.math.maxInt(i32);
+ const r = panes.Text.cellRange(text, @intCast(at.line -| 1), acol, @intCast(at.end_line -| 1), ecol);
+ pane.body.setRange(text, 0, r, true);
+}
+
+fn openPaneTarget(p: *const Pardes, path: []const u8, at: Spot) ?Target {
+ for (p.panes, 0..) |slot, i| {
+ const tt = slot orelse continue;
+ if (tt.addon) |k| if (std.mem.eql(u8, k.path, path)) {
+ return .{ .pane = .{ .id = i, .at = at } };
+ };
+ const ff = if (tt.file) |*f| f else continue;
+ if (!std.mem.eql(u8, ff.path, path)) continue;
+ return .{ .pane = .{ .id = i, .at = at } };
+ }
+ return null;
+}
+
+/// Navigation starts a new selection at the destination.
+pub fn clearNavigationSelection(p: *Pardes, pane: *Pane) void {
+ const v = p.view();
+ pane.body.vsel = .{};
+ pane.body.nsel = 0;
+ pane.body.select = false;
+ pane.body.normal.clear();
+ pane.body.restore_cursor = false;
+ pane.body.sticky_col = -1;
+ for (0..pane.sel.len) |slot| pane.clearPointerSelection(slot);
+ pane.sel = @splat(.{});
+ if (v.drag == .select and p.panes[v.drag.select.id] == pane) v.drag = .none;
+}
+
+/// The directories a relative name is looked for in, in order, as acme's
+/// look tries its window's and then the other windows' (Incl's come
+/// after, the caller's, as includename's): `first` (the pane's own, a
+/// plumb message's wdir), then the directory of each pane of the jump list
+/// but `from`, newest first, each once.
+pub const Dirs = struct {
+ p: *Pardes,
+ from: ?usize,
+ seen: [MAX_PANES + 1][]const u8 = undefined,
+ nseen: usize = 0,
+ /// The next of the jump list's, counted from its newest.
+ n: usize = 1,
+
+ pub fn init(p: *Pardes, from: ?usize, first: ?[]const u8) Dirs {
+ var d: Dirs = .{ .p = p, .from = from };
+ if (first) |dir| {
+ d.seen[0] = dir;
+ d.nseen = 1;
+ d.n = 0;
+ }
+ return d;
+ }
+
+ pub fn next(d: *Dirs) ?[]const u8 {
+ if (d.n == 0) {
+ d.n = 1;
+ return d.seen[0];
+ }
+ const id = d.from orelse return null;
+ const jumps = &d.p.view().jumps;
+ cand: while (d.n <= jumps.n) {
+ const k = jumps.list[jumps.n - d.n].pane;
+ d.n += 1;
+ if (k == id) continue;
+ const dir = Pardes.paneDir(d.p.panes[k] orelse continue);
+ for (d.seen[0..d.nseen]) |s| if (std.mem.eql(u8, s, dir)) continue :cand;
+ d.seen[d.nseen] = dir;
+ d.nseen += 1;
+ return dir;
+ }
+ return null;
+ }
+};
+
+/// Resolve without changing focus or falling back to search. PDF links use
+/// the same location rules as an ordinary Look before offering a choice.
+fn resolveLookTarget(p: *Pardes, id: usize, txt: []const u8, realbuf: *[4096]u8) Target {
+ const trimmed = std.mem.trim(u8, txt, " \t\r\n");
+ const pl = parsePathLine(trimmed);
+ if (pl.path.len > 0) if (openPaneTarget(p, pl.path, pl.at)) |target| return target;
+ var found: Target = .none;
+ var dirs: Dirs = .init(p, id, if (p.panes[id]) |op| Pardes.paneDir(op) else null);
+ while (dirs.next()) |dir| {
+ if (pl.path.len > 0 and pl.path[0] != '/') {
+ var joinbuf: [2048]u8 = undefined;
+ if (std.fmt.bufPrint(&joinbuf, "{s}/{s}", .{ dir, pl.path }) catch null) |j|
+ if (openPaneTarget(p, j, pl.at)) |target| return target;
+ }
+ found = resolve(p, txt, dir, realbuf);
+ // `.`, `..`, `./x` are this pane's directory's, not another's.
+ if (found != .none or pl.path.len == 0 or pl.path[0] == '/' or filesystem.dotRelative(pl.path)) break;
+ }
+ // Found nowhere else, a relative name is tried in Incl's directories,
+ // as acme's includename tries its (look.c:500).
+ if (found == .none and pl.path.len > 0 and pl.path[0] != '/' and !filesystem.dotRelative(pl.path))
+ for (p.incl.items) |dir| {
+ found = resolve(p, txt, dir, realbuf);
+ if (found != .none) break;
+ };
+ return found;
+}
+
+fn locationText(p: *Pardes, path: []const u8, at: Spot) ?[]const u8 {
+ if (std.mem.indexOfAny(u8, path, "\r\n") != null) return null;
+ const arena = p.scratch.allocator();
+ if (at.line == 0) return arena.dupe(u8, path) catch null;
+ if (at.end_line != 0) {
+ if (at.col == 0 and at.end_col == 0)
+ return std.fmt.allocPrint(arena, "{s}:{d}-{d}", .{ path, at.line, at.end_line }) catch null;
+ return std.fmt.allocPrint(arena, "{s}:{d}:{d}-{d}:{d}", .{ path, at.line, at.col, at.end_line, at.end_col }) catch null;
+ }
+ if (at.col != 0) return std.fmt.allocPrint(arena, "{s}:{d}:{d}", .{ path, at.line, at.col }) catch null;
+ return std.fmt.allocPrint(arena, "{s}:{d}", .{ path, at.line }) catch null;
+}
+
+fn canonicalLookLocation(p: *Pardes, id: usize, text: []const u8) ?[]const u8 {
+ const trimmed = std.mem.trim(u8, text, " \t\r\n");
+ if (trimmed.len == 0) return null;
+ var realbuf: [4096]u8 = undefined;
+ switch (resolveLookTarget(p, id, trimmed, &realbuf)) {
+ .none => return null,
+ .url => |url| {
+ if (url.len > 256) return null;
+ for (url) |c| if (c <= 0x20 or c == 0x7f) return null;
+ return p.scratch.allocator().dupe(u8, url) catch null;
+ },
+ .file => |file| return locationText(p, file.path, file.at),
+ .kind => |k| return locationText(p, k.path, .{}),
+ .dir => |dir| return locationText(p, dir, .{}),
+ .pane => |target| {
+ if (target.id >= p.panes.len) return null;
+ const pane = p.panes[target.id] orelse return null;
+ if (pane.file) |file| return locationText(p, file.path, target.at);
+ if (pane.addon) |k| if (k.path.len > 0) return locationText(p, k.path, target.at);
+ var path: [32]u8 = undefined;
+ return locationText(p, std.fmt.bufPrint(&path, config.pane_addr ++ "{d}", .{pane.serial}) catch unreachable, target.at); // `@p` and a u32 fit 32
+ },
+ }
+}
+
+/// 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, 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 {
+ return pardes.ctlfs.fitErr(text, buf[0..miss_path_cap]);
+}
+
+fn missedLine(p: *Pardes, id: usize, path: []const u8, line: usize) void {
+ var cut: [miss_path_cap + "…".len]u8 = undefined;
+ missed(p, id, "{s} has no line {d}", .{ missText(path, &cut), line });
+}
+
+/// Whether `:line:col`, `:line:col-col` or `:line:col-line:col` after a
+/// path names a column 0, which parsePathLine reads as no column.
+fn zeroColumn(rest: []const u8) bool {
+ var fields = std.mem.splitScalar(u8, rest, ':');
+ _ = fields.next(); // before the first ':'
+ _ = fields.next() orelse return false; // the line
+ const col = fields.next() orelse return false;
+ var ends = std.mem.splitScalar(u8, col, '-');
+ if (std.mem.eql(u8, ends.next().?, "0")) return true;
+ if (ends.next()) |end| if (std.mem.eql(u8, end, "0")) return true;
+ if (fields.next()) |end_col| if (std.mem.eql(u8, end_col, "0")) return true;
+ return false;
+}
+
+/// Whether `text` ends in a `:line:col` place (each spelling zeroColumn
+/// knows) whose column is 0, line 0 included.
+fn zeroColumnTail(text: []const u8) bool {
+ var i: usize = 0;
+ while (std.mem.indexOfScalarPos(u8, text, i, ':')) |at| : (i = at + 1) {
+ const rest = text[at..];
+ for (rest[1..]) |c| if (std.mem.indexOfScalar(u8, "0123456789:-", c) == null) break else {
+ if (rest.len > 1 and std.ascii.isDigit(rest[1]) and zeroColumn(rest)) return true;
+ };
+ }
+ return false;
+}
+
+fn missed(p: *Pardes, id: usize, comptime fmt: []const u8, args: anytype) void {
+ p.look_missed = true;
+ var said: Kind.Buf(miss_path_cap + 64) = .{};
+ const why = said.print(fmt, args);
+ var msg: Kind.Buf(miss_path_cap + 72) = .{};
+ // Shown on the pane; logged once, as the err below, not a msg too.
+ p.fs.unlogged = true;
+ p.setMessage(id, msg.print("Look: {s}", .{why}));
+ p.fs.unlogged = false;
+ const serial = if (p.panes[id]) |pane| pane.serial else 0;
+ var rec: Kind.Buf(miss_path_cap + 96) = .{};
+ pardes.ctlfs.events.noteErrCounted(p, rec.print("{d} look: {s}", .{ serial, why }));
+}
+
+/// A plain word looked at in a pane, as acme's look3 does with one that
+/// names no file (look.c:210, search): its next place in that pane after
+/// the dot, wrapping to the top, is selected there. No +Search pane.
+fn lookWord(p: *Pardes, id: usize, pane: *Pane, word: []const u8) void {
+ const ninep_pane = @import("ninep/pane.zig");
+ const f = pane.file orelse return;
+ const text = f.content;
+ const from: usize = @min(ninep_pane.dotOf(pane).q1, text.len);
+ const at = std.mem.indexOfPos(u8, text, from, word) orelse (std.mem.indexOf(u8, text[0..@min(text.len, from + word.len -| 1)], word) orelse {
+ var cut: [miss_path_cap + "…".len]u8 = undefined;
+ return missed(p, id, "no match for \"{s}\"", .{missText(word, &cut)});
+ });
+ clearNavigationSelection(p, pane);
+ ninep_pane.setDot(pane, .{ .q0 = @intCast(at), .q1 = @intCast(at + word.len) });
+ p.view().active = id;
+}
+
+/// `file:addr` or `:addr`, acme's look.c:450-543: a colon followed by an
+/// address character (addr.c:28, isaddrc) that is not a line spot this
+/// parser already reads (`file:12`, `file:12:5`). Not a URL.
+fn addressed(tok: []const u8) ?struct { path: []const u8, expr: []const u8 } {
+ if (std.mem.indexOf(u8, tok, "://") != null) return null;
+ const colon = std.mem.indexOfScalar(u8, tok, ':') orelse return null;
+ const expr = tok[colon + 1 ..];
+ // A written look is a whole line: the path has no blanks, but a
+ // pattern in the address may (`calc.py:/return a/`).
+ if (std.mem.indexOfAny(u8, tok[0..colon], " \t") != null) return null;
+ if (std.mem.indexOfAny(u8, expr, " \t") != null and std.mem.indexOfAny(u8, expr, "/?") == null) return null;
+ if (expr.len == 0 or std.mem.indexOfScalar(u8, "0123456789+-/?$.#,;", expr[0]) == null) return null;
+ // `file:12` is a path's line, looked at as a path; a bare `:12` (`:12:5`)
+ // has no path, and is this pane's line, an address like any other.
+ if (std.ascii.isDigit(expr[0])) {
+ const pl = parsePathLine(tok);
+ if (pl.at.line != 0 and pl.end == tok.len and pl.path.len > 0) return null;
+ }
+ return .{ .path = tok[0..colon], .expr = expr };
+}
+
+pub fn searchStep(p: *Pardes, id: usize, delta: i32) bool {
+ const pane = p.panes[id] orelse return false;
+ const rid = pane.search_pane orelse return false;
+ const rp = p.panes[rid] orelse return false;
+ const rf = if (rp.file) |*f| f else return false;
+ // one question covers both hazards: a freed slot can be reused by an
+ // unrelated pane, and a buffer of PROSE has nowhere to step to
+ const tr = panes.Output.fileTraits(rf.output);
+ if (!tr.steps) return false;
+ // fresh results: n starts at the first row, N has nothing behind it
+ const nrows: i64 = @intCast(std.mem.count(u8, rf.content, "\n") +
+ @intFromBool(rf.content.len > 0 and rf.content[rf.content.len - 1] != '\n'));
+ var step: i64 = if (pane.search_row) |c| @as(i64, @intCast(c)) + delta else if (delta > 0) 0 else -1;
+ if (delta == 0) return true;
+ const direction: i64 = if (delta > 0) 1 else -1;
+ while (step >= 0 and step < nrows) : (step += direction) {
+ if (!panes.Output.isResultRow(rf, @intCast(step))) continue;
+ _ = jumpResult(p, id, @intCast(step));
+ p.view().active = id;
+ break;
+ }
+ return true;
+}
+
+/// A look at text that names nothing to open: a `./` name is a missing
+/// file, anything else a search for the text as written.
+/// `text` is what a word search looks for: the look as written, its blanks
+/// kept; `trimmed` what a name is read from.
+fn lookUnresolved(p: *Pardes, id: usize, pane: *Pane, trimmed: []const u8, text: []const u8) void {
+ // A `./` or `../` name opened nothing: said, ENOENT, not searched
+ // for as a word. What is missing is the pane's directory when
+ // that is gone, else the file named.
+ if (filesystem.dotRelative(trimmed)) {
+ const dir = Pardes.paneDir(pane);
+ var said: Kind.Buf(4096 + 104) = .{};
+ const gone = if (filesystem.localPath(dir)) |local| exec.kindOf(local) != .directory else false;
+ if (gone) return p.reportFailure(id, said.print("look: {s}: no such directory", .{dir[0..@min(dir.len, 4096)]}));
+ // A file not there is a miss, as `x` and `/abs/x` are: said and
+ // logged, the write answered with nothing.
+ var cut: [miss_path_cap + "…".len]u8 = undefined;
+ return missed(p, id, "{s}: no such file", .{missText(trimmed, &cut)});
+ }
+ // A raw terminal's clicks are its program's; a look written over
+ // 9P is no keyboard input, and searches whatever the key mode.
+ if (pane.addon != null or (pane.body.mode == .tty and !p.fs.serving)) return;
+ if (text.len == 0) return;
+ if (pane.file != null) return lookWord(p, id, pane, text);
+ p.word_look = true;
+ defer p.word_look = false;
+ const rows = runSearch(p, id, text, .cursor, false) catch |err| {
+ p.reportError(id, "search", err);
+ return;
+ };
+ if (rows == 0) {
+ var cut: [miss_path_cap + "…".len]u8 = undefined;
+ return missed(p, id, "no match for \"{s}\"", .{missText(trimmed, &cut)});
+ }
+ clearNavigationSelection(p, pane);
+ const at = pane.search_row;
+ _ = searchStep(p, id, 1);
+ if (at != null and pane.search_row == at) {
+ pane.search_row = null;
+ _ = searchStep(p, id, 1);
+ }
+}
+
+/// Opens (or finds) `path` as Look would, `id`'s own pane when it is empty,
+/// and selects what `expr` addresses there from its dot. An address that
+/// does not evaluate moves nothing and says why (acme: no jump).
+fn lookAddress(p: *Pardes, id: usize, path: []const u8, expr: []const u8) void {
+ const v = p.view();
+ const ninep_pane = @import("ninep/pane.zig");
+ const Addr = @import("ninep/addr.zig").Addr;
+ var target = id;
+ // A pane already open on the path is evaluated where it stands: Look's
+ // own clean start would collapse its dot (and the looker's) before the
+ // address ever read it, so `f:/re/` again would find the same match.
+ var realbuf: [4096]u8 = undefined;
+ const open: ?usize = if (path.len == 0) null else switch (resolveLookTarget(p, id, path, &realbuf)) {
+ .pane => |t| if (t.id < MAX_PANES and p.panes[t.id] != null) t.id else null,
+ else => null,
+ };
+ // `@p<serial>:<address>`: that pane, or, not open, a miss said as one.
+ const by_serial = std.mem.startsWith(u8, path, config.pane_addr);
+ if (by_serial and open == null) return missed(p, id, "no pane {s}", .{path[0..@min(path.len, 32)]});
+ if (open) |o| target = o else if (path.len > 0) {
+ // A path that names nothing to open: the whole of what was written
+ // is looked for, as `zzq:2` is, and a miss quotes it as written.
+ if (!by_serial and resolveLookTarget(p, id, path, &realbuf) == .none)
+ return lookUnresolved(p, id, p.panes[id] orelse return, path.ptr[0 .. path.len + 1 + expr.len], path.ptr[0 .. path.len + 1 + expr.len]);
+ const before = v.active;
+ const failures = p.fs.failures;
+ const was_missed = p.look_missed;
+ lookAt(p, id, path);
+ target = v.active;
+ // Look said why it opened nothing (its placement refused, say):
+ // that one failure is the look's, no miss of the address after it.
+ if (p.fs.failures != failures or (p.look_missed and !was_missed)) return;
+ // The path opened nothing (a search, or no such file): Look said so.
+ if (target == before and target != id) return;
+ }
+ const pane = p.panes[target] orelse return;
+ const f = pane.file orelse {
+ if (pane.addon != null) return lookKind(p, id, target, expr, open == null and target != id);
+ if ((by_serial or path.len == 0) and pane.isTerminal()) return lookTerminalAddress(p, id, target, expr);
+ // Named as the pane is, the bare `:addr` (path empty) included.
+ var serial_name: [32]u8 = undefined;
+ const subject = if (pane.addon) |k| k.path else if (path.len > 0) path else std.fmt.bufPrint(&serial_name, config.pane_addr ++ "{d}", .{pane.serial}) catch unreachable; // `@p` and a u32 fit 32
+ var cut: [miss_path_cap + "…".len]u8 = undefined;
+ return missed(p, id, "{s} is no text to address", .{missText(subject, &cut)});
+ };
+ if (!by_serial and path.len > 0 and (f.output != null or !std.mem.endsWith(u8, f.path, std.Io.Dir.path.basename(path)))) return;
+ var a: Addr = .{ .text = f.content, .lim = null, .expr = expr };
+ // A miss names the file it was looked for in, and is that file's pane's.
+ var cut: [miss_path_cap + "…".len]u8 = undefined;
+ const name = missText(f.path, &cut);
+ // A look whose address fails opens nothing: a pane it opened to read
+ // the address in goes again, the miss said from the pane it came from.
+ const opened_here = open == null and target != id;
+ const r = a.address(ninep_pane.dotOf(pane)) orelse {
+ // A line past the end says so as `file:N` does, whichever way it
+ // was written: `<file>:N has no line N`.
+ if (std.fmt.parseInt(usize, expr, 10)) |line| {
+ var placed: Kind.Buf(miss_path_cap + "…".len + 24) = .{};
+ const place = placed.print("{s}:{d}", .{ name, line });
+ if (!opened_here) return missedLine(p, target, place, line);
+ p.removePane(target, null) catch |err| p.reportError(id, "look", err);
+ if (p.panes[id] != null) v.active = id;
+ return missedLine(p, id, place, line);
+ } else |_| {}
+ if (opened_here) return closeAndMiss(p, id, target, name, a.err);
+ return missed(p, target, "{s}: {s}", .{ name, a.err });
+ };
+ if (a.i < expr.len or r.q0 > r.q1) {
+ const why = if (r.q0 > r.q1) "addresses out of order" else "bad address syntax";
+ if (opened_here) return closeAndMiss(p, id, target, name, why);
+ return missed(p, target, "{s}: {s}", .{ name, why });
+ }
+ clearNavigationSelection(p, pane);
+ ninep_pane.setDot(pane, r);
+ v.active = target;
+}
+
+/// A place in a kind's pane, its `address`'s: one looked at in a list the
+/// kind made (`text`, a +PdfSections) handed with the list's name first.
+/// A miss is said as the kind said it (`<path> has no page 99`), and a
+/// pane opened for it goes again, as for a file's line past its end.
+fn lookKind(p: *Pardes, id: usize, target: usize, expr_raw: []const u8, opened: bool) void {
+ const slot = p.panes[target].?.addon.?;
+ const expr = std.mem.trim(u8, expr_raw, " \t");
+ var buf: [512]u8 = undefined;
+ const from: []const u8 = if (p.panes[id]) |src| if (src.file) |f| if (f.output) |o| if (o.from == .kind) o.arg() else "" else "" else "" else "";
+ const text = if (from.len > 0) std.fmt.bufPrint(&buf, "{s} {s}", .{ from, expr }) catch expr else expr;
+ var said: Kind.Buf(160) = .{};
+ if (Kind.address(p, target, text, &said)) {
+ if (p.panes[target]) |pane| clearNavigationSelection(p, pane);
+ p.view().active = target;
+ return;
+ }
+ var serial_name: [32]u8 = undefined;
+ const subject = if (slot.path.len > 0) slot.path else std.fmt.bufPrint(&serial_name, config.pane_addr ++ "{d}", .{p.panes[target].?.serial}) catch unreachable; // `@p` and a u32 fit 32
+ var cut: [miss_path_cap + "…".len]u8 = undefined;
+ const name = missText(subject, &cut);
+ if (opened) {
+ var kept: [miss_path_cap + "…".len]u8 = undefined;
+ @memcpy(kept[0..name.len], name);
+ p.removePane(target, null) catch |err| p.reportError(id, "look", err);
+ if (p.panes[id] != null) p.view().active = id;
+ return missed(p, id, "{s} {s}", .{ kept[0..name.len], if (said.len > 0) said.slice() else "is no text to address" });
+ }
+ missed(p, id, "{s} {s}", .{ name, if (said.len > 0) said.slice() else "is no text to address" });
+}
+
+/// A place as `address` takes it: `12`, `12:3`.
+fn spotText(at: Spot, buf: *[41]u8) []const u8 {
+ if (at.col == 0) return std.fmt.bufPrint(buf, "{d}", .{at.line}) catch unreachable; // a usize fits 41
+ return std.fmt.bufPrint(buf, "{d}:{d}", .{ at.line, at.col }) catch unreachable; // two usizes fit 41
+}
+
+fn closeAndMiss(p: *Pardes, id: usize, opened: usize, name: []const u8, why: []const u8) void {
+ var kept: [miss_path_cap + "…".len]u8 = undefined;
+ @memcpy(kept[0..name.len], name);
+ p.removePane(opened, null) catch |err| p.reportError(id, "look", err);
+ if (p.panes[id] != null) p.view().active = id;
+ missed(p, id, "{s}: {s}", .{ kept[0..name.len], why });
+}
+
+/// `@p<terminal>:<address>`: any address over the terminal's body as its
+/// logical lines read (the lines a +Search lists as `@p<serial>:<line>`),
+/// from its cursor; the match is selected there, as a +Search row's is.
+fn lookTerminalAddress(p: *Pardes, id: usize, target: usize, expr: []const u8) void {
+ const Addr = @import("ninep/addr.zig").Addr;
+ const pane = p.panes[target].?;
+ const lines = edit.paneCursorLines(p.editor(), &pane.body) catch return missed(p, id, "{s}", .{"out of memory"});
+ var text: std.ArrayList(u8) = .empty;
+ const arena = p.scratch.allocator();
+ const row: usize = @intCast(@max(0, pane.body.cur_row));
+ var dot: u32 = 0;
+ for (lines, 0..) |ln, i| {
+ if (i == row) dot = @intCast(text.items.len + @min(ln.len, @as(usize, @intCast(@max(0, pane.body.cur_col)))));
+ text.appendSlice(arena, ln) catch |err| return p.reportError(id, "look", err);
+ text.append(arena, '\n') catch |err| return p.reportError(id, "look", err);
+ }
+ var a: Addr = .{ .text = text.items, .lim = null, .expr = expr };
+ const r = a.address(.{ .q0 = dot, .q1 = dot }) orelse return missed(p, id, "{s}", .{a.err});
+ if (a.i < expr.len or r.q0 > r.q1)
+ return missed(p, id, "{s}", .{if (r.q0 > r.q1) "addresses out of order" else "bad address syntax"});
+ const from = spotAt(text.items, r.q0);
+ var at: Spot = .{ .line = from.line, .col = from.col };
+ if (r.q1 > r.q0) {
+ // The last byte of the match, 1-based and inclusive, as a row's range.
+ const to = spotAt(text.items, r.q1 - 1);
+ at.end_line = to.line;
+ at.end_col = to.col;
+ }
+ clearNavigationSelection(p, pane);
+ focusPaneLine(p, target, at, .center);
+}
+
+/// The 1-based line and column of byte `q` of `text`.
+fn spotAt(text: []const u8, q: u32) struct { line: usize, col: usize } {
+ const upto = text[0..@min(q, text.len)];
+ const line = std.mem.count(u8, upto, "\n") + 1;
+ const start = if (std.mem.lastIndexOfScalar(u8, upto, '\n')) |nl| nl + 1 else 0;
+ return .{ .line = line, .col = upto.len - start + 1 };
+}
+
+/// A remembered place in `path` (Recent, the jumplist): the file opened or
+/// focused, then `at` clamped to it as it is now, a line past the end its
+/// last line, never a miss; a selection's two ends restored where they
+/// still fit.
+pub fn reopenAt(p: *Pardes, from: usize, path: []const u8, at: Spot) void {
+ lookAt(p, from, path);
+ const id = p.view().active;
+ const pane = p.panes[id] orelse return;
+ // A kind's place is its `address`'s (a PDF's page), quietly.
+ if (pane.addon) |k| if (std.mem.eql(u8, k.path, path)) {
+ var said: Kind.Buf(160) = .{};
+ var place: [41]u8 = undefined;
+ if (at.line > 0) _ = Kind.address(p, id, spotText(.{ .line = at.line }, &place), &said);
+ return;
+ };
+ const f = if (pane.file) |*file| file else return;
+ if (!std.mem.eql(u8, f.path, path)) return;
+ // The empty "line" after a final newline is no line to land on.
+ const n = @max(1, panes.File.nlines(p.gpa, f) - @intFromBool(std.mem.endsWith(u8, f.content, "\n")));
+ const clamp = struct {
+ fn spot(text: []const u8, lines: usize, line: usize, col: usize) [2]usize {
+ const l = std.math.clamp(line, 1, lines);
+ // Its last character at most, never the newline after it, as
+ // addr's `L:C` clamps.
+ const width = @max(1, modal.lineSlice(text, l - 1).len);
+ return .{ l, std.math.clamp(col, 1, width) };
+ }
+ };
+ const head = clamp.spot(f.content, n, at.line, at.col);
+ var to: Spot = .{ .line = head[0], .col = head[1] };
+ if (at.end_line != 0) {
+ const end = clamp.spot(f.content, n, at.end_line, at.end_col);
+ to.end_line = end[0];
+ to.end_col = end[1];
+ }
+ clearNavigationSelection(p, pane);
+ focusPaneLine(p, id, to, .center);
+ // Said when the file no longer has the line, closed or open: the place
+ // is its last line now.
+ if (at.line > n or at.end_line > n) {
+ var said: Kind.Buf(miss_path_cap + 64) = .{};
+ var cut: [miss_path_cap + "…".len]u8 = undefined;
+ p.setMessage(id, said.print("{s} has {d} lines now: at its last", .{ missText(path, &cut), n }));
+ }
+}
+
+/// Whether `pane` is the Recent query pane or the Jumplist list, whose rows
+/// are remembered places: a look at one clamps to the file as it is now.
+fn isRecentList(pane: *const Pane) bool {
+ // A query pane over the recent files: its rows are remembered places.
+ if (pane.query) |q| if (q.source == .recent) return true;
+ const f = pane.file orelse return false;
+ const o = f.output orelse return false;
+ return std.meta.eql(o.from, panes.Output.Origin{ .cmd = .Jumplist });
+}
+
+/// Whether `pane` is the History list, whose rows name dumps.
+pub fn isHistoryList(pane: *const Pane) bool {
+ const f = pane.file orelse return false;
+ const o = f.output orelse return false;
+ return std.meta.eql(o.from, panes.Output.Origin{ .cmd = .History });
+}
+
+// ---- a look on a diff line ----
+
+/// The lines of a pane showing a diff, a .diff or .patch file or a
+/// finished command pane whose output is one (ansi.DiffOutput); null for
+/// any other pane. Good until the next step.
+pub fn diffLines(p: *Pardes, pane: *Pane) ?[]const []const u8 {
+ if (pane.file) |*f| {
+ if (pane.colorAlgo() != .diff) return null;
+ return panes.File.cursorLines(p.scratch.allocator(), pane, f) catch null;
+ }
+ if (!pane.isTerminal()) return null;
+ return p.diff_output.lines(p, pane);
+}
+
+/// The look address a diff line names (diff.targetAt): `path` for a
+/// `diff --git`, `---` or `+++` line, `path:N` for a `@@` line (its first
+/// new line) and a hunk line (its new line; a removed line's, the new line
+/// now standing where it was). The look of it is a regular one, as of that
+/// text selected by hand. Null for a line no part of a file section.
+pub fn diffAddress(pane: *const Pane, lines: []const []const u8, row: usize, buf: []u8) ?[]const u8 {
+ const target = diff.targetAt(lines, row, pane.file == null) orelse return null;
+ return target.address(buf);
+}
+
+/// What a click at byte `col` of line `row` of a diff pane takes: a file
+/// or hunk header anywhere, or a hunk line on its `+`/`-`/` ` prefix, is
+/// the address the line names (diffAddress); a hunk line's code is words,
+/// from `word_from` on, the prefix never one of them. Null when the line is
+/// no part of a diff.
+const DiffClick = struct { address: ?[]const u8 = null, word_from: usize = 0 };
+
+/// What a click at byte `col` of row `row` takes, the one answer for every
+/// way a click arrives (the mouse, exec.operandAt; an empty look written
+/// back to `event`, events.expandAt; a whole line written to `look`): the
+/// address a row's producer gave it (a query pane's row on its address,
+/// Query.rowAddress), else the one the pane's language reads in the line (a
+/// diff's: diffClickIn); or where its words start, the address no part of
+/// them. `line` is the row's text it was read from, and the address's text
+/// in it ends at `end`. Null for a row that names no address.
+pub const RowAddress = struct { address: ?[]const u8 = null, word_from: usize = 0, line: []const u8, end: usize };
+
+pub fn rowAddressAt(p: *Pardes, pane: *Pane, row: usize, col: usize, buf: []u8) ?RowAddress {
+ if (panes.Query.rowAddress(pane, row, col, buf)) |address| {
+ const f = &pane.file.?;
+ return .{ .address = address, .line = modal.lineSlice(f.content, row), .end = f.location_rows[row].location_end };
+ }
+ const lines = diffLines(p, pane) orelse return null;
+ if (row >= lines.len) return null;
+ const click = diffClickIn(pane, lines, row, col, buf) orelse return null;
+ return .{ .address = click.address, .word_from = click.word_from, .line = lines[row], .end = lines[row].len };
+}
+
+fn diffClickIn(pane: *const Pane, lines: []const []const u8, row: usize, col: usize, buf: []u8) ?DiffClick {
+ if (row >= lines.len) return null;
+ const line = lines[row];
+ const address = diffAddress(pane, lines, row, buf) orelse return null;
+ const target = diff.targetAt(lines, row, pane.file == null) orelse return null;
+ const prefixed = line.len > 0 and std.mem.indexOfScalar(u8, "+- ", line[0]) != null;
+ switch (target.kind) {
+ .context, .added, .removed => if (!(col == 0 and prefixed)) return .{ .word_from = @intFromBool(prefixed) },
+ else => {},
+ }
+ return .{ .address = address };
+}
+
+/// A look written over 9P of a whole line of a pane whose rows name
+/// addresses (a diff's, a query pane's: rowAddressAt), the cursor's line
+/// first, then the first after it: what a click on its first column takes.
+/// A blank context line (` `) is a line too.
+fn lineAddress(p: *Pardes, pane: *Pane, operand: []const u8, buf: []u8) ?[]const u8 {
+ const text = std.mem.trimEnd(u8, operand, "\r\n");
+ if (text.len == 0) return null;
+ const lines = (if (pane.query != null) panes.File.cursorLines(p.scratch.allocator(), pane, &pane.file.?) catch null else diffLines(p, pane)) orelse return null;
+ const cur: usize = @intCast(@max(0, pane.body.cur_row));
+ for (0..lines.len) |k| {
+ const i = (cur + k) % lines.len;
+ if (std.mem.eql(u8, std.mem.trimEnd(u8, lines[i], "\r"), text))
+ return (rowAddressAt(p, pane, i, 0, buf) orelse return null).address;
+ }
+ return null;
+}
+
+fn noteLookSource(p: *Pardes, id: usize) void {
+ const pane = p.panes[id] orelse return;
+ var w: usize = 0;
+ for (p.look_src[0..p.n_look_src]) |s| {
+ if (s == pane.serial) continue;
+ p.look_src[w] = s;
+ w += 1;
+ }
+ if (w == p.look_src.len) {
+ std.mem.copyForwards(u32, p.look_src[0 .. w - 1], p.look_src[1..w]);
+ w -= 1;
+ }
+ p.look_src[w] = pane.serial;
+ p.n_look_src = w + 1;
+ p.look_walk_owner = pane.serial;
+}
+
+/// After a look at `path:N` focused its pane: a line past the end focuses
+/// nothing, leaves no pane it opened, and is a miss; a bare line number
+/// selects the line, its newline included, as acme's does.
+fn settleLine(p: *Pardes, id: usize, path: []const u8, at: Spot, before: usize, opened: ?usize) void {
+ const shown = p.panes[p.view().active] orelse return;
+ const f = if (shown.file) |*file| file else return;
+ if (at.line > panes.File.nlines(p.gpa, f)) {
+ if (opened) |free| p.removePane(free, null) catch |err| p.reportError(id, "look", err);
+ if (p.panes[before] != null) p.view().active = before;
+ return missedLine(p, id, path, at.line);
+ }
+ if (at.line > 0 and at.col == 0 and at.end_line == 0) {
+ const start = modal.lineStartOffset(f.content, at.line - 1);
+ const next = std.mem.indexOfScalarPos(u8, f.content, start, '\n');
+ const end = if (next) |i| i + 1 else f.content.len;
+ @import("ninep/pane.zig").setDot(shown, .{ .q0 = @intCast(start), .q1 = @intCast(end) });
+ }
+}
+
+fn focusPaneByPath(p: *Pardes, path: []const u8, at: Spot) bool {
+ const target = openPaneTarget(p, path, at) orelse return false;
+ clearNavigationSelection(p, p.panes[target.pane.id].?);
+ focusPaneLine(p, target.pane.id, target.pane.at, .center);
+ return true;
+}
+
+/// 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;
+ // Not there, on a peer's mount as on this host: a miss, the write
+ // answered, as any path to no file is.
+ const remote_missing = err == error.Remote and std.mem.indexOf(u8, @import("runtime").ninep_io.Client.lastSaid(), "not exist") != null;
+ if (err == error.FileNotFound or err == error.NotFound or remote_missing)
+ return missed(p, id, "{s}: no such file", .{missText(path, &cut)});
+ var said: Kind.Buf(miss_path_cap + 16) = .{};
+ p.reportError(id, said.print("look: {s}", .{missText(path, &cut)}), err);
+}
+
+pub fn lookAt(p: *Pardes, id: usize, operand_raw: []const u8) void {
+ const v = p.view();
+ const pane = p.panes[id] orelse return;
+ // `~/x`, `~/x:12`, `~/x:/re/`: home, before anything reads the text.
+ // Anything else as written: a look of ` return x` is of those blanks
+ // too (the path, address and command readings below trim for
+ // themselves).
+ var home_buf: [4096]u8 = undefined;
+ const stripped = std.mem.trim(u8, operand_raw, " \t\r\n");
+ const operand = if (stripped.len > 0 and stripped[0] == '~') filesystem.expandHome(stripped, &home_buf) else std.mem.trimEnd(u8, operand_raw, "\r\n");
+ // A +History line names a dump of the state file's (`Restore <label>`;
+ // its date, size and panes are the indented line under it): a look at
+ // it is a Restore of that dump; other words are looked as any (a path
+ // in it opens).
+ if (isHistoryList(pane)) {
+ var row = std.mem.trim(u8, operand, " \t\r\n");
+ if (std.mem.startsWith(u8, row, "Restore ")) row = std.mem.trimStart(u8, row["Restore ".len..], " ");
+ const label = row[0 .. std.mem.indexOfAny(u8, row, " \t") orelse row.len];
+ if (std.mem.startsWith(u8, label, "pardes-")) return exec.runBuiltin(p, .Restore, id, "Restore", label);
+ }
+ // A +Recent row is a remembered place: reopened and clamped to the file
+ // as it is now, never a miss for a line the file no longer has.
+ if (isRecentList(pane)) {
+ const row = std.mem.trim(u8, operand, " \t\r\n");
+ const loc = row[0 .. std.mem.indexOfScalar(u8, row, ' ') orelse row.len];
+ const pl = parsePathLine(loc);
+ if (pl.path.len > 0 and pl.path[0] == '/' and pl.at.line != 0) return reopenAt(p, id, pl.path, pl.at);
+ }
+ p.noteHaptic(.look);
+ noteLookSource(p, id);
+ const command = std.mem.trim(u8, operand, " \t\r\n");
+ // A whole line of a diff written over 9P (a context line ` Del`
+ // included) is a look at the address it names, never the word run.
+ var diff_buf: [4096 + 32]u8 = undefined;
+ const looked: []const u8 = lineAddress(p, pane, operand_raw, &diff_buf) orelse looked: {
+ if (config.commandWord(command)) |cmd| {
+ if (exec.execute(p, id, cmd)) |dst| v.active = dst;
+ return;
+ }
+ break :looked operand;
+ };
+ // The operand may borrow selected terminal/PDF text released below.
+ const txt = p.scratch.allocator().dupe(u8, looked) catch |err| return p.reportError(id, "look", err);
+ // A trailing `:` (`a.txt:2:3:`, as a compiler's message ends) is no
+ // part of the place, as a click's expansion leaves it off.
+ const bare = std.mem.trimEnd(u8, std.mem.trim(u8, txt, " \t\r\n"), ":");
+ // `<stdio.h>` written whole: the name inside, as a click on it takes.
+ const trimmed = if (bare.len > 2 and bare[0] == '<' and bare[bare.len - 1] == '>') bare[1 .. bare.len - 1] else bare;
+ // acme's `file:addr` and `:addr` (look.c:450-543): an address after
+ // the colon, evaluated in that file from its dot (openfile, look.c:675).
+ // `file:3:0`, and `file:0:0` too: columns count from 1, as addr's do,
+ // and a zero is refused in addr's words rather than taken as no column
+ // (or, after line 0, as an address).
+ if (zeroColumnTail(trimmed)) return p.reportFailure(id, @import("ninep/addr.zig").e_col_zero);
+ if (addressed(trimmed)) |ad| return lookAddress(p, id, ad.path, ad.expr);
+ // `:N` on a kind's pane is its place N (a PDF's page), never a search
+ // for the text.
+ if (pane.addon != null and trimmed.len > 1 and trimmed[0] == ':')
+ return lookAddress(p, id, "", trimmed[1..]);
+ const pl = parsePathLine(trimmed);
+ var realbuf: [4096]u8 = undefined;
+ // What is looked for is the place without its trailing `:`, `@p33:`
+ // and `a.txt:` as much as `a.txt:2:`.
+ const found = resolveLookTarget(p, id, trimmed, &realbuf);
+ // A line past the end of an open pane is a miss (the target's line is
+ // already clamped, so the one written is asked).
+ if (found == .pane and found.pane.id < MAX_PANES) if (p.panes[found.pane.id]) |shown| {
+ // A terminal's lines are its logical lines, as a +Search lists them.
+ const n = if (shown.file) |*f| panes.File.nlines(p.gpa, f) else if (shown.isTerminal())
+ if (edit.paneCursorLines(p.editor(), &shown.body)) |ls| ls.len else |_| std.math.maxInt(usize)
+ else
+ std.math.maxInt(usize);
+ if (pl.at.line > n) return missedLine(p, id, trimmed, pl.at.line);
+ };
+ // A miss changes nothing, the selection included; a look that stays in
+ // this pane starts from a clean one. One that goes to another pane
+ // leaves this one's dot alone, as acme's does: only the click's own
+ // highlight goes.
+ if (found == .pane and found.pane.id == id)
+ clearNavigationSelection(p, pane)
+ else if (found != .none) {
+ for (0..pane.sel.len) |slot| pane.clearPointerSelection(slot);
+ pane.sel = @splat(.{});
+ }
+ // The plumber, asked before Look's own look as acme asks it (look.c's
+ // look3): what is looked at, sent from this pane. A name already open
+ // in a pane is focused first, never sent; nor is a look that opens
+ // as text (look_text), or the edit port's open of what was. A message
+ // the rules give back to `edit` as sent is Look's own to open, on what
+ // it found; one nothing takes, Look's too.
+ const shown = switch (found) {
+ .pane => true,
+ .file => |f| openPaneTarget(p, f.path, f.at) != null,
+ .kind => |k| openPaneTarget(p, k.path, .{}) != null,
+ .none, .dir, .url => false,
+ };
+ if (!shown and !p.look_text) {
+ const msg: Plumb.Msg = .{
+ .src = if (pane.addon) |k| k.nameOf() else if (pane.body.mode == .tty and !p.fs.serving) "term" else "pardes",
+ .wdir = Pardes.paneDir(pane),
+ .type = "text",
+ .data = trimmed,
+ };
+ const seen: Plumb.Seen = .{ .name = pl.path, .found = switch (found) {
+ .file => |f| .{ .path = f.path },
+ .kind => |k| .{ .path = k.path },
+ .dir => |d| .{ .path = d, .dir = true },
+ .none, .url, .pane => null,
+ } };
+ switch (Plumb.send(p, id, msg, seen)) {
+ .done => return,
+ .look, .refused => {},
+ }
+ }
+ switch (found) {
+ .none => lookUnresolved(p, id, pane, trimmed, std.mem.trimEnd(u8, txt, "\r\n")),
+ .pane => |t| {
+ // `@p<serial>` names no open pane: one this session closed comes
+ // back where it was (Store.reopen), any other is a miss, said.
+ if (t.id >= MAX_PANES or p.panes[t.id] == null) {
+ if (@TypeOf(p.store).closedAddress(pl.path)) |serial| if (p.store.reopen(p, serial, id)) return;
+ return missed(p, id, "no pane {s}", .{pl.path[0..@min(pl.path.len, 32)]});
+ }
+ const target = p.panes[t.id].?;
+ // A kind's placeholder waiting for its file opens if it is here now.
+ if (target.addon) |k| if (!k.live) pardes.dump.reviveSlot(p, t.id, k);
+ // A place in a kind's pane is its `address`'s, a miss its to say.
+ if (target.addon != null and t.at.line > 0) {
+ var place: [41]u8 = undefined;
+ return lookKind(p, id, t.id, spotText(t.at, &place), false);
+ }
+ // A directory's pane, looked at again: read again.
+ if (target.file) |f| if (f.listing != null) return panes.Dir.show(p, id, t.id);
+ const before = v.active;
+ clearNavigationSelection(p, target);
+ focusPaneLine(p, t.id, t.at, .center);
+ settleLine(p, id, trimmed, t.at, before, null);
+ },
+ // acme's own look opens no URL: the plumber's web port does.
+ .url => lookUnresolved(p, id, pane, trimmed, std.mem.trimEnd(u8, txt, "\r\n")),
+ .dir => |dir| {
+ // A directory that is not there (the pane's own, gone): said,
+ // ENOENT, no terminal made in it.
+ if (filesystem.localPath(dir)) |local| if (exec.kindOf(local) != .directory) {
+ var said: Kind.Buf(4096 + 104) = .{};
+ return p.reportFailure(id, said.print("look: {s}: no such directory", .{dir[0..@min(dir.len, 4096)]}));
+ };
+ // acme's: a pane listing it (Dir.zig).
+ panes.Dir.look(p, id, dir);
+ },
+ .file => |target| {
+ // An open pane on this path too short for the line: a miss that
+ // touches nothing.
+ if (openPaneTarget(p, target.path, target.at)) |open| if (p.panes[open.pane.id].?.file) |*f|
+ if (target.at.line > panes.File.nlines(p.gpa, f))
+ return missedLine(p, id, target.path, target.at.line);
+ // focus an existing pane on this path (rescrolled), else open
+ const before = v.active;
+ var opened: ?usize = null;
+ 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 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;
+ layout.placeNew(p, id, id, free, .doc);
+ // Refused a place: that is the look's one failure, not a
+ // miss of its line too.
+ if (p.fs.failures != failures) return;
+ layout.compute(p);
+ nt.file.?.scroll -|= @max(1, v.rects[free].h -| BOX_H) / 2;
+ if (target.at.end_line != 0) {
+ const centered = nt.file.?.scroll;
+ selectSpan(p, nt, target.at);
+ nt.file.?.scroll = centered;
+ }
+ opened = free;
+ }
+ settleLine(p, id, target.path, target.at, before, opened);
+ },
+ .kind => |target| {
+ var place: [41]u8 = undefined;
+ // A row of a list a kind's pane made (a +PdfSections) is that
+ // pane's place, never another's of the same file: none once it
+ // is gone.
+ const from_list = if (p.panes[id]) |src| if (src.file) |f| if (f.output) |o| o.from == .kind else false else false else false;
+ if (from_list) {
+ for (p.panes, 0..) |slot, owner| if (slot) |op| if (op.search_pane == id) if (op.addon) |k| if (std.mem.eql(u8, k.path, target.path)) {
+ if (target.at.line > 0) return lookKind(p, id, owner, spotText(target.at, &place), false);
+ p.view().active = owner;
+ return;
+ };
+ return missed(p, id, "{s}: the pane its list is of is gone", .{target.path});
+ }
+ if (focusPaneByPath(p, target.path, .{})) {
+ if (target.at.line > 0) lookKind(p, id, v.active, spotText(target.at, &place), false);
+ return;
+ }
+ const free = p.freeSlot() orelse return p.reportError(id, "look", error.NoPaneSlots);
+ const made = Kind.openFile(p, free, target.kind, target.path) catch |err|
+ return lookOpenFailed(p, id, target.path, err);
+ // One its kind refuses (an image corrupt, truncated, not what
+ // its name says) is said, a failure, rather than shown blank.
+ if (made.addon.?.refused.len > 0) {
+ made.vweight = 0;
+ p.unplaced.set(free);
+ var said: Kind.Buf(miss_path_cap + 160) = .{};
+ var cut: [miss_path_cap + "…".len]u8 = undefined;
+ return p.reportFailure(id, said.print("look: {s}: {s}", .{ missText(target.path, &cut), made.addon.?.refused.slice() }));
+ }
+ layout.placeNew(p, id, id, free, .doc);
+ if (target.at.line > 0) lookKind(p, id, free, spotText(target.at, &place), true);
+ },
+ }
+}
+
+// A diff pane on `diff_text`, saved as change.diff in a fresh directory
+// that holds `files` (path, content) and, if `repo`, a `.git`.
+const DiffFixture = struct {
+ tmp: std.testing.TmpDir,
+ dir: []const u8,
+ dir_buf: [4096]u8 = undefined,
+
+ fn init(f: *DiffFixture, repo: bool, files: []const [2][]const u8, diff_text: []const u8) !void {
+ const io = std.testing.io;
+ f.tmp = std.testing.tmpDir(.{});
+ errdefer f.tmp.cleanup();
+ if (repo) try f.tmp.dir.createDir(io, ".git", .default_dir);
+ for (files) |file| {
+ if (std.Io.Dir.path.dirname(file[0])) |sub| try f.tmp.dir.createDirPath(io, sub);
+ try f.tmp.dir.writeFile(io, .{ .sub_path = file[0], .data = file[1] });
+ }
+ try f.tmp.dir.writeFile(io, .{ .sub_path = "change.diff", .data = diff_text });
+ const len = try f.tmp.dir.realPathFile(io, "change.diff", &f.dir_buf);
+ f.dir = std.Io.Dir.path.dirname(f.dir_buf[0..len]).?;
+ }
+
+ fn open(f: *DiffFixture, p: *Pardes, diff_text: []const u8) !*Pane {
+ const pane = try p.setTestFile(diff_text);
+ p.gpa.free(pane.file.?.path);
+ pane.file.?.path = try std.Io.Dir.path.join(p.gpa, &.{ f.dir, "change.diff" });
+ return pane;
+ }
+
+ /// A right click's look at `row` of the diff pane (slot 0): the look
+ /// of the address that line names.
+ fn click(p: *Pardes, diff_pane: *Pane, row: usize) void {
+ p.view().active = 0;
+ const lines = diffLines(p, diff_pane).?;
+ var buf: [4096]u8 = undefined;
+ p.look_missed = false;
+ lookAt(p, 0, diffAddress(diff_pane, lines, row, &buf).?);
+ }
+};
+
+/// The rows n/N's walk over look-able text reads before it stops (look.zig).
+pub const max_look_rows = 8192;
+
+fn expectAt(p: *Pardes, suffix: []const u8, line: usize) !void {
+ const pane = p.panes[p.view().active].?;
+ const f = pane.file orelse return error.NoFileOpened;
+ if (!std.mem.endsWith(u8, f.path, suffix)) {
+ std.debug.print("opened {s}, not {s}\n", .{ f.path, suffix });
+ return error.WrongFile;
+ }
+ try std.testing.expectEqual(@as(i32, @intCast(line)) - 1, pane.body.cur_row);
+}
+
+test "parsePathLine: spots, ranges, and the paths that merely look like them" {
+ const cases = [_]struct { tok: []const u8, path: []const u8, at: Spot }{
+ .{ .tok = "main.zig", .path = "main.zig", .at = .{} },
+ .{ .tok = "main.zig:100", .path = "main.zig", .at = .{ .line = 100 } },
+ .{ .tok = "main.zig:100:", .path = "main.zig", .at = .{ .line = 100 } },
+ .{ .tok = "main.zig:100:7", .path = "main.zig", .at = .{ .line = 100, .col = 7 } },
+ .{ .tok = "main.zig:100-104", .path = "main.zig", .at = .{ .line = 100, .end_line = 104 } },
+ .{ .tok = "main.zig:100:7-21", .path = "main.zig", .at = .{ .line = 100, .col = 7, .end_line = 100, .end_col = 21 } },
+ .{ .tok = "main.zig:100:7-104:3", .path = "main.zig", .at = .{ .line = 100, .col = 7, .end_line = 104, .end_col = 3 } },
+ .{ .tok = "my-file.zig", .path = "my-file.zig", .at = .{} },
+ .{ .tok = "my-file:10", .path = "my-file", .at = .{ .line = 10 } },
+ .{ .tok = "x:1-y", .path = "x:1-y", .at = .{} },
+ .{ .tok = "a-b-c", .path = "a-b-c", .at = .{} },
+ .{ .tok = "2026-07-30", .path = "2026-07-30", .at = .{} },
+ .{ .tok = "main.zig:100x", .path = "main.zig:100x", .at = .{} },
+ .{ .tok = "main.zig:100:7x", .path = "main.zig", .at = .{ .line = 100 } },
+ };
+ for (cases) |c| {
+ const got = parsePathLine(c.tok);
+ try std.testing.expectEqualStrings(c.path, got.path);
+ try std.testing.expectEqual(c.at, got.at);
+ }
+}
+
+test "a number too big to be a line saturates instead of taking the editor down" {
+ const huge = "99999999999999999999999999";
+ const cases = [_][]const u8{
+ "f.zig:" ++ huge,
+ "f.zig:" ++ huge ++ ":" ++ huge,
+ "f.zig:1-" ++ huge,
+ "f.zig:1:2-" ++ huge ++ ":" ++ huge,
+ };
+ for (cases) |tok| {
+ const got = parsePathLine(tok);
+ try std.testing.expectEqualStrings("f.zig", got.path);
+ try std.testing.expect(got.at.line >= 1);
+ }
+
+ var realbuf: [4096]u8 = undefined;
+ const target = resolve(null, "@p" ++ huge, "/tmp", &realbuf);
+ try std.testing.expect(target == .pane);
+ try std.testing.expect(target.pane.id >= 16);
+}
+
+test "parsePathLine: `end` separates a whole-token target from a lenient read" {
+ for ([_][]const u8{
+ "main.zig", "main.zig:100", "main.zig:100:7",
+ "main.zig:100-104", "main.zig:100:7-21", "main.zig:100:7-104:3",
+ "@p3:10:5", "x:1-y",
+ }) |tok| try std.testing.expectEqual(tok.len, parsePathLine(tok).end);
+ const partial = [_]struct { tok: []const u8, end: usize }{
+ .{ .tok = "main.zig:100:", .end = "main.zig:100".len }, // trailing ':' is peeled, not parsed
+ .{ .tok = "main.zig:100:7x", .end = "main.zig:100".len },
+ .{ .tok = "main.zig:100:7 fn main() void {", .end = "main.zig:100".len },
+ .{ .tok = "main.zig:100:7-21 const x = 1;", .end = "main.zig:100:7-21".len },
+ .{ .tok = "@p3:10:5 /home/goblin", .end = "@p3:10".len },
+ };
+ for (partial) |c| try std.testing.expectEqual(c.end, parsePathLine(c.tok).end);
+ const whole = "main.zig:100-104 whole lines";
+ try std.testing.expectEqual(whole.len, parsePathLine(whole).end);
+ try std.testing.expectEqualStrings(whole, parsePathLine(whole).path);
+}
+
+test "lookableSpan peels prose punctuation off a path, largest first" {
+ if (!platform_has_fs) return;
+ var realbuf: [4096]u8 = undefined;
+ try std.testing.expectEqualDeep(
+ @as(?Span, .{ .start = 0, .end = "core/look.zig".len }),
+ wordSpan(null, "core/look.zig", ".", &realbuf),
+ );
+ try std.testing.expectEqualDeep(
+ @as(?Span, .{ .start = 1, .end = 1 + "core/look.zig".len }),
+ wordSpan(null, "(core/look.zig),", ".", &realbuf),
+ );
+ try std.testing.expectEqualDeep(
+ @as(?Span, .{ .start = 0, .end = "core/look.zig:12:3".len }),
+ wordSpan(null, "core/look.zig:12:3,", ".", &realbuf),
+ );
+ try std.testing.expectEqualDeep(
+ @as(?Span, .{ .start = 0, .end = "core/look.zig:12".len }),
+ wordSpan(null, "core/look.zig:12:", ".", &realbuf),
+ );
+ try std.testing.expectEqual(@as(?Span, null), wordSpan(null, "nothing-here", ".", &realbuf));
+ try std.testing.expectEqual(@as(?Span, null), wordSpan(null, "", ".", &realbuf));
+ try std.testing.expectEqual(@as(?Span, null), wordSpan(null, "((()))", ".", &realbuf));
+}
+
+test "lookableLineSpan takes the row's location and stops before its text" {
+ if (!platform_has_fs) return;
+ var realbuf: [4096]u8 = undefined;
+ try std.testing.expectEqualDeep(
+ @as(?Span, .{ .start = 0, .end = "core/look.zig:12:5-9".len }),
+ lineSpan(null, "core/look.zig:12:5-9 const std = @import(\"std\");", ".", &realbuf),
+ );
+ try std.testing.expectEqualDeep(
+ @as(?Span, .{ .start = 0, .end = "core/look.zig:12:5".len }),
+ lineSpan(null, "core/look.zig:12:5 pub fn resolve", ".", &realbuf),
+ );
+ try std.testing.expectEqualDeep(
+ @as(?Span, .{ .start = 0, .end = "@p3:10:5".len }),
+ lineSpan(null, "@p3:10:5 /home/goblin", ".", &realbuf),
+ );
+ try std.testing.expectEqualDeep(
+ @as(?Span, .{ .start = 3, .end = 3 + "core/look.zig".len }),
+ lineSpan(null, " (core/look.zig)", ".", &realbuf),
+ );
+ try std.testing.expectEqualDeep(
+ @as(?Span, .{ .start = 0, .end = "https://pardes.dev/a".len }),
+ lineSpan(null, "https://pardes.dev/a Chapter One", ".", &realbuf),
+ );
+ try std.testing.expectEqual(
+ @as(?Span, null),
+ lineSpan(null, "see also core/look.zig", ".", &realbuf),
+ );
+ try std.testing.expectEqual(@as(?Span, null), lineSpan(null, " ", ".", &realbuf));
+ try std.testing.expectEqual(@as(?Span, null), lineSpan(null, "", ".", &realbuf));
+}
+
+test "lookableLineSpan prefers the longest run, so a blank inside a path is one span" {
+ if (!platform_has_fs) return;
+ var realbuf: [4096]u8 = undefined;
+ const io = std.testing.io;
+ var tmp = std.testing.tmpDir(.{});
+ defer tmp.cleanup();
+ const name = "pardes look span.txt";
+ try tmp.dir.writeFile(io, .{ .sub_path = name, .data = "" });
+ try tmp.dir.createDir(io, "subdir", .default_dir);
+ var path: [4096]u8 = undefined;
+ const len = try tmp.dir.realPathFile(io, name, &path);
+ const cwd = std.Io.Dir.path.dirname(path[0..len]).?;
+ try std.testing.expectEqualDeep(
+ @as(?Span, .{ .start = 0, .end = name.len }),
+ lineSpan(null, name, cwd, &realbuf),
+ );
+ try std.testing.expectEqualDeep(
+ @as(?Span, .{ .start = 0, .end = "subdir".len }),
+ lineSpan(null, "subdir holds pardes look span.txt", cwd, &realbuf),
+ );
+}
+
+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/" ++ std.mem.asBytes(&@as([80][5]u8, @splat("deep/".*))) ++ "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));
+}
+
+test "a zero column ends a look's text, line 0 included" {
+ for ([_][]const u8{ "f.txt:0:0", "f.txt:3:0", "dir/f.txt:3:2-0" }) |t| try std.testing.expect(zeroColumnTail(t));
+ for ([_][]const u8{ "f.txt:3", "f.txt:3:1", "f.txt:0", "f.txt", "a:b:0x" }) |t| try std.testing.expect(!zeroColumnTail(t));
+}
+
+test "a zero column after a path is found, in every spelling a look takes" {
+ for ([_][]const u8{ ":3:0", ":3:0-4", ":3:2-0", ":3:2-5:0" }) |rest| try std.testing.expect(zeroColumn(rest));
+ for ([_][]const u8{ "", ":3", ":3:1", ":3:2-5", ":3:2-5:7", ":30:10" }) |rest| try std.testing.expect(!zeroColumn(rest));
+}
+
+
+test "Look hover waits without mutating the pane and input cancels it" {
+ if (pardes.Term.ops == null) return error.SkipZigTest; // a shell
+ const delay = config.look_preview_delay_frames;
+
+ const gpa = std.testing.allocator;
+ const p = try Pardes.init(gpa, .{ .cols = 60, .rows = 12, .tty_only = true });
+ defer p.deinit();
+ while (p.nextEffect()) |_| {}
+ const pane = try p.setTestFile("alpha beta gamma\n");
+ pane.tag_expanded = false; // a one-row tag keeps this small screen's rows
+ p.sync();
+ while (p.nextEffect()) |_| {}
+ const other_id = p.freeSlot() orelse return error.NoSparePaneForHoverTest;
+ _ = try p.newShell(other_id, "");
+ p.panes[other_id].?.tag_expanded = false; // the blank spot right of the file is its body, not its tag
+ try std.testing.expect(layout.splitColumn(p, 0, other_id, false));
+ p.sync();
+ while (p.nextEffect()) |_| {}
+
+ var frame = std.heap.ArenaAllocator.init(gpa);
+ defer frame.deinit();
+ _ = try p.render(frame.allocator());
+ const rect = p.view().rects[p.view().active];
+ const word_x = rect.x + config.GUTTER + config.PREFIX_W + 7;
+ const body_y = rect.y + BOX_H;
+ const motion = Event{ .mouse = .{ .button = .none, .kind = .motion, .col = word_x, .row = body_y } };
+
+ const selections_before = pane.sel;
+ const active_before = p.view().active;
+ const cursor_before = .{ pane.body.cur_row, pane.body.cur_col };
+ const jumps_before = .{ p.view().jumps.n, p.view().jumps.cur, p.n_look_src };
+ const effects_before = p.effects_len;
+
+ p.update(motion);
+ try std.testing.expect(p.look_hover_wait != null);
+ try std.testing.expect(p.look_hover_preview == null);
+ try std.testing.expect(p.animationActive());
+
+ var ticks: u16 = 0;
+ while (ticks + 1 < delay) : (ticks += 1) {
+ p.update(.tick);
+ // Repeated motion reports for one cell are noise, not a fresh delay.
+ if (ticks == delay / 2) p.update(motion);
+ try std.testing.expect(p.look_hover_preview == null);
+ }
+ p.update(.tick);
+ const preview = p.look_hover_preview orelse return error.MissingLookHoverPreview;
+ const preview_sel = preview.sel orelse return error.MissingLookHoverSelection;
+ try std.testing.expectEqual(.done, preview_sel.state);
+ try std.testing.expectEqual(@as(i32, config.PREFIX_W + 6), preview_sel.c0);
+ try std.testing.expectEqual(@as(i32, config.PREFIX_W + 9), preview_sel.c1);
+ try std.testing.expect(!p.animationActive());
+
+ // Resolving and displaying the operand is observational only.
+ try std.testing.expect(std.meta.eql(selections_before, pane.sel));
+ try std.testing.expectEqual(active_before, p.view().active);
+ try std.testing.expectEqual(cursor_before, .{ pane.body.cur_row, pane.body.cur_col });
+ try std.testing.expectEqual(jumps_before, .{ p.view().jumps.n, p.view().jumps.cur, p.n_look_src });
+ try std.testing.expectEqual(effects_before, p.effects_len);
+
+ _ = frame.reset(.retain_capacity);
+ const surface = try p.render(frame.allocator());
+ const expected_bg = colors.mix(p.theme().bg orelse p.theme().tag_bg, colors.mix(p.theme().bg orelse p.theme().tag_bg, p.theme().sel_bg));
+ try std.testing.expectEqual(Color{ .rgb = expected_bg }, surface.at(word_x, body_y).style.bg);
+
+ // Background traffic in another pane does not change the text or geometry
+ // under this pointer and must not strand a stationary hover unarmed.
+ p.update(.{ .output = .{ .pane = @intCast(other_id), .bytes = "busy\r\n" } });
+ try std.testing.expect(p.look_hover_preview != null);
+
+ const seam_x = p.view().col_x[0] + p.view().col_w[0] - 1;
+ p.update(.{ .mouse = .{ .button = .none, .kind = .motion, .col = seam_x, .row = body_y } });
+ p.update(.pointer_leave);
+ try std.testing.expect(p.look_hover_wait == null);
+ try std.testing.expect(p.look_hover_preview == null);
+
+ const blank_x = rect.x + config.GUTTER + config.PREFIX_W + 30;
+ p.update(.{ .mouse = .{ .button = .none, .kind = .motion, .col = blank_x, .row = body_y } });
+ for (0..delay) |_| p.update(.tick);
+ try std.testing.expect(p.look_hover_wait == null);
+ try std.testing.expect(p.look_hover_preview == null);
+ try std.testing.expect(!p.animationActive());
+
+ // File PREFIX_W belongs only to body line numbers. A preview on the tag's
+ // first character must be paintable all the way at tag column zero — which
+ // is TAG_TEXT_INSET, not GUTTER: the grip keeps the gutter and the gap
+ // beside it separates the grip's hit area from the text.
+ const tag_y = rect.y;
+ p.look_hover_preview = .{
+ .col = rect.x + TAG_TEXT_INSET,
+ .row = tag_y,
+ .pane = p.view().active,
+ .serial = pane.serial,
+ .sel = .{ .state = .done, .c0 = 0, .c1 = 0, .r0 = 0, .r1 = 0 },
+ };
+ _ = frame.reset(.retain_capacity);
+ const tag_surface = try p.render(frame.allocator());
+ try std.testing.expectEqual(Color{ .rgb = expected_bg }, tag_surface.at(rect.x + TAG_TEXT_INSET, tag_y).style.bg);
+
+ p.look_hover_preview = null;
+ p.update(motion);
+ try std.testing.expect(p.look_hover_wait != null);
+ p.update(.{ .key = .{ .cp = Key.escape } });
+ try std.testing.expect(p.look_hover_wait == null);
+ try std.testing.expect(p.look_hover_preview == null);
+ // The following host repaint must not resurrect a hover after keyboard
+ // input cancelled its raw-pointer intent.
+ p.presented();
+ try std.testing.expect(p.look_hover_wait == null);
+}
+
+test "cwd changes cancel only the affected pane's Look hover" {
+ if (pardes.Term.ops == null) return error.SkipZigTest; // the classic boot's three shells
+ const gpa = std.testing.allocator;
+ const p = try Pardes.init(gpa, .{ .shells = 3 });
+ defer p.deinit();
+
+ const first = p.panes[0] orelse return error.MissingFirstPane;
+ const other = p.panes[1] orelse return error.MissingOtherPane;
+ p.setCwd(0, "/work/first");
+ p.setCwd(1, "/work/other");
+ p.look_hover_wait = .{ .col = 1, .row = 1, .pane = 0, .serial = first.serial };
+
+ // Hosts poll cwd every frame. An unchanged answer is observational and a
+ // change reported for another pane cannot invalidate this pane's operand.
+ p.setCwd(0, "/work/first");
+ try std.testing.expect(p.look_hover_wait != null);
+ p.setCwd(1, "/work/elsewhere");
+ try std.testing.expect(p.look_hover_wait != null);
+ try std.testing.expectEqual(other.serial, p.panes[1].?.serial);
+
+ p.setCwd(0, "/work/changed");
+ try std.testing.expect(p.look_hover_wait == null);
+ try std.testing.expect(p.look_hover_preview == null);
+}
+
+test "Look copies its operand before releasing pointer selection storage" {
+ const p = try Pardes.init(std.testing.allocator, .{ .cols = 60, .rows = 12 });
+ defer p.deinit();
+ const pane = try p.setTestFile("alpha beta\ngamma delta\nepsilon zeta\n");
+ const operand = try p.gpa.dupe(u8, "/test.txt:3:2");
+ pane.sel[0] = .{ .state = .done, .source_id = 1 };
+ pane.pointer_selections[0] = .{
+ .gesture = pane.sel[0],
+ .rows = try p.gpa.alloc(Pane.PointerRow, 0),
+ .raw_text = operand,
+ };
+ p.view().drag = .{ .select = .{ .id = 0, .button = config.select_button } };
+ lookAt(p, 0, operand);
+ try std.testing.expectEqual(@as(i32, 2), pane.body.cur_row);
+ try std.testing.expectEqual(@as(i32, 1), pane.body.cur_col);
+ try std.testing.expect(pane.pointer_selections[0] == null);
+ try std.testing.expectEqual(.none, pane.sel[0].state);
+ try std.testing.expectEqual(.none, p.view().drag);
+}
+
+test "@p names a pane by its serial, as /index does" {
+ const p = try Pardes.init(std.testing.allocator, .{ .cols = 60, .rows = 12 });
+ defer p.deinit();
+ const pane = try p.setTestFile("alpha\nbravo\n");
+ var realbuf: [4096]u8 = undefined;
+ var word: [32]u8 = undefined;
+ const target = resolve(p, try std.fmt.bufPrint(&word, config.pane_addr ++ "{d}:2", .{pane.serial}), "/", &realbuf);
+ try std.testing.expectEqual(p.paneBySerial(pane.serial).?, target.pane.id);
+}
+
+test "Look ignores missing and out of bounds pane addresses" {
+ const p = try Pardes.init(std.testing.allocator, .{ .cols = 60, .rows = 12 });
+ defer p.deinit();
+ const pane = try p.setTestFile("alpha\nbravo\n");
+ for ([_][]const u8{ config.pane_addr ++ "15:2", config.pane_addr ++ "999999:2" }) |operand| {
+ pane.body.setRange(pane.file.?.content, 0, .{ .anchor = 0, .head = 3 }, true);
+ lookAt(p, 0, operand);
+ try std.testing.expectEqual(@as(usize, 0), p.view().active);
+ try std.testing.expectEqual(@as(i32, 0), pane.body.cur_row);
+ try std.testing.expect(pane.body.vsel.active); // a miss changes nothing, the selection included
+ }
+}
+
+test "a pointer resting where a look-hover found nothing does not wake the core every frame" {
+ const p = try Pardes.init(std.testing.allocator, .{ .cols = 80, .rows = 24 });
+ defer p.deinit();
+ _ = try p.setTestFile(std.mem.asBytes(&@as([30][6]u8, @splat(" \n".*))));
+ p.sync();
+ const r = p.view().rects[p.view().active];
+ // Resting on blanks in the body: a wait, then nothing to open.
+ p.update(.{ .mouse = .{ .button = .none, .kind = .motion, .col = r.x + 20, .row = r.y + 5 } });
+ var frames: usize = 0;
+ while (p.nextWake() != null and frames < 20) : (frames += 1) {
+ p.update(.tick);
+ // What a shell's present does after every frame.
+ p.presented();
+ }
+ try std.testing.expect(frames < 20);
+ try std.testing.expect(p.look_hover_wait == null and p.look_hover_preview == null);
+}
+
+test "Look on each kind of diff line opens the new file at the line it names" {
+ if (!platform_has_fs) return;
+ const numbered = "line 1\nline 2\nline 3\nline 4\nline 5\nline 6\nline 7\nline 8\nline 9\n" ++
+ "line 10\nline 11\nline 12\nline 13\nline 14\nline 15\n";
+ const diff_text =
+ \\diff --git a/src/a.zig b/src/a.zig
+ \\index 1111111..2222222 100644
+ \\--- a/src/a.zig
+ \\+++ b/src/a.zig
+ \\@@ -10,3 +10,4 @@ fn x() void {
+ \\ line 10
+ \\-Del
+ \\+line 11
+ \\+line 12
+ \\ line 13
+ \\
+ ;
+ var fx: DiffFixture = undefined;
+ try fx.init(true, &.{.{ "src/a.zig", numbered }}, diff_text);
+ defer fx.tmp.cleanup();
+ const p = try Pardes.init(std.testing.allocator, .{ .cols = 100, .rows = 30 });
+ defer p.deinit();
+ const pane = try fx.open(p, diff_text);
+
+ DiffFixture.click(p, pane, 4); // @@: the hunk's first new line
+ try expectAt(p, "/src/a.zig", 10);
+ DiffFixture.click(p, pane, 5); // a context line
+ try expectAt(p, "/src/a.zig", 10);
+ // A removed line (whose text is a builtin: no Del runs) opens the new
+ // line now standing where it was.
+ DiffFixture.click(p, pane, 6);
+ try expectAt(p, "/src/a.zig", 11);
+ try std.testing.expect(p.panes[0] != null);
+ DiffFixture.click(p, pane, 7); // added lines
+ try expectAt(p, "/src/a.zig", 11);
+ DiffFixture.click(p, pane, 8);
+ try expectAt(p, "/src/a.zig", 12);
+ DiffFixture.click(p, pane, 9);
+ try expectAt(p, "/src/a.zig", 13);
+ DiffFixture.click(p, pane, 3); // +++ b/path: the file, a/ b/ dropped
+ try std.testing.expect(std.mem.endsWith(u8, p.panes[p.view().active].?.file.?.path, "/src/a.zig"));
+ DiffFixture.click(p, pane, 2); // --- a/path
+ try std.testing.expect(std.mem.endsWith(u8, p.panes[p.view().active].?.file.?.path, "/src/a.zig"));
+ try std.testing.expect(!p.look_missed);
+
+ // No click: a 9P look writes a whole line, found from the cursor on.
+ p.view().active = 0;
+ pane.body.cur_row = 0;
+ lookAt(p, 0, "+line 12");
+ try expectAt(p, "/src/a.zig", 12);
+ // A word on a hunk line is a word, looked for in the diff as ever.
+ p.view().active = 0;
+ pane.body.cur_row = 9;
+ lookAt(p, 0, "line");
+ try std.testing.expectEqual(@as(usize, 0), p.view().active);
+ // A line that is no part of a hunk is looked at as ever.
+ p.view().active = 0;
+ pane.body.cur_row = 1;
+ lookAt(p, 0, "1111111");
+ try std.testing.expectEqual(@as(usize, 0), p.view().active);
+}
+
+test "Look on plain diff -u output: names as written, timestamps cut, next to the diff" {
+ if (!platform_has_fs) return;
+ const diff_text = "--- old/x.zig\t2026-09-30 10:00:00.000000000 +0000\n" ++
+ "+++ new/x.zig\t2026-09-30 11:00:00.000000000 +0000\n" ++
+ "@@ -1,2 +1,3 @@\n" ++
+ " const a = 1;\n" ++
+ "+const b = 2;\n" ++
+ " const c = 3;\n";
+ var fx: DiffFixture = undefined;
+ try fx.init(false, &.{.{ "new/x.zig", "const a = 1;\nconst b = 2;\nconst c = 3;\n" }}, diff_text);
+ defer fx.tmp.cleanup();
+ const p = try Pardes.init(std.testing.allocator, .{ .cols = 100, .rows = 30 });
+ defer p.deinit();
+ const pane = try fx.open(p, diff_text);
+ DiffFixture.click(p, pane, 4);
+ try expectAt(p, "/new/x.zig", 2);
+ DiffFixture.click(p, pane, 5);
+ try expectAt(p, "/new/x.zig", 3);
+}
+
+test "Look on a diff: headers and a hunk line's prefix are the whole line, hover and click alike" {
+ if (!platform_has_fs) return;
+ const numbered = "one\ntwo\nthree\nfour\nfive\nsix\n";
+ const diff_text =
+ \\diff --git a/src/old.zig b/src/new.zig
+ \\similarity index 80%
+ \\rename from src/old.zig
+ \\rename to src/new.zig
+ \\--- a/src/old.zig
+ \\+++ b/src/new.zig
+ \\@@ -2,2 +2,2 @@ fn x() void {
+ \\ two
+ \\-drei
+ \\+three
+ \\
+ ;
+ var fx: DiffFixture = undefined;
+ try fx.init(true, &.{.{ "src/new.zig", numbered }}, diff_text);
+ defer fx.tmp.cleanup();
+ const p = try Pardes.init(std.testing.allocator, .{ .cols = 100, .rows = 30 });
+ defer p.deinit();
+ const pane = try fx.open(p, diff_text);
+ pane.tag_expanded = false;
+ // `word`: what the pointer there expands to when it is not the whole
+ // line; `line` 0: that word is looked at in the diff, nothing opened.
+ const Point = struct { row: u16, col: u16, line: usize, word: ?[]const u8 = null, addr: []const u8 = "" };
+ const points = [_]Point{
+ .{ .row = 0, .col = 0, .line = 1, .addr = "src/new.zig" }, // `diff`: the new side
+ .{ .row = 0, .col = 35, .line = 1, .addr = "src/new.zig" }, // on b/src/new.zig
+ .{ .row = 4, .col = 1, .line = 1, .addr = "src/new.zig" }, // `---`: renamed, so the new name
+ .{ .row = 4, .col = 5, .line = 1, .addr = "src/new.zig" }, // the `a/` of the old name
+ .{ .row = 5, .col = 0, .line = 1, .addr = "src/new.zig" }, // `+++`
+ .{ .row = 5, .col = 4, .line = 1, .addr = "src/new.zig" }, // its `b/`
+ .{ .row = 5, .col = 10, .line = 1, .addr = "src/new.zig" }, // its path
+ .{ .row = 6, .col = 0, .line = 2, .addr = "src/new.zig:2" }, // the first `@@`
+ .{ .row = 6, .col = 9, .line = 2, .addr = "src/new.zig:2" }, // `+2,2`
+ .{ .row = 6, .col = 13, .line = 2, .addr = "src/new.zig:2" }, // the second `@@`
+ .{ .row = 6, .col = 20, .line = 2, .addr = "src/new.zig:2" }, // the function after it
+ .{ .row = 7, .col = 0, .line = 2, .addr = "src/new.zig:2" }, // a context line's ` `
+ .{ .row = 8, .col = 0, .line = 3, .addr = "src/new.zig:3" }, // a removed line's `-`: where it was
+ .{ .row = 9, .col = 0, .line = 3, .addr = "src/new.zig:3" }, // an added line's `+`
+ .{ .row = 9, .col = 3, .line = 0, .word = "three" }, // its code: a word
+ .{ .row = 7, .col = 2, .line = 0, .word = "two" },
+ };
+ var frame = std.heap.ArenaAllocator.init(std.testing.allocator);
+ defer frame.deinit();
+ for (points) |at| {
+ // Back to the diff, scrolled to its top again.
+ p.view().active = 0;
+ pane.file.?.scroll = 0;
+ p.sync();
+ _ = frame.reset(.retain_capacity);
+ _ = try p.render(frame.allocator());
+ const rect = p.view().rects[0];
+ const x = rect.x + config.GUTTER + panes.File.gutterWidth(pane) + at.col;
+ const y = p.bodyTop(pane, rect) + at.row;
+ // The hover's span is the click's operand.
+ const pointed = edit.pointerTextSelection(p, 0, x, y, null, null) orelse return error.NothingPointed;
+ const operand = exec.operandAt(p, pane, pointed.sel, true, true);
+ const lines = diffLines(p, pane).?; // scratch: good until the next update
+ const span = operand.file_word orelse return error.NoHoverSpan;
+ try std.testing.expectEqual(@as(i32, at.row), span.row);
+ if (at.word) |word| {
+ try std.testing.expectEqualStrings(word, operand.text.?);
+ try std.testing.expectEqualStrings(word, lines[at.row][@intCast(span.lo)..@intCast(span.hi)]);
+ } else {
+ // The hover shows the line; the look is of the address it names.
+ try std.testing.expectEqualStrings(at.addr, operand.text.?);
+ try std.testing.expectEqual(@as(i32, 0), span.lo);
+ try std.testing.expectEqual(@as(i32, @intCast(lines[at.row].len)), span.hi);
+ }
+ p.look_missed = false;
+ p.update(.{ .mouse = .{ .button = config.look_button, .kind = .press, .col = x, .row = y } });
+ p.update(.{ .mouse = .{ .button = config.look_button, .kind = .release, .col = x, .row = y } });
+ if (at.line == 0) {
+ try std.testing.expectEqual(@as(usize, 0), p.view().active);
+ continue;
+ }
+ try std.testing.expect(!p.look_missed);
+ if (p.view().active == 0) {
+ std.debug.print("a look at row {d} col {d} stayed in the diff\n", .{ at.row, at.col });
+ return error.LookStayed;
+ }
+ try expectAt(p, "/src/new.zig", at.line);
+ }
+}
+
+test "a click, a 9P whole-line look and an empty event write-back take one expansion on every kind of diff line, a blank context line too" {
+ if (!platform_has_fs) return;
+ const diff_text =
+ \\diff --git a/src/new.zig b/src/new.zig
+ \\--- a/src/new.zig
+ \\+++ b/src/new.zig
+ \\@@ -2,3 +2,3 @@ fn x() void {
+ \\ two
+ \\-drei
+ \\+three
+ \\
+ \\
+ ;
+ var fx: DiffFixture = undefined;
+ try fx.init(true, &.{.{ "src/new.zig", "one\ntwo\nthree\n\nfive\n" }}, diff_text);
+ defer fx.tmp.cleanup();
+ const p = try Pardes.init(std.testing.allocator, .{ .cols = 100, .rows = 30 });
+ defer p.deinit();
+ const pane = try fx.open(p, diff_text);
+ pane.tag_expanded = false;
+ const Point = struct { row: u16, col: u16, want: []const u8, whole_line: bool = true };
+ const points = [_]Point{
+ .{ .row = 0, .col = 0, .want = "src/new.zig" }, // diff --git
+ .{ .row = 1, .col = 0, .want = "src/new.zig" }, // ---
+ .{ .row = 2, .col = 0, .want = "src/new.zig" }, // +++
+ .{ .row = 3, .col = 0, .want = "src/new.zig:2" }, // @@
+ .{ .row = 4, .col = 0, .want = "src/new.zig:2" }, // a context line's ` `
+ .{ .row = 5, .col = 0, .want = "src/new.zig:3" }, // `-`
+ .{ .row = 6, .col = 0, .want = "src/new.zig:3" }, // `+`
+ .{ .row = 7, .col = 0, .want = "src/new.zig:4" }, // a blank context line
+ .{ .row = 6, .col = 3, .want = "three", .whole_line = false }, // code: a word
+ };
+ var frame = std.heap.ArenaAllocator.init(std.testing.allocator);
+ defer frame.deinit();
+ for (points) |at| {
+ p.view().active = 0;
+ pane.file.?.scroll = 0;
+ pane.body.cur_row = 0;
+ p.sync();
+ _ = frame.reset(.retain_capacity);
+ _ = try p.render(frame.allocator());
+ // The mouse's.
+ const rect = p.view().rects[0];
+ const x = rect.x + config.GUTTER + panes.File.gutterWidth(pane) + at.col;
+ const y = p.bodyTop(pane, rect) + at.row;
+ const pointed = edit.pointerTextSelection(p, 0, x, y, null, null) orelse return error.NothingPointed;
+ const clicked = exec.operandAt(p, pane, pointed.sel, true, true).text orelse return error.NothingClicked;
+ try std.testing.expectEqualStrings(at.want, clicked);
+ // An empty record written back to event, at the same byte.
+ const body = pane.file.?.content;
+ const line_start = modal.lineStartOffset(body, at.row);
+ const written = pardes.ctlfs.events.expandAt(p, pane, body, line_start + at.col, true, true);
+ try std.testing.expectEqualStrings(at.want, written);
+ // A 9P look of the whole line.
+ if (at.whole_line) {
+ const lines = diffLines(p, pane).?;
+ var buf: [4096 + 32]u8 = undefined;
+ const whole = lineAddress(p, pane, lines[at.row], &buf) orelse return error.NoWholeLineAddress;
+ try std.testing.expectEqualStrings(at.want, whole);
+ }
+ }
+}
+
+test "every entry point to Look takes one expansion: a diff line and a file:12:5: line land in one place by each" {
+ if (!platform_has_fs) return;
+ const numbered = "l1\nl2\nl3\nl4\nl5\nl6\nl7\nl8\nl9\nl10\nl11\nline 12 here\nl13\n";
+ const diff_text =
+ \\diff --git a/src/x.zig b/src/x.zig
+ \\--- a/src/x.zig
+ \\+++ b/src/x.zig
+ \\@@ -11,2 +11,3 @@
+ \\ l11
+ \\-old
+ \\+line 12 here
+ \\
+ ;
+ const log_text = "src/x.zig:12:5: error: bad\n";
+ var fx: DiffFixture = undefined;
+ try fx.init(true, &.{.{ "src/x.zig", numbered }}, diff_text);
+ defer fx.tmp.cleanup();
+ const th = @import("ninep/testing.zig");
+ // `column` -1: wherever a click puts it, every other way the same.
+ const Case = struct { text: []const u8, name: []const u8, row: u16, col: u16, sweep: [2]u16, line: i32, column: i32 };
+ const cases = [_]Case{
+ // `+line 12 here` pointed at on its `+`: the hunk's new line 12.
+ .{ .text = diff_text, .name = "change.diff", .row = 6, .col = 0, .sweep = .{ 0, 12 }, .line = 11, .column = -1 },
+ // A compiler's place, its trailing `:` dropped: line 12, column 5.
+ .{ .text = log_text, .name = "build.log", .row = 0, .col = 2, .sweep = .{ 0, 14 }, .line = 11, .column = 4 },
+ };
+ for (cases) |case| {
+ const p = try Pardes.init(std.testing.allocator, .{ .cols = 100, .rows = 30 });
+ defer p.deinit();
+ const pane = try fx.open(p, case.text);
+ p.gpa.free(pane.file.?.path);
+ pane.file.?.path = try std.Io.Dir.path.join(p.gpa, &.{ fx.dir, case.name });
+ pane.tag_expanded = false;
+ var frame = std.heap.ArenaAllocator.init(std.testing.allocator);
+ defer frame.deinit();
+ const Entry = enum { click, sweep, enter, bare_look, look_file, event_write_back };
+ var column = case.column;
+ for (std.enums.values(Entry)) |entry| {
+ // From the pane, its cursor on the place, nothing selected,
+ // the target (once open) moved off it.
+ for (p.panes[1..]) |slot| if (slot) |other| {
+ other.body.cur_row = 0;
+ other.body.cur_col = 0;
+ };
+ p.view().active = 0;
+ pane.body.mode = .normal;
+ pane.body.vsel.active = false;
+ pane.body.cur_row = case.row;
+ pane.body.cur_col = case.col;
+ pane.body.cur_pinned = true;
+ pane.file.?.scroll = 0;
+ p.sync();
+ _ = frame.reset(.retain_capacity);
+ _ = try p.render(frame.allocator());
+ const rect = p.view().rects[0];
+ const x0 = rect.x + config.GUTTER + panes.File.gutterWidth(pane);
+ const y = p.bodyTop(pane, rect) + case.row;
+ switch (entry) {
+ .click => {
+ p.update(.{ .mouse = .{ .button = .right, .kind = .press, .col = x0 + case.col, .row = y } });
+ p.update(.{ .mouse = .{ .button = .right, .kind = .release, .col = x0 + case.col, .row = y } });
+ },
+ .sweep => {
+ p.update(.{ .mouse = .{ .button = .right, .kind = .press, .col = x0 + case.sweep[0], .row = y } });
+ p.update(.{ .mouse = .{ .button = .right, .kind = .drag, .col = x0 + case.sweep[1], .row = y } });
+ p.update(.{ .mouse = .{ .button = .right, .kind = .release, .col = x0 + case.sweep[1], .row = y } });
+ },
+ .enter => p.update(.{ .key = .{ .cp = Key.enter } }),
+ .bare_look => _ = p.executeBuiltinLine(0, "Look"),
+ .look_file => {
+ const line = modal.lineSlice(case.text, case.row);
+ // A diff line written whole; a place, as a script writes it.
+ const written = if (std.mem.eql(u8, case.name, "change.diff")) line else line[case.sweep[0] .. case.sweep[1] + 1];
+ _ = th.wr(p, @backingInt(pardes.ctlfs.TopFile.look), written);
+ },
+ .event_write_back => {
+ const body = pane.file.?.content;
+ const text = pardes.ctlfs.events.expandAt(p, pane, body, modal.lineStartOffset(body, case.row) + case.col, true, true);
+ lookAt(p, 0, p.scratch.allocator().dupe(u8, text) catch unreachable);
+ },
+ }
+ const landed = p.panes[p.view().active].?;
+ const f = landed.file orelse return error.NothingOpened;
+ if (column < 0) column = landed.body.cur_col;
+ if (!std.mem.endsWith(u8, f.path, "/src/x.zig") or landed.body.cur_row != case.line or landed.body.cur_col != column) {
+ std.debug.print("{s} by {s}: at {s} {d}:{d}\n", .{ case.name, @tagName(entry), f.path, landed.body.cur_row, landed.body.cur_col });
+ return error.EntryPointsDiffer;
+ }
+ }
+ }
+}
+
+test "a tag word looked at by a click and by Enter is one record to an event reader; an exec on a diff line takes its word, never the address" {
+ if (!platform_has_fs) return;
+ const diff_text =
+ \\diff --git a/src/x.zig b/src/x.zig
+ \\--- a/src/x.zig
+ \\+++ b/src/x.zig
+ \\@@ -1,1 +1,1 @@
+ \\-old
+ \\+line one
+ \\
+ ;
+ var fx: DiffFixture = undefined;
+ try fx.init(true, &.{.{ "src/x.zig", "line one\n" }}, diff_text);
+ defer fx.tmp.cleanup();
+ const th = @import("ninep/testing.zig");
+ const p = try Pardes.init(std.testing.allocator, .{ .cols = 100, .rows = 30 });
+ defer p.deinit();
+ const pane = try fx.open(p, diff_text);
+ pane.tag_expanded = true;
+ var frame = std.heap.ArenaAllocator.init(std.testing.allocator);
+ defer frame.deinit();
+ p.sync();
+ _ = try p.render(frame.allocator());
+
+ // An exec on the `+` of a hunk line takes the word there; a look, the
+ // address the line names.
+ pane.body.cur_row = 5;
+ pane.body.cur_col = 0;
+ try std.testing.expectEqualStrings("+line", exec.operandAt(p, pane, cursorWordSel(p, pane), false, false).text.?);
+ try std.testing.expectEqualStrings("src/x.zig:1", exec.operandAt(p, pane, cursorWordSel(p, pane), false, true).text.?);
+ // An exec written back to event (`MX0 0`) takes the word too, on a
+ // header, a hunk header and a marker column; a look, the address.
+ const body = pane.file.?.content;
+ const events = pardes.ctlfs.events;
+ try std.testing.expectEqualStrings("diff", events.expandAt(p, pane, body, 0, true, false));
+ try std.testing.expectEqualStrings("@@", events.expandAt(p, pane, body, modal.lineStartOffset(body, 3), true, false));
+ try std.testing.expectEqualStrings("+line", events.expandAt(p, pane, body, modal.lineStartOffset(body, 5), true, false));
+ try std.testing.expectEqualStrings("src/x.zig", events.expandAt(p, pane, body, 0, true, true));
+ try std.testing.expectEqualStrings("src/x.zig:1", events.expandAt(p, pane, body, modal.lineStartOffset(body, 5), true, true));
+
+ // An event reader on the pane.
+ const event = pardes.ctlfs.Node.of(pane.serial, .event);
+ const opened = th.call(p, .{ .tag = 1, .op = .open, .node = event });
+ defer _ = th.call(p, .{ .tag = 9, .op = .release, .node = event, .handle = opened.reply.handle });
+ const tag = try tagline.tagText(p, p.scratch.allocator(), pane);
+ const at: u16 = @intCast(std.mem.lastIndexOf(u8, tag, "Del").?);
+ // A B3 click on the tag's Del, where the tag as shown has it...
+ const shown = (try tagline.shownTag(p, p.scratch.allocator(), pane)).text;
+ const shown_at = std.mem.lastIndexOf(u8, shown, "Del").?;
+ const shown_row: u16 = @intCast(std.mem.count(u8, shown[0..shown_at], "\n"));
+ const line_start = if (std.mem.lastIndexOfScalar(u8, shown[0..shown_at], '\n')) |nl| nl + 1 else 0;
+ const x = p.view().rects[0].x + TAG_TEXT_INSET + @as(u16, @intCast(panes.File.displayWidth(shown[line_start..shown_at]))) + 1;
+ const y = p.view().rects[0].y + shown_row;
+ p.update(.{ .mouse = .{ .button = .right, .kind = .press, .col = x, .row = y } });
+ p.update(.{ .mouse = .{ .button = .right, .kind = .release, .col = x, .row = y } });
+ var clicked_buf: [128]u8 = undefined;
+ const clicked = th.rd(p, event, 0, 4096).bytes;
+ @memcpy(clicked_buf[0..clicked.len], clicked);
+ // ...and Enter with the tag's cursor on it.
+ tagline.enterTag(p, pane);
+ pane.tag.mode = .normal;
+ pane.tag.cur_row = 0;
+ pane.tag.cur_col = at + 1;
+ p.update(.{ .key = .{ .cp = Key.enter } });
+ const keyed = th.rd(p, event, 0, 4096).bytes;
+ // The same record but for its origin, mouse or keyboard.
+ try std.testing.expect(clicked.len > 2);
+ try std.testing.expectEqualStrings(clicked_buf[1..clicked.len], keyed[1..]);
+ try std.testing.expect(p.panes[0] != null);
+}
+
+test "Incl's directories find a name found nowhere else, <name> too; bare Incl lists them, Incl - empties them, and a dump keeps them" {
+ if (!platform_has_fs) return;
+ var tmp = std.testing.tmpDir(.{});
+ defer tmp.cleanup();
+ try tmp.dir.createDirPath(std.testing.io, "inc");
+ try tmp.dir.createDirPath(std.testing.io, "src");
+ try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "inc/pardes_incl_probe.h", .data = "#define X 1\n" });
+ var dir_buf: [4096]u8 = undefined;
+ const root = dir_buf[0..try tmp.dir.realPath(std.testing.io, &dir_buf)];
+ const p = try Pardes.init(std.testing.allocator, .{ .cols = 100, .rows = 30 });
+ defer p.deinit();
+ // C's two by default.
+ try std.testing.expectEqualStrings("/usr/include", p.incl.items[0]);
+ const pane = try p.setTestFile("#include <pardes_incl_probe.h>\n");
+ p.gpa.free(pane.file.?.path);
+ pane.file.?.path = try std.Io.Dir.path.join(p.gpa, &.{ root, "src", "main.c" });
+ var line: [4200]u8 = undefined;
+ try std.testing.expect(p.executeBuiltinLine(0, try std.fmt.bufPrint(&line, "Incl {s}/inc", .{root})));
+ for ([_][]const u8{ "pardes_incl_probe.h", "<pardes_incl_probe.h>" }) |word| {
+ p.view().active = 0;
+ p.look_missed = false;
+ lookAt(p, 0, word);
+ try std.testing.expect(!p.look_missed);
+ try std.testing.expect(std.mem.endsWith(u8, p.panes[p.view().active].?.file.?.path, "/inc/pardes_incl_probe.h"));
+ }
+ // Bare, it lists them.
+ try std.testing.expect(p.executeBuiltinLine(0, "Incl"));
+ try std.testing.expect(std.mem.indexOf(u8, pane.msg[0..pane.msg_len], "/inc") != null);
+ // A dump keeps them.
+ try pardes.dump.dumpState(p);
+ const restored = try pardes.dump.restore(p, p.dump_out.?, "/tmp/pardes.dump.zon");
+ defer restored.deinit();
+ try std.testing.expectEqual(p.incl.items.len, restored.incl.items.len);
+ try std.testing.expect(std.mem.endsWith(u8, restored.incl.items[restored.incl.items.len - 1], "/inc"));
+ // Emptied, the name is found nowhere.
+ try std.testing.expect(p.executeBuiltinLine(0, "Incl -"));
+ try std.testing.expectEqual(@as(usize, 0), p.incl.items.len);
+}
+
+test "LookNext in a command pane walks its own file:line places, whoever walked last" {
+ if (pardes.Term.ops == null) return error.SkipZigTest; // a command pane
+ if (!platform_has_fs) return;
+ var tmp = std.testing.tmpDir(.{});
+ defer tmp.cleanup();
+ try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "x.c", .data = "a\nb\nc\n" });
+ try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "y.c", .data = "a\nb\n" });
+ var dir_buf: [4096]u8 = undefined;
+ const dir = dir_buf[0..try tmp.dir.realPath(std.testing.io, &dir_buf)];
+ const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 100, .rows = 30 });
+ defer p.deinit();
+ const doc = try p.setTestFile("x\n");
+ p.gpa.free(doc.file.?.path);
+ doc.file.?.path = try std.Io.Dir.path.join(p.gpa, &.{ dir, "main.c" });
+ while (p.nextEffect()) |_| {}
+ const dst = exec.execute(p, 0, "make") orelse return error.NoCommandPane;
+ while (p.nextEffect()) |_| {}
+ p.update(.{ .output = .{ .pane = @intCast(dst), .bytes = "x.c:3:1: error: bad\r\ny.c:2:1: warning: odd\r\n" } });
+ p.update(.{ .exited = .{ .pane = @intCast(dst), .status = 2 } });
+ p.update(.{ .eof = .{ .pane = @intCast(dst) } });
+ const cmd = p.panes[dst].?;
+ // A walk last made elsewhere, and another pane with places in it.
+ try std.testing.expect(p.executeBuiltinLine(0, "New"));
+ const scratch = p.panes[p.view().active].?;
+ _ = pardes.ctlfs.pane.spliceBody(p, scratch, 0, 0, "x.c:1:1 elsewhere\n") orelse return error.NoScratch;
+ p.look_walk_owner = scratch.serial;
+ p.view().active = dst;
+ cmd.focus = .body;
+ cmd.body.mode = .normal;
+ for ([_]u21{ 'g', 'g' }) |cp| p.update(.{ .key = .{ .cp = cp } });
+ exec.runBuiltin(p, .LookNext, p.view().active, "", null);
+ try std.testing.expectEqual(dst, p.view().active);
+ const first = cmd.look_at orelse return error.NoSpot;
+ const lines = try edit.paneCursorLines(p.editor(), &cmd.body);
+ try std.testing.expect(std.mem.startsWith(u8, lines[@intCast(first.row)][@intCast(first.col0)..], "x.c:3:1"));
+ exec.runBuiltin(p, .LookNext, p.view().active, "", null);
+ try std.testing.expectEqual(dst, p.view().active);
+ const second = cmd.look_at orelse return error.NoSpot;
+ try std.testing.expect(std.mem.startsWith(u8, lines[@intCast(second.row)][@intCast(second.col0)..], "y.c:2:1"));
+}
+
+test "Look outside a diff pane expands and looks as ever" {
+ const p = try Pardes.init(std.testing.allocator, .{ .cols = 100, .rows = 30 });
+ defer p.deinit();
+ const pane = try p.setTestFile("+++ b/x.zig\n@@ -1 +1 @@\n+const a = 1;\n");
+ pane.tag_expanded = false;
+ try std.testing.expect(diffLines(p, pane) == null);
+ p.sync();
+ var frame = std.heap.ArenaAllocator.init(std.testing.allocator);
+ defer frame.deinit();
+ _ = try p.render(frame.allocator());
+ const rect = p.view().rects[0];
+ const x = rect.x + config.GUTTER + panes.File.gutterWidth(pane) + 0;
+ const pointed = edit.pointerTextSelection(p, 0, x, p.bodyTop(pane, rect) + 2, null, null).?;
+ const operand = exec.operandAt(p, pane, pointed.sel, true, true);
+ try std.testing.expect(operand.text == null or !std.mem.eql(u8, operand.text.?, "+const a = 1;"));
+}
+
+test "Look on a diff under each git prefix opens the repository's file, and a real a/ directory under --no-prefix" {
+ if (!platform_has_fs) return;
+ const Case = struct { text: []const u8, file: []const u8 };
+ const cases = [_]Case{
+ .{ .text = "diff --git a/src/x.zig b/src/x.zig\n--- a/src/x.zig\n+++ b/src/x.zig\n@@ -1,2 +1,2 @@\n-one\n+uno\n two\n", .file = "/src/x.zig" },
+ .{ .text = "diff --git c/src/x.zig w/src/x.zig\n--- c/src/x.zig\n+++ w/src/x.zig\n@@ -1,2 +1,2 @@\n-one\n+uno\n two\n", .file = "/src/x.zig" },
+ .{ .text = "diff --git i/src/x.zig w/src/x.zig\n--- i/src/x.zig\n+++ w/src/x.zig\n@@ -1,2 +1,2 @@\n-one\n+uno\n two\n", .file = "/src/x.zig" },
+ // --no-prefix: `a/x.zig` is the file x.zig in the directory a, and
+ // a `x.zig` at the top is never taken for it.
+ .{ .text = "diff --git a/x.zig a/x.zig\n--- a/x.zig\n+++ a/x.zig\n@@ -1,2 +1,2 @@\n-one\n+uno\n two\n", .file = "/a/x.zig" },
+ };
+ for (cases) |c| {
+ var fx: DiffFixture = undefined;
+ try fx.init(true, &.{ .{ "src/x.zig", "uno\ntwo\n" }, .{ "a/x.zig", "uno\ntwo\n" }, .{ "x.zig", "top\n" } }, c.text);
+ defer fx.tmp.cleanup();
+ const p = try Pardes.init(std.testing.allocator, .{ .cols = 100, .rows = 30 });
+ defer p.deinit();
+ const pane = try fx.open(p, c.text);
+ DiffFixture.click(p, pane, 6); // `two`, a context line: new line 2
+ try std.testing.expect(!p.look_missed);
+ try expectAt(p, c.file, 2);
+ DiffFixture.click(p, pane, 1); // `---`
+ try std.testing.expect(!p.look_missed);
+ try std.testing.expect(std.mem.endsWith(u8, p.panes[p.view().active].?.file.?.path, c.file));
+ }
+}
+
+test "Look on a diff line is the look of the address it names, selected by hand: a cached patch, the checkout elsewhere" {
+ if (!platform_has_fs) return;
+ const io = std.testing.io;
+ const patch = "diff --git a/entry/src/entry.rs b/entry/src/entry.rs\n--- a/entry/src/entry.rs\n+++ b/entry/src/entry.rs\n" ++
+ "@@ -1,2 +1,2 @@\n-fn old() {}\n+fn new() {}\n fn kept() {}\n";
+ // The review tool's cache, with no checkout in it.
+ var cache: DiffFixture = undefined;
+ try cache.init(false, &.{}, patch);
+ defer cache.tmp.cleanup();
+ // The checkout, elsewhere, with a file of it open in the session.
+ var checkout = std.testing.tmpDir(.{});
+ defer checkout.cleanup();
+ try checkout.dir.createDir(io, ".git", .default_dir);
+ try checkout.dir.createDirPath(io, "entry/src");
+ try checkout.dir.writeFile(io, .{ .sub_path = "entry/src/entry.rs", .data = "fn new() {}\nfn kept() {}\n" });
+ try checkout.dir.writeFile(io, .{ .sub_path = "Cargo.toml", .data = "[workspace]\n" });
+ var path_buf: [4096]u8 = undefined;
+ const cargo = path_buf[0..try checkout.dir.realPathFile(io, "Cargo.toml", &path_buf)];
+
+ const Seen = struct { active_path: []u8, row: i32, missed: bool, msg: []u8, panes: usize };
+ var seen: [2]Seen = undefined;
+ for (0..2) |way| {
+ const p = try Pardes.init(std.testing.allocator, .{ .cols = 100, .rows = 30 });
+ defer p.deinit();
+ const pane = try cache.open(p, patch);
+ // The checkout's file, opened by a look from the diff pane.
+ lookAt(p, 0, cargo);
+ p.update(.tick);
+ try std.testing.expect(std.mem.endsWith(u8, p.panes[p.view().active].?.file.?.path, "Cargo.toml"));
+ p.view().active = 0;
+ p.update(.tick);
+ p.look_missed = false;
+ if (way == 0) {
+ DiffFixture.click(p, pane, 6); // ` fn kept() {}`, new line 2
+ } else {
+ lookAt(p, 0, "entry/src/entry.rs:2"); // the same, selected by hand
+ }
+ const shown = p.panes[p.view().active].?;
+ var n: usize = 0;
+ for (p.panes) |slot| n += @intFromBool(slot != null);
+ seen[way] = .{
+ .active_path = try std.testing.allocator.dupe(u8, if (shown.file) |f| f.path else ""),
+ .row = shown.body.cur_row,
+ .missed = p.look_missed,
+ .msg = try std.testing.allocator.dupe(u8, pane.msg[0..pane.msg_len]),
+ .panes = n,
+ };
+ }
+ defer for (seen) |s| {
+ std.testing.allocator.free(s.active_path);
+ std.testing.allocator.free(s.msg);
+ };
+ try std.testing.expectEqualStrings(seen[1].active_path, seen[0].active_path);
+ try std.testing.expectEqual(seen[1].row, seen[0].row);
+ try std.testing.expectEqual(seen[1].missed, seen[0].missed);
+ try std.testing.expectEqualStrings(seen[1].msg, seen[0].msg);
+ try std.testing.expectEqual(seen[1].panes, seen[0].panes);
+ // And it works: the checkout's file, at the line.
+ try std.testing.expect(std.mem.endsWith(u8, seen[0].active_path, "/entry/src/entry.rs"));
+ try std.testing.expectEqual(@as(i32, 1), seen[0].row);
+}
+
+test "Plumb: a look sends what it looks at, the rules written first: a rule's word or port takes it, a name open in a pane is focused unsent, one nothing takes is Look's own" {
+ if (!platform_has_fs) return;
+ var tmp = std.testing.tmpDir(.{});
+ defer tmp.cleanup();
+ try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "pic.svg", .data = "<svg/>" });
+ var dir_buf: [4096]u8 = undefined;
+ const root = dir_buf[0..try tmp.dir.realPath(std.testing.io, &dir_buf)];
+ var pic_buf: [4200]u8 = undefined;
+ const pic = try std.fmt.bufPrint(&pic_buf, "{s}/pic.svg", .{root});
+ const p = try Pardes.init(std.testing.allocator, .{ .cols = 100, .rows = 30 });
+ defer p.deinit();
+ const pane = try p.setTestFile("see https://ziglang.org here\n");
+ // The defaults: a URL to the web port, the host's opener; the hover
+ // asks resolve, as before.
+ lookAt(p, 0, "https://ziglang.org");
+ var linked = false;
+ while (p.nextEffect()) |e| if (e == .open_link) {
+ try std.testing.expectEqualStrings("https://ziglang.org", e.open_link.slice());
+ linked = true;
+ };
+ try std.testing.expect(linked);
+ var real: [4096]u8 = undefined;
+ try std.testing.expect(resolve(p, "https://ziglang.org", root, &real) == .url);
+ // A rule set written first takes what it matches: its word started in
+ // place, from the looking pane, and no pane opened.
+ try std.testing.expect(Plumb.apply(p, false, "plumb/rules", "type is text\ndata matches '.*\\.svg'\narg isfile $data\nplumb start Msg svg $file\n\ninclude basic\n") == null);
+ lookAt(p, 0, pic);
+ try std.testing.expectEqual(@as(usize, 0), p.view().active);
+ var said_buf: [4300]u8 = undefined;
+ try std.testing.expectEqualStrings(try std.fmt.bufPrint(&said_buf, "svg {s}", .{pic}), pane.msg[0..pane.msg_len]);
+ // A name open in a pane is focused, never sent.
+ p.look_text = true;
+ lookAt(p, 0, pic);
+ p.look_text = false;
+ const opened = p.view().active;
+ try std.testing.expect(opened != 0);
+ p.view().active = 0;
+ p.setMessage(0, "before");
+ lookAt(p, 0, pic);
+ try std.testing.expectEqual(opened, p.view().active);
+ try std.testing.expectEqualStrings("before", pane.msg[0..pane.msg_len]);
+ // With no web rule, a URL is a word Look searches for.
+ p.view().active = 0;
+ try std.testing.expect(Plumb.apply(p, false, "plumb/rules", "type is text\narg isfile $data\nplumb to edit\n") == null);
+ while (p.nextEffect()) |_| {}
+ lookAt(p, 0, "https://ziglang.org");
+ while (p.nextEffect()) |e| try std.testing.expect(e != .open_link);
+ const dot = @import("ninep/pane.zig").dotOf(pane);
+ try std.testing.expectEqualStrings("https://ziglang.org", pane.file.?.content[dot.q0..dot.q1]);
+}
+
+test "Plumb: a commit hash looked at in a git work tree is git show's, paged; outside one Diff declines, and the word is searched for" {
+ if (pardes.Term.ops == null) return error.SkipZigTest; // a command pane
+ if (!platform_has_fs) return;
+ var tmp = std.testing.tmpDir(.{});
+ defer tmp.cleanup();
+ try tmp.dir.createDir(std.testing.io, ".git", .default_dir);
+ try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "notes.txt", .data = "fixed in 3f2a9c1\n" });
+ var dir_buf: [4096]u8 = undefined;
+ const root = dir_buf[0..try tmp.dir.realPath(std.testing.io, &dir_buf)];
+ const p = try Pardes.init(std.testing.allocator, .{ .cols = 100, .rows = 30 });
+ defer p.deinit();
+ // /test.txt: its directory, /, is in no work tree.
+ const pane = try p.setTestFile("fixed in 3f2a9c1\n");
+ lookAt(p, 0, "3f2a9c1");
+ const dot = @import("ninep/pane.zig").dotOf(pane);
+ try std.testing.expectEqualStrings("3f2a9c1", pane.file.?.content[dot.q0..dot.q1]);
+ for (p.panes) |slot| if (slot) |pn| try std.testing.expect(pn.command == null);
+ var notes_buf: [4200]u8 = undefined;
+ lookAt(p, 0, try std.fmt.bufPrint(&notes_buf, "{s}/notes.txt", .{root}));
+ const notes = p.view().active;
+ try std.testing.expect(notes != 0);
+ lookAt(p, notes, "3f2a9c1");
+ var paged = false;
+ for (p.panes) |slot| if (slot) |pn| if (pn.command) |cmd| {
+ try std.testing.expect(std.mem.endsWith(u8, cmd, "git show 3f2a9c1"));
+ try std.testing.expect(pn.command_pages);
+ paged = true;
+ };
+ try std.testing.expect(paged);
+}