summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-24 21:10:48 -0300
committerGabriel Schneider <[email protected]>2026-11-24 21:10:58 -0300
commit9d7f1c626687454cd2d8431aa8f6c905efd7ce97 (patch)
tree9a2c82edc4d7faaf70119f48f101bcfeaf5b2470
parent3621482c586b1d0d3601a1668a307918f1faea93 (diff)
downloadpardes-9d7f1c626687454cd2d8431aa8f6c905efd7ce97.tar.gz
pardes-9d7f1c626687454cd2d8431aa8f6c905efd7ce97.zip
Pick: the entry points open a picker in the tag (walk UI, pick-ui SPEC.md §14.3 phase 4, item 5 of line D): in a session whose jumps walk, from the keyboard or a click (Pick.asked: never a 9P script's, which keeps the query pane whose rows it reads back and whose `not found` it hears), Find and Grep (`SPC f f`, `SPC f g`, their words), Recent (`SPC f r`), Search's sources (`SPC b b` Panes, `SPC s s` Symbols, `SPC /` All), Panes, Jumplist (`SPC j l`) and the language server's symbols and diagnostics (`SPC l s`, `l S`, `l d`, `l D`: lsp/Ask.zig, a list picker titled by its word) unroll in the tag of the pane their Enter lands in; `Jumps new-pane` (still the default) keeps today's query pane and +Jumps, so no golden moves; `/` in a body stays today's; two fixes to the items before: the band is as tall as its second step (the acts and what they act on, the sources), and with the preview off (M-p) no frame is asked for it (Pick.busy spun every frame); test/perf.zig `--pick`: a key in a Find of 50,000 paths and its frame, the frames after it while the names are scored, a cursor move over files and the frame after it that loads the preview, instructions and time; TEST FIRST: Pick.zig "pick-ui §14.3 phase 4: SPC f f from a held pane opens in its reader and Esc removes it; from a reading pane it unrolls there; Enter lands as a step leaving the list word; n walks; a Look on the word reopens it with its cursor and marks"; core-test 0 failed; pane-test 182/184 and behaviour-test (and --replay) 274/277, process-test 5 of 146 failed: all the base's (A's tests not updated in this base: Help's +Help, window mode, a PDF's SPC; the goldens find, tagnav, builtins, leader, ttyhelp of A's report), shell-test, term-test, kitty-test pass
Co-Authored-By: Claude Opus 5.5 <[email protected]>
-rw-r--r--core/Pick.zig95
-rw-r--r--core/builtins.zig9
-rw-r--r--core/lsp/Ask.zig6
-rw-r--r--test/perf.zig81
4 files changed, 187 insertions, 4 deletions
diff --git a/core/Pick.zig b/core/Pick.zig
index 372ff139..7913a7e0 100644
--- a/core/Pick.zig
+++ b/core/Pick.zig
@@ -60,7 +60,7 @@ const words = std.EnumArray(Source, struct { word: []const u8, keys: []const u8
.symbols = .{ .word = "Symbols", .keys = "s" },
.all = .{ .word = "All", .keys = "" },
.jumplist = .{ .word = "Jumplist", .keys = "j" },
- .list = .{ .word = "List", .keys = "" },
+ .list = .{ .word = "List", .keys = "l" },
});
/// The pickers kept after they roll up, for their list words and Resume.
@@ -143,6 +143,14 @@ pub fn deinit(pk: *Pick, gpa: std.mem.Allocator) void {
gpa.free(pk.rows);
}
+/// Whether a search a builtin asks for from pane `id` is a picker in the
+/// tag (SPEC §14.3 phase 4): in a session whose jumps walk, from the
+/// keyboard or a click, never a script's (a 9P write's: the query pane,
+/// whose rows it reads back, and whose `not found` it hears).
+pub fn asked(p: *const Pardes) bool {
+ return p.settings.jumps == .walk and !p.fs.serving;
+}
+
/// Picker `id`, kept or live.
pub fn byId(p: *const Pardes, id: u32) ?*Pick {
if (id == 0) return null;
@@ -374,7 +382,7 @@ pub fn produceAll(p: *Pardes, tick: bool) void {
/// The frames a live picker still owes: scoring, a preview (nextWake's).
pub fn busy(p: *const Pardes) bool {
for (p.picks) |slot| if (slot) |pk| if (pk.unrolled) {
- if (pk.names.busy() or pk.shown != p.view().tag_state.rows.at) return true;
+ if (pk.names.busy() or (pk.previews and pk.shown != p.view().tag_state.rows.at)) return true;
};
return false;
}
@@ -562,7 +570,17 @@ pub fn head(p: *Pardes, arena: std.mem.Allocator, pane: *Pane) !?TagState.Head {
pub fn bandRows(p: *const Pardes) u16 {
const pk = live(p) orelse return 0;
const have = if (!fuzzy(pk)) Band.Cursor.shown else pk.names.cands.items.len;
- return @intCast(@max(1, @min(Band.Cursor.shown, have)));
+ const rows: usize = @max(1, @min(Band.Cursor.shown, have));
+ // Its second step's rows too: the sources, the acts and what they act on.
+ return @intCast(switch (pk.spine) {
+ .sources => @max(rows, spine_rows.len),
+ .acts => acts: {
+ var n: usize = 1;
+ for (acts) |act| n += @intFromBool(offered(pk, act));
+ break :acts @max(rows, n);
+ },
+ .rows, .edit => rows,
+ });
}
/// The band's steps: the rows around the cursor.
@@ -1498,6 +1516,10 @@ test "a picker's keys: Tab marks and moves, M-a all and none, C-SPC refines and
try std.testing.expectEqualStrings("alpha", s.field.text());
settle(p);
try std.testing.expectEqual(@as(usize, 3), count(p, pk));
+ // M-p: the preview off, and no frame asked for it.
+ p.update(.{ .key = .{ .cp = 'p', .alt = true } });
+ try std.testing.expect(!pk.previews and !busy(p));
+ p.update(.{ .key = .{ .cp = 'p', .alt = true } });
// M-h r: Recent, the query kept.
p.update(.{ .key = .{ .cp = 'h', .alt = true } });
try std.testing.expect(pk.spine == .sources);
@@ -1568,6 +1590,8 @@ test "M-l unrolls the act step, which says what it acts on; Copy puts the places
settle(p);
p.update(.{ .key = .{ .cp = 'l', .alt = true } });
try std.testing.expect(pk.spine == .acts);
+ // The band as tall as the acts and what they act on, the list's rows fewer.
+ try std.testing.expectEqual(@as(u16, 10), bandRows(p));
var frame = std.heap.ArenaAllocator.init(std.testing.allocator);
defer frame.deinit();
const band = (try Band.of(p, frame.allocator(), p.panes[id].?, id)).?;
@@ -1655,6 +1679,71 @@ test "after Enter the list is a word in the reader's trail: n and N walk its row
p.update(.{ .key = .{ .cp = Key.escape } });
}
+test "pick-ui §14.3 phase 4: SPC f f from a held pane opens in its reader and Esc removes it; from a reading pane it unrolls there; Enter lands as a step leaving the list word; n walks; a Look on the word reopens it with its cursor and marks" {
+ const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 160, .rows = 50 });
+ defer p.deinit();
+ p.settings.jumps = .walk;
+ p.stream.engine = .walk;
+ var tmp = std.testing.tmpDir(.{});
+ defer tmp.cleanup();
+ const a_path = try testFile(p, &tmp, "pick.zig", "const pick = 1;\n");
+ defer p.gpa.free(a_path);
+ const b_path = try testFile(p, &tmp, "pick_test.zig", "test {}\n");
+ defer p.gpa.free(b_path);
+ const c_path = try testFile(p, &tmp, "other.zig", "x\n");
+ defer p.gpa.free(c_path);
+ _ = try p.setTestFile("held\n");
+ const held = p.view().active;
+ Trail.keep(p.panes[held].?);
+ p.gpa.free(p.panes[held].?.file.?.path);
+ p.panes[held].?.file.?.path = try std.Io.Dir.path.join(p.gpa, &.{ std.Io.Dir.path.dirname(a_path).?, "held.txt" });
+ const npanes = paneCount(p);
+ const typeIn = struct {
+ fn f(pp: *Pardes, keys: []const u8) void {
+ for (keys) |c| pp.update(.{ .key = .{ .cp = c, .text = &[_]u8{c} } });
+ }
+ }.f;
+ // SPC f f from the held pane: a reader made for it, which Esc takes.
+ typeIn(p, " ff");
+ try std.testing.expect(live(p) != null and live(p).?.made);
+ try std.testing.expectEqual(npanes + 1, paneCount(p));
+ p.update(.{ .key = .{ .cp = Key.escape } });
+ try std.testing.expectEqual(npanes, paneCount(p));
+ try std.testing.expectEqual(held, p.view().active);
+ // Again, typed into: Enter lands in a reader of the held pane.
+ typeIn(p, " ffpick");
+ const pk = live(p).?;
+ settle(p);
+ try std.testing.expectEqual(@as(usize, 2), count(p, pk));
+ p.update(.{ .key = .{ .cp = Key.tab } });
+ p.update(.{ .key = .{ .cp = Key.up } });
+ p.update(.{ .key = .{ .cp = Key.enter } });
+ const reader = Trail.readerOf(p, p.panes[held].?).?;
+ const t = &p.panes[reader].?.trail;
+ try std.testing.expect(t.n == 3 and t.steps[1] == .list);
+ try std.testing.expect(std.mem.startsWith(u8, t.steps[1].list.text.slice(), "Find pick 1/2 •1"));
+ const first = p.panes[reader].?.file.?.path;
+ try std.testing.expect(std.mem.eql(u8, first, a_path) or std.mem.eql(u8, first, b_path));
+ // n: the other row, in place of the step.
+ p.view().active = reader;
+ p.update(.{ .key = .{ .cp = 'n', .text = "n" } });
+ const now = Trail.readerOf(p, p.panes[held].?).?;
+ try std.testing.expect(!std.mem.eql(u8, p.panes[now].?.file.?.path, first));
+ try std.testing.expectEqual(@as(u8, 3), p.panes[now].?.trail.n);
+ // SPC f f from the reader, which reads: it unrolls in the reader itself.
+ typeIn(p, " ff");
+ try std.testing.expectEqual(@as(?usize, now), TagState.hostOf(p));
+ try std.testing.expect(!live(p).?.made);
+ p.update(.{ .key = .{ .cp = Key.escape } });
+ // A Look on the list word: the list again, its cursor and its mark.
+ Trail.lookStep(p, now, 1);
+ try std.testing.expect(live(p) == pk);
+ try std.testing.expectEqual(@as(u16, 1), p.view().tag_state.rows.at);
+ try std.testing.expectEqual(@as(usize, 1), pk.marks.items.len);
+ try std.testing.expectEqualStrings("pick", p.view().tag_state.field.text());
+ p.update(.{ .key = .{ .cp = Key.escape } });
+}
+
test "a picker from a reading pane unrolls in that pane, its own text set aside while it previews and back on Esc" {
const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 140, .rows = 50 });
defer p.deinit();
diff --git a/core/builtins.zig b/core/builtins.zig
index 589915c2..52e4ce1d 100644
--- a/core/builtins.zig
+++ b/core/builtins.zig
@@ -1801,6 +1801,7 @@ pub const Grep = struct {
/// stays, its count 0; the write hears `not found`.
fn search(c: Ctx, source: panes.Query.Source, miss: []const u8) void {
const pat = std.mem.trim(u8, c.arg orelse "", " \t\r\n");
+ if (pardes.Pick.asked(c.p)) return pardes.Pick.open(c.p, c.id, if (source == .find) .find else .grep, "", pat, "");
const reused = panes.Query.ofOwner(c.p, c.pane.serial) != null;
panes.Query.open(c.p, c.id, source, pat, pat.len == 0);
if (pat.len == 0 or !c.p.fs.serving) return;
@@ -1823,6 +1824,11 @@ pub const Search = struct {
pub fn run(c: Ctx) void {
const line = std.mem.trim(u8, c.arg orelse "", " \t\r\n");
const asked = panes.Query.parse(line) orelse panes.Query.parse(std.mem.concat(c.p.scratch.allocator(), u8, &.{ "/", line }) catch return).?;
+ // `SPC b b`, `SPC s s`, `SPC /` and the like: a picker in the tag.
+ if (pardes.Pick.asked(c.p)) switch (asked.source) {
+ inline .find, .grep, .recent, .panes, .symbols, .all => |s| return pardes.Pick.open(c.p, c.id, @field(pardes.Pick.Source, @tagName(s)), "", asked.pat, ""),
+ else => {},
+ };
panes.Query.open(c.p, c.id, asked.source, asked.pat, true);
}
};
@@ -1844,6 +1850,7 @@ pub const Panes = struct {
pub const takes_arg = true;
pub const quiet = true;
pub fn run(c: Ctx) void {
+ if (pardes.Pick.asked(c.p)) return pardes.Pick.open(c.p, c.id, .panes, "", std.mem.trim(u8, c.arg orelse "", " \t\r\n"), "");
panes.Query.open(c.p, c.id, .panes, std.mem.trim(u8, c.arg orelse "", " \t\r\n"), true);
}
};
@@ -2072,6 +2079,7 @@ pub const Recent = struct {
// The query pane under the pane the keyboard is in, line 1
// `Recent `, typed into; what follows the word narrows the files.
if (c.p.panes[c.id] == null) return c.p.reportFailure(c.id, "Recent: open a pane to search from");
+ if (pardes.Pick.asked(c.p)) return pardes.Pick.open(c.p, c.id, .recent, "", std.mem.trim(u8, c.arg orelse "", " \t\r\n"), "");
panes.Query.open(c.p, c.id, .recent, std.mem.trim(u8, c.arg orelse "", " \t\r\n"), true);
}
};
@@ -2101,6 +2109,7 @@ pub const Jumplist = struct {
pub const scope: Scope = .session;
pub const output: OutputTraits = .{ .name = config.jumps_buffer, .steps = true, .locations = true };
pub fn run(c: Ctx) void {
+ if (pardes.Pick.asked(c.p)) return pardes.Pick.open(c.p, c.id, .jumplist, "", "", "");
panes.Output.openJumps(c.p, c.id) catch |err| c.p.reportError(.at(c.id), "jumplist", err);
}
};
diff --git a/core/lsp/Ask.zig b/core/lsp/Ask.zig
index 29d36f0a..976821d5 100644
--- a/core/lsp/Ask.zig
+++ b/core/lsp/Ask.zig
@@ -366,6 +366,12 @@ pub fn lspResponse(p: *Pardes, id: u32, response: ?[]const u8) void {
return;
}
+ // Symbols and diagnostics asked from the keyboard, where jumps walk: a
+ // picker in the tag of the pane its Enter lands in (Pick.zig).
+ if (pardes.Pick.asked(p)) switch (w.kind) {
+ .document_symbols, .workspace_symbols, .diagnostics, .workspace_diagnostics => return pardes.Pick.open(p, asked, .list, lspWord(w.kind), "", rows),
+ else => {},
+ };
// The lists of places: into the asking text's query pane (made or
// reused), line 1 their word, the places in that text its places.
const listed: ?panes.Query.Source = switch (w.kind) {
diff --git a/test/perf.zig b/test/perf.zig
index f36d64ac..16066e9f 100644
--- a/test/perf.zig
+++ b/test/perf.zig
@@ -394,6 +394,8 @@ const Options = struct {
mini: bool = false,
/// The scans a frame's slice bounds, a call at a time (`measureSearch`).
search: bool = false,
+ /// A picker's key and frame (`measurePick`).
+ pick: bool = false,
terminal_mib: ?usize = null,
/// The real binary's keystroke-to-present, `yes` stream and big open
/// (a tty pardes), or its keystrokes alone (a pardes-gui).
@@ -410,7 +412,7 @@ const Options = struct {
while (i < args.len) : (i += 1) {
const arg = args[i];
if (!std.mem.startsWith(u8, arg, "--")) return error.UnknownOption;
- const option = std.meta.stringToEnum(enum { json, creation, startup, mini, search, @"terminal-mib", @"self-test", reps, cols, rows, base, only, op, @"max-ratio", live, @"live-gui" }, arg[2..]) orelse
+ const option = std.meta.stringToEnum(enum { json, creation, startup, mini, search, pick, @"terminal-mib", @"self-test", reps, cols, rows, base, only, op, @"max-ratio", live, @"live-gui" }, arg[2..]) orelse
return error.UnknownOption;
switch (option) {
.json => opts.json = true,
@@ -418,6 +420,7 @@ const Options = struct {
.startup => opts.startup = true,
.mini => opts.mini = true,
.search => opts.search = true,
+ .pick => opts.pick = true,
.@"self-test" => opts.self_test = true,
else => {
i += 1;
@@ -480,6 +483,7 @@ pub fn main(init: std.process.Init) !void {
if (opts.terminal_mib) |mib| return measureTerminalSession(init.io, mib, reps, opts.json);
if (opts.mini) return measureMini(init.io, init.gpa, reps, opts.json);
if (opts.search) return measureSearch(init.io);
+ if (opts.pick) return measurePick(init.io);
if (opts.live) |exe| return measureLive(init.io, exe, false, reps, opts.json);
if (opts.live_gui) |exe| return measureLive(init.io, exe, true, reps, opts.json);
// The image-frame cells load the image addon by the path the build baked
@@ -1824,6 +1828,81 @@ fn measureSearch(io: std.Io) !void {
}
}
+/// `--pick`: a picker's hot paths (core/Pick.zig, walk UI line D), each
+/// a step and the frame that draws it, timed and its instructions counted
+/// (user space, this thread): a key typed into a Find of 50,000 paths and
+/// the frames after it while its names are scored; a cursor move over rows
+/// that are files, and the frame after it that loads the preview into the
+/// landing pane's body (a 2,000-line file read from the disk).
+fn measurePick(io: std.Io) !void {
+ var random: [12]u8 = undefined;
+ io.random(&random);
+ const dir = try std.fmt.allocPrint(gpa, "/tmp/pardes-pick-{x}", .{random});
+ defer gpa.free(dir);
+ try std.Io.Dir.createDirAbsolute(io, dir, .default_dir);
+ defer std.Io.Dir.cwd().deleteTree(io, dir) catch {};
+ var counter: Instructions = try .open();
+ defer counter.close();
+ var body: std.ArrayList(u8) = .empty;
+ defer body.deinit(gpa);
+ for (0..2000) |i| try body.print(gpa, " const value_{d} = compute(value_{d}, \"a line of the preview\");\n", .{ i, i -| 1 });
+ var name: [160]u8 = undefined;
+ for (0..20) |i| try writeFile(try std.fmt.bufPrint(&name, "{s}/pickme_{d}.zig", .{ dir, i }), body.items);
+ const start = try std.fmt.allocPrint(gpa, "{s}/start.zig", .{dir});
+ defer gpa.free(start);
+ try writeFile(start, "const start = 1;\n");
+ const core = try boot();
+ defer core.deinit();
+ core.settings.jumps = .walk;
+ pardes.look.lookAt(core, 0, start);
+ pump(core);
+ const id = filePane(core) orelse return error.OpenDidNotOpenFile;
+ pardes.Pick.open(core, id, .find, "", "", "");
+ const pk = pardes.Pick.live(core) orelse return error.NoPicker;
+ // The listing as the disk engine would give it: 50,000 paths, the
+ // real files among them.
+ _ = core.stream.stop();
+ pk.names.reset();
+ const dirs = [_][]const u8{ "core", "dev/gui", "dev/tui", "runtime", "test/behaviour", "addons/pdf", "zig-pkg/ghostty/src/terminal" };
+ const words = [_][]const u8{ "layout", "places", "names", "query", "stream", "surface", "replica", "tape", "kitty", "render" };
+ for (0..50_000) |i| {
+ const path = if (i % 2500 == 0) try std.fmt.bufPrint(&name, "pickme_{d}.zig", .{i / 2500}) else try std.fmt.bufPrint(&name, "{s}/module_{d}/{s}_{d}.zig", .{ dirs[i % dirs.len], i / 64 % 997, words[i * 7 % words.len], i });
+ try pk.names.add(gpa, path, 0, path.len, @TypeOf(pk.names).baseOf(path), 0);
+ }
+ pk.names.typed(gpa, "");
+ while (pk.names.busy()) pk.names.rescore(gpa);
+ try frame(core);
+ const Step = struct {
+ fn run(c: *pardes.Pardes, ev: pardes.Event, n: *Instructions, s: *Slowest, hits: usize) !void {
+ const was = n.read();
+ const t0 = nowNs();
+ c.update(ev);
+ try frame(c);
+ s.add(nowNs() -| t0, n.read() -| was, hits);
+ }
+ };
+ var keys: Slowest = .{};
+ var after: Slowest = .{};
+ for ("pickme") |ch| {
+ try Step.run(core, .{ .key = .{ .cp = ch, .text = &[_]u8{ch} } }, &counter, &keys, pk.names.hits.items.len);
+ while (pk.names.busy()) try Step.run(core, .tick, &counter, &after, pk.names.hits.items.len);
+ }
+ keys.report("pick key + frame", "pickme", pk.names.hits.items.len);
+ after.report("pick tick + frame while scoring", "pickme", pk.names.hits.items.len);
+ // The first preview, then the cursor moved and the preview after it.
+ try Step.run(core, .tick, &counter, &after, 0);
+ var moves: Slowest = .{};
+ var previews: Slowest = .{};
+ for (0..19) |_| {
+ try Step.run(core, .{ .key = .{ .cp = pardes.Key.down } }, &counter, &moves, 0);
+ try Step.run(core, .tick, &counter, &previews, 0);
+ }
+ moves.report("pick Down + frame", "pickme", pk.names.hits.items.len);
+ previews.report("pick preview tick + frame", "pickme", pk.names.hits.items.len);
+ const landing = core.panes[core.paneBySerial(pk.landing) orelse return error.NoLanding].?;
+ if (!std.mem.endsWith(u8, landing.file.?.path, ".zig") or std.mem.indexOf(u8, landing.file.?.path, "pickme_") == null) return error.NoPreview;
+}
+
/// The longest of a scan's calls.
const Slowest = struct {
calls: usize = 0,