summaryrefslogtreecommitdiff
path: root/core/Prompt.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-25 08:30:30 -0300
committerGabriel Schneider <[email protected]>2026-11-25 08:47:11 -0300
commit58d7434f56a9fef3098cfc191fbd1cb32ec09cfb (patch)
treec69ff77501f3fdc5b308632c38ba29de2d9c968b /core/Prompt.zig
parent59e1178acaabaa5ef16ed829b854542c21394d6f (diff)
parenteb8ecb8a451ae32d590c42755614b801f9cc0c09 (diff)
downloadpardes-58d7434f56a9fef3098cfc191fbd1cb32ec09cfb.tar.gz
pardes-58d7434f56a9fef3098cfc191fbd1cb32ec09cfb.zip
walk UI M6: the polish round's P1 (vuzlwsvx eb8ecb8a451a: the tag out of rest D1, no dim D9, the delays D12, the right block D3, wrapping D2, a band over a terminal or a kind's pane drawn over its body, the band's height D6, drawing the band D5 in part, the trail at rest D8 in part, asking D13 in part, a load's band rows made again and the tag's rows held to MAX_TAG_ROWS) merged onto M5 (zqwxonrs 59e1178acaab), both on G3's kytxrnnk, resolved by meaning: P1's `// P2:` markers go to P2's roles: the spines a head's rows hang (TagState.Builder.row) and the spines in the rows a tag keeps from rest (draw.zig paintPaneTag) in the rule ink, where P1 drew them in the box's, and the word n walks in the roles' key ink, underlined (draw.zig, D8), where P1 drew it in the box's; one mechanism for dim text: P1's hints go through Builder.right as dim spans, P2's painter draws every dim span in the dim ink of the tag's ground (never the faint attribute), so P2's own dim hint spans in TagState (run, a sequence, rename, roll up, unroll) are P1's lines, and the forward steps, the fold `+N` and an unlit search word are drawn in that dim ink (where P1 kept the line numbers' ink); the spines still hang from the key cells: Builder.keyCells puts them first in every head (TagState, Pick, Prompt's key cell), right() moves spans without reordering them and row() puts its rule spans after, so M5's span-order fix holds under the right block (D3) and the act row (D2); Pick.head is P1's builder with the actions picker's branch (P3) beside the themes picker's, its hint `⏎ or 1-9 apply it · esc` a dim right-block hint, and P2's `|` and other sources' words dim in P1's one-row act row (the acts in the text ink; `.actions` never offered as a source); Prompt.head is P1's right block with P2's D14: an invalid pattern's reason in the err ink and what is shown meanwhile dim stand in the count's place (D3: the count never drops, so the reason is never dropped as a hint would be) and no hints; TagState's rolled level is P1's row-breaking (D2) over P2's registers (D11): the level's children are the registers holding something before it lays them out, so `+N ↓` counts registers not shown, each child its shown value, `⏎` dim; Band.zig: a list step's width is P1's (52 cells at most) with P2's meta counted in it, a row is P1's cutRow with P2's meta after it, only when the whole text and the meta fit (D5: the meta gives way before the text is cut); draw.zig's band cursor row: P1's tint across the `▶ ` lead (D5) on P2's selection ground, the lead's ground only so `▶` keeps the key ink (D4); P2's D7 with P1's D6: the preview's landing line sits ⌈rows/3⌉ down the body the band leaves (fsearch's ctrln: line 6 at body row 3 of 8 under a 5-row band); TESTS (the merge's choices): TagState "a rolled level breaks between its children only ..." asks its spines in the rule role, Trail "... the word n walks is underlined" asks it in the key ink, Band "a band is drawn in the theme's roles ..." asks the cursor's `▶` in the key ink on the selection ground; P1's Trail fold test asks the fold in the dim ink of the reading ground (it asked the line numbers' ink); goldens: the five that conflicted (find, fsearch, lookrange, lsp, selregex) regenerated and every changed row read against P1's: P2's D7 `▸` on a picker's landing line and its sentence on the notice row (find, fsearch, lsp), the message coming back on the notice row when the picker closes (find promoted and cancel, fsearch landed, lsp), P3's `1 message` for the walked pane's one entry (find), P2's D14 (fsearch: the `▪` marks gone, the hits on the hit ground #5e4923, `▸` in the key ink #bada9d), the third-of-the-body placement (fsearch ctrln), P2's inks (the reading tint #2c2c0f, the key ink #bada9d for key cells and the n word, the dim ink #79836f for the plain word and the hints where the faint attribute was, the notice row's dim #6f7d75: fsearch, lookrange, selregex); no other golden moved; core-test 1083/1254 (171 skipped), process-test 0 of 147 failed (3 skipped, gui-only)
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.zig75
1 files changed, 48 insertions, 27 deletions
diff --git a/core/Prompt.zig b/core/Prompt.zig
index 4db7e424..9dfe9ec2 100644
--- a/core/Prompt.zig
+++ b/core/Prompt.zig
@@ -809,10 +809,11 @@ pub fn execWord(p: *Pardes, id: usize) void {
/// The span of pane `pane`'s tag its search word takes while its places no
/// longer light it (the first Esc cleared them): drawn dimmed (draw.zig).
pub fn unlit(p: *const Pardes, pane: *Pane) ?[2]usize {
+ if (Trail.outOfRest(p, pane)) return null;
const t = &pane.trail;
- const whole = Trail.folded(p, pane);
+ const whole = pardes.tagline.folded(p, pane);
for (t.steps[0..t.cur], 0..) |*step, i| if (step.* == .search) {
- if (lights(pane, &step.search) or t.cur - i > whole) return null;
+ if (lights(pane, &step.search) or t.isFolded(i, whole)) return null;
return t.spanOf(i, whole);
};
return null;
@@ -1059,15 +1060,15 @@ 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
+/// The head of the prompt's tag: `s self▌ = Exec Edit x/self/ 4
/// 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;
- var text: std.ArrayList(u8) = .empty;
- var spans: std.ArrayList(TagState.Span) = .empty;
- try text.append(arena, ' ');
- 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();
@@ -1077,23 +1078,29 @@ 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) {
// A pattern that is no regex: why, in the err ink, in place of the
- // hints (UX D14), what is shown meanwhile dim.
+ // hints (UX D14), what is shown meanwhile dim; in the count's place,
+ // which never drops.
if (pr.bad) {
- try text.appendSlice(arena, " ");
- try styled(arena, &text, &spans, regexMessage(line), .err);
- try styled(arena, &text, &spans, try std.fmt.allocPrint(arena, " · the {d} from before shown, dimmed", .{@as(usize, pane.body.nsel) + 1}), .dim);
+ try styled(arena, text, spans, regexMessage(line), .err);
+ try styled(arena, text, spans, try std.fmt.allocPrint(arena, " · the {d} from before shown, dimmed", .{@as(usize, pane.body.nsel) + 1}), .dim);
+ try b.right(at, text.items.len);
return .{ .text = text.items, .spans = spans.items, .cells = 1, .caret = caret };
} 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 };
}
@@ -1121,7 +1128,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")
@@ -1261,8 +1268,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" {
@@ -1275,9 +1296,9 @@ 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.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);
try std.testing.expect(selecting(p, pane).?.dim == false);
// No match: 0, and the selection it began with.
@@ -1317,10 +1338,10 @@ test "Enter keeps what s found, the pattern in / and in the history Up brings ba
typeKeys(p, "K");
p.update(.{ .key = .{ .cp = Key.up } });
try std.testing.expectEqualStrings("self..", p.view().tag_state.field.text());
- try std.testing.expect(has(try tagOf(p), " K self.. = Exec Edit g/self../ keeps 2 of 2"));
+ try std.testing.expect(has(try tagOf(p), "K self.. = Exec Edit g/self../ keeps 2 of 2"));
p.update(.{ .key = .{ .cp = Key.down } });
typeKeys(p, "b");
- try std.testing.expect(has(try tagOf(p), " K b = Exec Edit g/b/ keeps 1 of 2 ⏎ keep"));
+ try std.testing.expect(has(try tagOf(p), "K b = Exec Edit g/b/ keeps 1 of 2 ⏎ keep"));
// Ctrl-r: the history under the tag, a row a line.
p.update(.{ .key = .{ .cp = 'r', .ctrl = true } });
try std.testing.expectEqual(@as(u16, 1), Band.takes(p, p.view().active));
@@ -1332,7 +1353,7 @@ test "Enter keeps what s found, the pattern in / and in the history Up brings ba
typeKeys(p, "|");
try std.testing.expectEqual(Pane.Prompt.none, pane.prompt);
p.update(.{ .key = .{ .cp = 't', .text = "tr a-z A-Z" } });
- try std.testing.expect(has(try tagOf(p), " | tr a-z A-Z = Exec Edit |tr a-z A-Z ⋯ ⏎ replace"));
+ try std.testing.expect(has(try tagOf(p), "| tr a-z A-Z = Exec Edit |tr a-z A-Z ⋯ ⏎ replace"));
p.update(.{ .key = .{ .cp = Key.enter } });
try std.testing.expectEqualStrings("tr a-z A-Z", p.registers.value('|', 0).?);
var asked: ?u32 = null;
@@ -1369,7 +1390,7 @@ test "/ searches the body as it is typed: the current place selected, `▸` in t
pane.body.cur_row = 2;
pane.body.cur_col = 6;
typeKeys(p, "/dirty");
- try std.testing.expect(has(try tagOf(p), " / dirty = Look /dirty/ 3/7 · 5 lines ⏎ land · M-⏎ as a list"));
+ try std.testing.expect(has(try tagOf(p), "/ dirty = Look /dirty/ 3/7 · 5 lines ⏎ land · M-⏎ as a list"));
try std.testing.expectEqual(@as(?usize, 2), pane.places.current);
try std.testing.expectEqualStrings(" ", try gutterAt(p, frame.allocator(), 0));
try std.testing.expectEqualStrings(" ", try gutterAt(p, frame.allocator(), 1));
@@ -1426,7 +1447,7 @@ test "? searches back from the caret; no match is 0; a pattern that is no regex
pane.body.cur_col = 6;
const was = pane.body.primaryRange(pane.file.?.content, 0);
typeKeys(p, "?dirty");
- try std.testing.expect(has(try tagOf(p), " ? dirty = Look ?dirty? 2/7 · 5 lines ⏎ land"));
+ try std.testing.expect(has(try tagOf(p), "? dirty = Look ?dirty? 2/7 · 5 lines ⏎ land"));
typeKeys(p, "x");
try std.testing.expect(has(try tagOf(p), "= Look ?dirtyx? 0 ⏎ land"));
try std.testing.expectEqualDeep(was, pane.body.primaryRange(pane.file.?.content, 0));
@@ -1514,7 +1535,7 @@ test "a pipe prompt runs a known filter live, a run a selection: the outputs gho
p.update(.{ .key = .{ .cp = Key.enter } });
typeKeys(p, "|");
p.update(.{ .key = .{ .cp = 't', .text = "tr a-z A-Z" } });
- try std.testing.expect(has(try tagOf(p), " | tr a-z A-Z = Exec Edit |tr a-z A-Z ⋯ ⏎ replace"));
+ try std.testing.expect(has(try tagOf(p), "| tr a-z A-Z = Exec Edit |tr a-z A-Z ⋯ ⏎ replace"));
const first = lastPipe(p) orelse return error.MissingLiveRun;
const asked = p.pipe.pipeRequest(first).?;
try std.testing.expectEqual(@as(usize, 2), asked.inputs.len);