diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-25 00:44:54 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-25 01:05:40 -0300 |
| commit | 32f8f603f30a6e6e196da929fa0df82b8e94f4c1 (patch) | |
| tree | ed2a839e5aa06da9bd540cb1d9b46b165353fa43 /core/Prompt.zig | |
| parent | ab4e13779ccda0ac5ce497fd2b706930e2f2845c (diff) | |
| download | pardes-32f8f603f30a6e6e196da929fa0df82b8e94f4c1.tar.gz pardes-32f8f603f30a6e6e196da929fa0df82b8e94f4c1.zip | |
Prompt, Pick: lines D's pickers and E's prompts work together where jumps walk (walk UI M3 item 2, pick-ui SPEC §7.2, §6.3, §7.3): Alt-Enter in a search (`/ ?`) or a sam prompt (`s S K A-K`) keeps the result as a list, a row a place (`path:line:col: text`, the text's leading blanks off, cut to 160 bytes, look.parsePathLine's form so the column lands too), the first Query.max_rows (2000) and a message saying how many there were past it: where jumps walk (Pick.asked: never a 9P script's) a picker of those rows (Pick.Source.list, titled by the prompt's plain word, `/dirty/` or `Edit x/dirty/`, cut to the picker's word at a character's start) in the tag of the pane its Enter lands in, the body as it was before the prompt, its Enter the list word `/dirty/ 3/7` in the trail; under `Jumps new-pane` a search keeps E's query pane (Query.open) and a sam prompt's selections are a +Search list (Output.fillResults), where before Alt-Enter in a sam prompt did nothing; the sam prompts' hints say `M-⏎ as a list` as the search's do; one owner for n and N (§6.3: the newest list or search word, or the one Looked at): a search's places answer n while they light its word (§7.3: tinted while it is the word n walks), so a list landed in the pane (Pick.listed, after Trail.through) puts a search's tints out, n then walking the list (D's walkList already gives way to a newer search word), and Look on the search word (Prompt.lookWord) lights it and takes n back; F's colors.previewTheme stays the one theme preview (no other in the tree; it is derived each step from the live themes picker, Pick.produceAll, so E2's `:theme ` either goes through Pick.Source.themes or derives it the same way); TEST FIRST: Prompt.zig "Alt-Enter in / or s keeps the result as a list ..." (failed before: no picker, Pick.live null), Pick.zig "n and N walk the newest list or search word, or the one Looked at ..." (failed before: the search's places still lit after the list landed, Pick.zig:1912, n stepping the search); E's `?` test loses its Alt-Enter tail (now in the new test, both routings), its `s` head test reads the new hint; five Query/Stream tests about today's query pane opened by Alt-Enter in `/` set `Jumps new-pane` (G's newpane.py); goldens: selregex and msg regenerated (process-test --update), each changed row the sam prompt's hint `⏎ select · M-⏎ as a list · C-r history · esc` and nothing else; tui core-test 1053/1223 (170 skipped, 0 failed); process-test 9 of 146 failed before the two updates: those two and item 1's seven left to item 3
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.zig | 130 |
1 files changed, 114 insertions, 16 deletions
diff --git a/core/Prompt.zig b/core/Prompt.zig index 8081f7f9..6b177c19 100644 --- a/core/Prompt.zig +++ b/core/Prompt.zig @@ -123,10 +123,10 @@ const Info = struct { const info = std.EnumArray(Op, Info).init(.{ .search = .{ .cell = "/", .hint = "⏎ land · M-⏎ as a list · C-r history · esc" }, .search_back = .{ .cell = "?", .hint = "⏎ land · M-⏎ as a list · C-r history · esc" }, - .select = .{ .cell = "s", .hint = "⏎ select · C-r history · esc" }, - .split = .{ .cell = "S", .hint = "⏎ select · C-r history · esc" }, - .keep = .{ .cell = "K", .hint = "⏎ keep · C-r history · esc" }, - .remove = .{ .cell = "A-K", .hint = "⏎ keep · C-r history · esc" }, + .select = .{ .cell = "s", .hint = "⏎ select · M-⏎ as a list · C-r history · esc" }, + .split = .{ .cell = "S", .hint = "⏎ select · M-⏎ as a list · C-r history · esc" }, + .keep = .{ .cell = "K", .hint = "⏎ keep · M-⏎ as a list · C-r history · esc" }, + .remove = .{ .cell = "A-K", .hint = "⏎ keep · M-⏎ as a list · C-r history · esc" }, .pipe = .{ .cell = "|", .hint = "⏎ replace · C-r history · esc" }, .pipe_to = .{ .cell = "A-|", .hint = "⏎ run · C-r history · esc" }, .insert = .{ .cell = "!", .hint = "⏎ insert · C-r history · esc" }, @@ -415,19 +415,71 @@ fn land(p: *Pardes, id: usize, pane: *Pane, op: Op, pat: []const u8, bad: bool) word(pane, if (op == .search_back) '?' else '/', pat); } -/// Alt-Enter in `/` or `?`: the places kept as a list, a row each, in the -/// pane's query pane (Query.zig), the body as it was before the prompt. +/// Alt-Enter in `/ ?` or `s S K A-K` (SPEC §7.2): the result kept as a +/// list, a row a place, the body as it was before the prompt. Where jumps +/// walk, a picker of those rows (Pick.zig's `list`, titled by the plain +/// word, `/dirty/`) in the tag of the pane its Enter lands in; else `/`'s +/// query pane (Query.zig) and the selections as a +Search list. fn asList(p: *Pardes, id: usize, pane: *Pane) void { const s = &p.view().tag_state; const op = s.prompt.op; - if (!searches(op)) return; + if (!searches(op) and mode(op) == null) return; + if (s.prompt.bad) return; var kept: [Field.max]u8 = undefined; const typed = kept[0..s.field.len]; @memcpy(typed, s.field.text()); + var said: [Trail.max_text]u8 = undefined; + var sw: std.Io.Writer = .fixed(&said); + _ = plainWord(&sw, op, typed) catch {}; + // The word cut at a character's start to a picker's word's room. + const plain = sw.buffered(); + const title = plain[0..modal.graphemeStart(plain, @min(plain.len, 24))]; + var rows: std.Io.Writer.Allocating = .init(p.gpa); + defer rows.deinit(); + const total = listRows(p, pane, op, &rows.writer) catch |err| return p.reportError(.at(id), "prompt", err); s.kind = .rest; TagState.toRest(p); undo(p, pane, op); - panes.Query.open(p, id, .text, typed, true); + if (total > panes.Query.max_rows) { + var cut: [96]u8 = undefined; + p.setMessage(.at(id), std.fmt.bufPrint(&cut, "{s}: the first {d} of {d} places", .{ title, panes.Query.max_rows, total }) catch ""); + } + if (pardes.Pick.asked(p)) return pardes.Pick.open(p, id, .list, title, "", rows.written()); + if (searches(op)) return panes.Query.open(p, id, .text, typed, true); + const content = rows.toOwnedSlice() catch |err| return p.reportError(.at(id), "prompt", err); + panes.Output.fillResults(p, id, panes.paneDir(pane), .search, title, content, null) catch |err| return p.reportError(.at(id), "prompt", err); +} + +/// The live result of prompt `op` in `pane` as a list's rows, +/// `path:line:col text` each, the first `Query.max_rows`: a search's +/// places (every one found within a search's budget) or a sam prompt's +/// selections. How many there were. +fn listRows(p: *Pardes, pane: *Pane, op: Op, w: *std.Io.Writer) !usize { + const f = &pane.file.?; + const index = try File.lineIndex(p.gpa, f); + if (searches(op)) { + const set = &pane.places; + set.fill(p, pane, std.math.maxInt(usize), regexp.Regex.budget); + const hits = set.hits.items; + for (hits[0..@min(hits.len, panes.Query.max_rows)]) |h| try placeRow(w, f, index, h.start); + return hits.len; + } + var sels: [Text.max_selections]modal.Selection = undefined; + const got = pane.body.ranges(f.content, 0, &sels); + for (sels[0..@min(got.n, panes.Query.max_rows)]) |r| try placeRow(w, f, index, @min(r.anchor, r.head)); + return got.n; +} + +/// Byte `at` of file `f` as a list's row: its place (`path:line:col:`, +/// look.parsePathLine's) and its line's text, the blanks it starts with +/// off, cut to `row_text` bytes. +fn placeRow(w: *std.Io.Writer, f: *const File.State, index: []const usize, at: usize) !void { + const row_text = 160; + const line = Places.lineOf(index, at); + const start = index[line]; + const end = std.mem.indexOfScalarPos(u8, f.content, start, '\n') orelse f.content.len; + const text = std.mem.trimStart(u8, f.content[start..end], " \t"); + try w.print("{s}:{d}:{d}: {s}\n", .{ f.path, line + 1, at - start + 1, text[0..modal.graphemeStart(text, @min(text.len, row_text))] }); } /// The filters a pipe prompt runs live as it is typed: commands that @@ -998,7 +1050,7 @@ fn strike(p: *Pardes, s: *Surface, pane: *Pane, r: pardes.Rect, line: i32, lo_: } /// The head of the prompt's tag: ` s self▌ = Exec Edit x/self/ 4 -/// selections in 6 lines ⏎ select · C-r history · esc`. +/// selections in 6 lines ⏎ select · M-⏎ as a list · C-r history · esc`. pub fn head(p: *Pardes, arena: std.mem.Allocator, pane: *Pane) !TagState.Head { const s = &p.view().tag_state; const pr = &s.prompt; @@ -1197,7 +1249,7 @@ test "s asks in the tag's head: its key cell, the field, the plain word and the try std.testing.expectEqual(TagState.Kind.prompt, p.view().tag_state.kind); // No chip on the notice band: the prompt is the tag's. try std.testing.expectEqual(Pane.Prompt.none, pane.prompt); - try std.testing.expect(std.mem.endsWith(u8, try tagOf(p), " s ⏎ select · C-r history · esc")); + try std.testing.expect(std.mem.endsWith(u8, try tagOf(p), " s ⏎ select · M-⏎ as a list · C-r history · esc")); typeKeys(p, "self"); try std.testing.expect(has(try tagOf(p), " s self = Exec Edit x/self/ 2 selections in 3 lines ⏎ select")); try std.testing.expectEqual(@as(u16, 1), pane.body.nsel); @@ -1329,7 +1381,7 @@ test "/ searches the body as it is typed: the current place selected, the gutter try std.testing.expectEqual(@as(u8, 1), pane.trail.n); } -test "? searches back from the caret; no match is 0; a pattern that is no regex keeps the last places dimmed; Esc puts the body back; * makes the search word with no prompt; Alt-Enter keeps the places as the query pane's rows" { +test "? searches back from the caret; no match is 0; a pattern that is no regex keeps the last places dimmed; Esc puts the body back; * makes the search word with no prompt" { const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 200, .rows = 30 }); defer p.deinit(); const pane = try p.setTestFile(dirty); @@ -1354,11 +1406,6 @@ test "? searches back from the caret; no match is 0; a pattern that is no regex typeKeys(p, "gge*"); try std.testing.expectEqual(TagState.Kind.rest, p.view().tag_state.kind); try std.testing.expect(std.mem.startsWith(u8, try tagOf(p), "/\\bdirty\\b/ 1/7 › ")); - // Alt-Enter: the query pane, its line `/dirty`. - typeKeys(p, "/dirty"); - p.update(.{ .key = .{ .cp = Key.enter, .alt = true } }); - try std.testing.expectEqual(TagState.Kind.rest, p.view().tag_state.kind); - try std.testing.expect(p.panes[p.view().active].?.query != null); } test "sam prompts one after another make one recipe word, the Edit line it is; a motion ends it and the next starts the pane's one again; ! adds nothing; the scope fenced in the gutter, what K drops struck; Look puts its selections back, Exec runs it as Edit" { @@ -1512,3 +1559,54 @@ test "a live run's framing says each run's output, stderr and status in a real s // `grep x` finds nothing: exit 1 for both, an empty stderr. try std.testing.expectEqualSlices(u8, &.{ 1, 1 }, p.pipe.preview.?.codes); } + +test "Alt-Enter in / or s keeps the result as a list (SPEC §7.2): where jumps walk, a picker of a row a place in the tag of the pane its Enter lands in, the body as it was, its Enter the list word in the trail; more than a list holds, the first ones and a word saying so; under Jumps new-pane, /'s query pane as before" { + const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 200, .rows = 30 }); + defer p.deinit(); + const Pick = pardes.Pick; + const pane = try p.setTestFile(dirty); + typeKeys(p, "/dirty"); + p.update(.{ .key = .{ .cp = Key.enter, .alt = true } }); + const pk = Pick.live(p) orelse return error.TestUnexpectedResult; + try std.testing.expectEqual(Pick.Source.list, pk.source); + try std.testing.expectEqualStrings("/dirty/", pk.word.slice()); + try std.testing.expectEqual(@as(usize, 7), Pick.count(p, pk)); + try std.testing.expectEqual(pane.serial, p.view().tag_state.host); + try std.testing.expect(!pane.places.started); + // The third place (line 3's second `dirty`): Enter lands there, the + // list word before it. + p.update(.{ .key = .{ .cp = Key.down } }); + p.update(.{ .key = .{ .cp = Key.down } }); + p.update(.{ .key = .{ .cp = Key.enter } }); + try std.testing.expectEqual(TagState.Kind.rest, p.view().tag_state.kind); + try std.testing.expectEqual(@as(i32, 2), pane.body.cur_row); + try std.testing.expectEqual(@as(i32, 10), pane.body.cur_col); + try std.testing.expect(has(try tagOf(p), "/dirty/ 3/7 › ")); + // `s` over the whole text: its selections the rows, its word the Edit + // line it stands for; Esc rolls the list up, the selection as it was. + typeKeys(p, "%sdirty"); + p.update(.{ .key = .{ .cp = Key.enter, .alt = true } }); + const sel = Pick.live(p) orelse return error.TestUnexpectedResult; + try std.testing.expectEqualStrings("Edit x/dirty/", sel.word.slice()); + try std.testing.expectEqual(@as(usize, 7), Pick.count(p, sel)); + p.update(.{ .key = .{ .cp = Key.escape } }); + try std.testing.expectEqual(TagState.Kind.rest, p.view().tag_state.kind); + try std.testing.expectEqual(@as(usize, 0), pane.body.nsel); + // More places than a list holds (Query.max_rows): the first ones. + const many = try std.testing.allocator.alloc(u8, 2 * (panes.Query.max_rows + 5)); + defer std.testing.allocator.free(many); + for (0..panes.Query.max_rows + 5) |i| @memcpy(many[2 * i ..][0..2], "x\n"); + _ = try p.setTestFile(many); + typeKeys(p, "/x"); + p.update(.{ .key = .{ .cp = Key.enter, .alt = true } }); + const big = Pick.live(p) orelse return error.TestUnexpectedResult; + try std.testing.expectEqual(@as(usize, panes.Query.max_rows), Pick.count(p, big)); + try std.testing.expect(has(p.messages.saidBy(p.panes[p.view().active].?), "the first 2000 of 2005 places")); + p.update(.{ .key = .{ .cp = Key.escape } }); + // Under Jumps new-pane, `/`'s query pane, as before. + p.settings.jumps = .@"new-pane"; + typeKeys(p, "/x"); + p.update(.{ .key = .{ .cp = Key.enter, .alt = true } }); + try std.testing.expectEqual(TagState.Kind.rest, p.view().tag_state.kind); + try std.testing.expect(p.panes[p.view().active].?.query != null); +} |
