summaryrefslogtreecommitdiff
path: root/core/Prompt.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-26 01:14:33 -0300
committerGabriel Schneider <[email protected]>2026-11-26 02:11:21 -0300
commit1ce3bcb6178b720058518a12e45f25769be7d39c (patch)
tree29b78d95235d06de3bf85bc8a748e8c940546c87 /core/Prompt.zig
parentd75f8947fde8d2fa425ee0b60c7a687a0ff9f314 (diff)
downloadpardes-1ce3bcb6178b720058518a12e45f25769be7d39c.tar.gz
pardes-1ce3bcb6178b720058518a12e45f25769be7d39c.zip
Pick, Prompt, keys: Ctrl-r in a picker unrolls its source's earlier queries (UX DESIGN L2's last line, "Small, any of them: `C-r` in a picker recalls that source's earlier queries, as prompts do", in the L options the user liked; the coordinator's item 4): a history per source (Find, Grep, Recent, Panes, Symbols, All, ...; Lists keeps none), kept as the prompts' are, beside them (`Prompt.History.pick`, a `Ring` per source: the last 16 lines of a field's room, an older copy of a line gone, the same dump and digest walk, held to its count), a query kept as its picker rolls up with it typed, which a landing does too (Pick.rollUp); Ctrl-r in a picker is a band step like any other (the spine's `history`, beside the rows): its lines newest first, those holding the field, a cursor on one; Down and Up (C-n, C-p) move that cursor, Enter puts its line in the field and the picker filters again, Ctrl-r rolls it up and so does Esc, back to the picker (Pick.closeHistory, asked by keys.tagStateKey before its Esc rolls the tag to rest); anything else types in the field, which filters both; out of it Up and Down are the rows' cursor, no recall; Prompt's history step, its cursor and its rows take the ring, the field and the cursor as arguments now (historyStep, historyAt, historyRows, historyKey: Down and Up's walk, once in Prompt.key), one for the prompts and the pickers; the reference's "Back to a picker" says it; RUN (TEST FIRST): Pick.zig "Ctrl-r in a picker unrolls its source's earlier queries ..." types SPC f f `words` Enter, a Grep left with `in_w`, then SPC f f Ctrl-r and asks the band's history rows (`words` alone: Grep's is not Find's), Esc (the band rolled up, the picker live), Ctrl-r Enter (`words` in the field, the rows one), Grep's Ctrl-r (`in_w`), a Lists left typed (nothing kept), then seventeen Find queries (16 kept, q1 the oldest, q16 the newest) and Ctrl-r over the field `q1` (q16 .. q10, q1, no `words`): on L'3's tree the first Ctrl-r shows no history (Pick.zig:3196, expected `words`), passes now; a user hit it on every picker whose earlier query they wanted again; docs/typ/builtins-gui.json regenerated here for L'3's Lists and Resume's doc (the window build's list); with L'1 to L'3 under it: core-test 1128/1301 (173 skipped), shell-test 1349/1352 (3 skipped), pane-test 183/184, behaviour-test 280/280 and --replay 280/280, process-test 1 of 147 failed (ttyhelp, the merge's placeholder), term-test 17/17, kitty-test 45/45, the gui unit-test 1952/1956 (4 skipped; its perf check's BaselineHarnessMismatch, every base's); the dump fuzz (Prompt.History.pick) at 40,000 join seeds twice and 1,779 image seeds 13/13; the soak replicas --clients 5 --rtt 30,80,207: diverged 0, unequal 0, quiet checks 492/0 457/0 491/0, stops not on may_wait 0, the corpus 22 of 22 scenes the same, no leak; no frame or perf gate (the user's rule of 2026-11-26: at the programme's end); load 3.4 to 14.0
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNBFhdevVu48bvL9kCE
Diffstat (limited to 'core/Prompt.zig')
-rw-r--r--core/Prompt.zig95
1 files changed, 52 insertions, 43 deletions
diff --git a/core/Prompt.zig b/core/Prompt.zig
index afe9f78e..b76b2d9a 100644
--- a/core/Prompt.zig
+++ b/core/Prompt.zig
@@ -78,11 +78,14 @@ refused: bool = false,
/// `:`'s (Command.zig): what its rows are of, and where Tab writes.
command: Command = .{},
-/// The session's prompt histories: the lines Enter took, newest last.
+/// The session's prompt histories: the lines Enter took, newest last; and
+/// each picker source's queries, as its picker landed or was left typed
+/// (Pick.zig, UX L2).
pub const History = struct {
search: Ring = .{},
pipe: Ring = .{},
command: Ring = .{},
+ pick: std.EnumArray(pardes.Pick.Source, Ring) = .initFill(.{}),
};
pub const Ring = struct {
@@ -262,25 +265,9 @@ pub fn key(p: *Pardes, k: Key) void {
// Up and C-p move its cursor to the next line it shows, older or newer,
// the field kept as typed; Enter takes the line under it.
if (s.prompt.history) {
- const down = (plain and k.cp == Key.down) or (ctrl and k.cp == 'n');
- const up = (plain and k.cp == Key.up) or (ctrl and k.cp == 'p');
const r = ring(p, s.prompt.op);
- const at = historyAt(p);
- if (down or up) {
- var newer: u8 = 0;
- var older: u8 = 0;
- var rows: usize = 0;
- var back: u8 = 1;
- while (back <= r.n and rows < Band.Cursor.shown) : (back += 1) {
- if (std.mem.indexOf(u8, r.get(back).?, s.field.text()) == null) continue;
- rows += 1;
- if (back < at) newer = back;
- if (back > at and older == 0) older = back;
- }
- const to = if (down) older else newer;
- if (to != 0) s.prompt.recall = to;
- return;
- }
+ if (historyKey(r, s.field.text(), &s.prompt.recall, k)) return;
+ const at = historyAt(r, s.field.text(), s.prompt.recall);
if (plain and k.cp == Key.enter and at != 0) {
s.field.set(r.get(at).?);
live(p, pane);
@@ -1261,11 +1248,12 @@ fn plural(n: usize) []const u8 {
/// lines the field is in, eleven at most.
pub fn takes(p: *Pardes) u16 {
const s = &p.view().tag_state;
- if (s.prompt.op == .command) return @max(Command.takes(p), if (s.prompt.history) historyRows(p) else 0);
+ const rows = historyRows(ring(p, s.prompt.op), s.field.text());
+ if (s.prompt.op == .command) return @max(Command.takes(p), if (s.prompt.history) rows else 0);
if (s.prompt.op == .pipe_to) if (p.panes[TagState.hostOf(p) orelse return 0]) |pane| if (answered(p, pane, s.field.text())) |l|
- return @max(runRows(l), if (s.prompt.history) historyRows(p) else 0);
+ return @max(runRows(l), if (s.prompt.history) rows else 0);
if (!s.prompt.history) return 0;
- return historyRows(p);
+ return rows;
}
/// `A-|`'s runs as rows: each `#1 exit 0`, then its output's lines.
@@ -1275,12 +1263,12 @@ fn runRows(l: *const Pipe.PendingPipe) u16 {
return @intCast(@min(Band.Cursor.shown, n));
}
-fn historyRows(p: *Pardes) u16 {
- const s = &p.view().tag_state;
+/// The rows history `r` unrolled takes: its lines holding `q`, one at
+/// least, eleven at most.
+pub fn historyRows(r: *const Ring, q: []const u8) u16 {
var n: u16 = 0;
- const r = ring(p, s.prompt.op);
for (r.lines[0..r.n]) |l| {
- if (std.mem.indexOf(u8, l.slice(), s.field.text()) != null) n += 1;
+ if (std.mem.indexOf(u8, l.slice(), q) != null) n += 1;
}
return @max(1, @min(Band.Cursor.shown, n));
}
@@ -1292,8 +1280,9 @@ pub fn steps(p: *Pardes, arena: std.mem.Allocator, out: *[Band.max_steps]Band.St
var made: usize = 0;
// `:`'s history before its rows and their doc, which takes the width
// left after the others.
+ const r = ring(p, s.prompt.op);
if (s.prompt.op == .command) {
- if (s.prompt.history) made = try historyStep(p, arena, &out[0]);
+ if (s.prompt.history) made = try historyStep(arena, r, s.field.text(), s.prompt.recall, &out[0]);
return out[0 .. made + try Command.steps(p, arena, out[made..])];
}
if (s.prompt.op == .pipe_to) if (p.panes[TagState.hostOf(p) orelse return out[0..0]]) |pane| if (answered(p, pane, s.field.text())) |l| {
@@ -1312,35 +1301,55 @@ pub fn steps(p: *Pardes, arena: std.mem.Allocator, out: *[Band.max_steps]Band.St
made += 1;
};
if (!s.prompt.history) return out[0..made];
- return out[0 .. made + try historyStep(p, arena, &out[made])];
+ return out[0 .. made + try historyStep(arena, r, s.field.text(), s.prompt.recall, &out[made])];
}
-/// The line of its history the cursor of the history unrolled is on: the
-/// one the keys moved to (`recall`), else the newest holding the field;
-/// 0 with none.
-fn historyAt(p: *Pardes) u8 {
- const s = &p.view().tag_state;
- if (s.prompt.recall != 0) return s.prompt.recall;
- const r = ring(p, s.prompt.op);
+/// The line of history `r` the cursor of it unrolled is on: the one the
+/// keys moved to (`recall`), else the newest holding the field `q`; 0
+/// with none.
+pub fn historyAt(r: *const Ring, q: []const u8, recall: u8) u8 {
+ if (recall != 0) return recall;
var back: u8 = 1;
while (back <= r.n) : (back += 1) {
- if (std.mem.indexOf(u8, r.get(back).?, s.field.text()) != null) return back;
+ if (std.mem.indexOf(u8, r.get(back).?, q) != null) return back;
}
return 0;
}
+/// Down and Ctrl-n, Up and Ctrl-p in history `r` unrolled (UX D5: a list
+/// like any other): its cursor `recall` to the next line it shows, older
+/// or newer, the field `q` kept as typed; true when the key was one.
+pub fn historyKey(r: *const Ring, q: []const u8, recall: *u8, k: Key) bool {
+ const plain = !k.ctrl and !k.alt;
+ const ctrl = k.ctrl and !k.alt;
+ const down = (plain and k.cp == Key.down) or (ctrl and k.cp == 'n');
+ const up = (plain and k.cp == Key.up) or (ctrl and k.cp == 'p');
+ if (!down and !up) return false;
+ const at = historyAt(r, q, recall.*);
+ var newer: u8 = 0;
+ var older: u8 = 0;
+ var rows: usize = 0;
+ var back: u8 = 1;
+ while (back <= r.n and rows < Band.Cursor.shown) : (back += 1) {
+ if (std.mem.indexOf(u8, r.get(back).?, q) == null) continue;
+ rows += 1;
+ if (back < at) newer = back;
+ if (back > at and older == 0) older = back;
+ }
+ const to = if (down) older else newer;
+ if (to != 0) recall.* = to;
+ return true;
+}
+
/// A history step's row's index: its line's place in the ring with this
/// bit, which a click tells from the other steps' rows (Command.point).
pub const history_row: u16 = 0x8000;
-/// The history step (Ctrl-r): its lines newest first, those holding the
-/// field, its cursor on one.
-fn historyStep(p: *Pardes, arena: std.mem.Allocator, out: *Band.Step) !usize {
- const s = &p.view().tag_state;
- const r = ring(p, s.prompt.op);
+/// History `r`'s step (Ctrl-r): its lines newest first, those holding the
+/// field `q`, its cursor on one.
+pub fn historyStep(arena: std.mem.Allocator, r: *const Ring, q: []const u8, recall: u8, out: *Band.Step) !usize {
var rows: std.ArrayList(Band.Row) = .empty;
- const q = s.field.text();
- const at = historyAt(p);
+ const at = historyAt(r, q, recall);
var back: u8 = 1;
while (back <= r.n and rows.items.len < Band.Cursor.shown) : (back += 1) {
const l = r.get(back).?;