summaryrefslogtreecommitdiff
path: root/core/Prompt.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-25 05:39:53 -0300
committerGabriel Schneider <[email protected]>2026-11-25 05:39:53 -0300
commit99c70953a0c3b8e32cc5b61121c2b18e5ee68edd (patch)
tree0f950dfa341c68ed8376ea70b0c383ef68255576 /core/Prompt.zig
parentc3b01a651dcee194f20a5be8da80a3f55a7235e7 (diff)
downloadpardes-99c70953a0c3b8e32cc5b61121c2b18e5ee68edd.tar.gz
pardes-99c70953a0c3b8e32cc5b61121c2b18e5ee68edd.zip
TagState, Pick, Prompt: the head's right block, the count `cursor/matches` and the hints at its row's right end, fixed while the field grows, the hints dim and first to go (walk UI polish P1, UX DESIGN.md D3): the count sat three spaces after the field (`Help tut▌ 3/133`, `Find re▌ 2/3`), so it slid right with every key typed, the only moving thing in the tag, and meant two things (Help's matches/total, the picker's cursor/matches); the hints followed it and wrapped mid-word onto a row of their own (msg's `s EXT ... C-r histo` / `ry · esc`); now `TagState.Builder.right(count, hints)` moves what was put from those bytes on to the row's right end (its last cell the row's last, two blanks between, at least two before), drops the hints whole when the row has no room for them, never the count (a head with no room for it runs past its row: the field's scroll D3 asks for there is not built); THE CHANGE: Builder is pub, made by `Builder.of(p, arena, pane)` with the row's width and the prefix's cells before the head (`col`), and Pick.head and Prompt.head build in it (their text and spans the builder's); counts: Help's is the cursor's row of its hits (`2/17`, `0` with none: no total), the picker's `0` with none (was `0/0`), the search prompt's wrap ` ↻` (was ` · wrapped`); hints are dim spans (describe-key's `⏎ run · esc`, Rename's, unrolled's `↑ roll up · ? field · esc`, the prompts' and the themes picker's); the rolled level keeps its hint as before (D2's rows put it on its last row); TEST FIRST: TagState.zig "the right block: the count `cursor/matches` at the row's right end, fixed while the field grows; the hints after it, dim, dropped whole where the row has no room" (Help at 60 columns: the first row exactly the tag's width ending ` 1/N`, the same after typing and `2/N` after Down; unrolled SPC's hints at the end, a dim span; at 24 columns `␣ SPC` alone); the tests reading heads read a run of blanks as two (Prompt.zig, Command.zig `has`; Pick, Band: the first row's start and end); core-test 1063/1233 (170 skipped); process-test: 7 goldens regenerated and read (find, fsearch, lsp, msg, pipe, selregex, ttyhelp): every changed row a count or hints moved to the row's right end (`␣ f Find zqm` ... `1/3`), `0/0` now `0`, ttyhelp's `1/136` now `1/1` (one match, the cursor on it), msg's `s EXT` hints dropped at 70 columns so its tag is one row again (the body a row up, where it is at rest); a user saw the count move at every key
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.zig46
1 files changed, 33 insertions, 13 deletions
diff --git a/core/Prompt.zig b/core/Prompt.zig
index 10886606..27b59649 100644
--- a/core/Prompt.zig
+++ b/core/Prompt.zig
@@ -1062,9 +1062,10 @@ fn strike(p: *Pardes, s: *Surface, pane: *Pane, r: pardes.Rect, line: i32, lo_:
pub fn head(p: *Pardes, arena: std.mem.Allocator, pane: *Pane) !TagState.Head {
const s = &p.view().tag_state;
const pr = &s.prompt;
- var text: std.ArrayList(u8) = .empty;
- var spans: std.ArrayList(TagState.Span) = .empty;
- try styled(arena, &text, &spans, info.get(pr.op).cell, .key);
+ var b = try TagState.Builder.of(p, arena, pane);
+ const text = &b.text;
+ const spans = &b.spans;
+ try styled(arena, text, spans, info.get(pr.op).cell, .key);
try text.append(arena, ' ');
const caret: u32 = @intCast(text.items.len + s.field.caret);
const line = s.field.text();
@@ -1074,20 +1075,25 @@ pub fn head(p: *Pardes, arena: std.mem.Allocator, pane: *Pane) !TagState.Head {
var w: std.Io.Writer = .fixed(&buf);
const said = if (pr.op == .command) Command.plainWord(p, &w, line) else plainWord(&w, pr.op, line) catch null;
if (said) |verb| {
- try styled(arena, &text, &spans, try std.fmt.allocPrint(arena, " = {s}", .{verb}), .dim);
+ try styled(arena, text, spans, try std.fmt.allocPrint(arena, " = {s}", .{verb}), .dim);
try text.print(arena, " {s}", .{w.buffered()});
}
+ }
+ // The count and the hints at the row's right end (UX D3).
+ const at = text.items.len;
+ if (line.len > 0) {
if (pr.bad) {
try text.appendSlice(arena, " ");
- try styled(arena, &text, &spans, regexMessage(line), .err);
+ try styled(arena, text, spans, regexMessage(line), .err);
try text.print(arena, " · the {d} from before shown, dimmed", .{@as(usize, pane.body.nsel) + 1});
} else if (behavior(pr.op) != null) {
- try pipeCount(p, arena, &text, &spans, pane, pr, line);
- } else try count(arena, &text, pane, pr);
+ try pipeCount(p, arena, text, spans, pane, pr, line);
+ } else try count(arena, text, pane, pr);
}
- if (pr.op == .command) try Command.count(p, arena, &text);
- try text.appendSlice(arena, " ");
- try styled(arena, &text, &spans, info.get(pr.op).hint, .dim);
+ if (pr.op == .command) try Command.count(p, arena, text);
+ const hints = text.items.len;
+ try styled(arena, text, spans, info.get(pr.op).hint, .dim);
+ try b.right(at, hints);
return .{ .text = text.items, .spans = spans.items, .cells = 1, .caret = caret };
}
@@ -1115,7 +1121,7 @@ fn count(arena: std.mem.Allocator, text: *std.ArrayList(u8), pane: *Pane, pr: *c
// Round the end from where it began.
const c = at orelse return;
const origin = set.origin(pane);
- if (if (pr.op == .search) hits[c].start < origin else hits[c].start > origin) try text.appendSlice(arena, " · wrapped");
+ if (if (pr.op == .search) hits[c].start < origin else hits[c].start > origin) try text.appendSlice(arena, " ↻");
},
.select, .split => if (pr.found == 0)
try text.appendSlice(arena, " 0")
@@ -1255,8 +1261,22 @@ fn tagOf(p: *Pardes) ![]const u8 {
return tagline.tagText(p, p.scratch.allocator(), p.panes[p.view().active].?);
}
+/// Whether `needle` is in `hay`, a run of two spaces or more in either read
+/// as two: a right block's padding is its row's (UX D3).
fn has(hay: []const u8, needle: []const u8) bool {
- return std.mem.indexOf(u8, hay, needle) != null;
+ var in: [8192]u8 = undefined;
+ var of: [1024]u8 = undefined;
+ return std.mem.indexOf(u8, squeezed(hay, &in), squeezed(needle, &of)) != null;
+}
+
+fn squeezed(s: []const u8, buf: []u8) []const u8 {
+ var n: usize = 0;
+ for (s, 0..) |c, i| {
+ if (c == ' ' and i >= 2 and s[i - 1] == ' ' and s[i - 2] == ' ') continue;
+ buf[n] = c;
+ n += 1;
+ }
+ return buf[0..n];
}
test "s asks in the tag's head: its key cell, the field, the plain word and the count, the selections live in the body; no match is 0, a pattern that is no regex keeps the last result dimmed and says why, Esc puts them back" {
@@ -1269,7 +1289,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 · M-⏎ as a list · C-r history · esc"));
+ try std.testing.expect(has(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);