summaryrefslogtreecommitdiff
path: root/core/Pick.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-25 05:58:33 -0300
committerGabriel Schneider <[email protected]>2026-11-25 05:58:33 -0300
commit1d440373e90516ace8e45e8e64f2e4ae5d4a4773 (patch)
tree2eb1247e10a143c37d4972d1d1f883a38e140a85 /core/Pick.zig
parent99c70953a0c3b8e32cc5b61121c2b18e5ee68edd (diff)
downloadpardes-1d440373e90516ace8e45e8e64f2e4ae5d4a4773.tar.gz
pardes-1d440373e90516ace8e45e8e64f2e4ae5d4a4773.zip
TagState, Pick, Band: computed text breaks between its items only, a hanging indent under the spines, a rolled level three rows at most ending `+N ↓`, the picker's act row one row, a row too long cut with `…` (a path from the left) (walk UI polish P1, UX DESIGN.md D2): the rolled level was one long line wrapped by the tag's grapheme wrap, so a key fell apart from its label (`P`/`ClipPasteBefore`, `l ls`/`p…`, `D d`/`iagnostic end`) and its continuation rows started at the tag's first column under the box; the act row wrapped onto two (`Grep Rec`/`ent`); a band row was clipped at its step's edge; now (TagState.Builder) `keyCell` keeps each key cell's column and `row(indent)` starts a row of the head with a `│` under each key cell left of the indent (UX D5's spines through the tag's continuation rows; `// P2: the rule role`) and blanks up to it; the rolled level puts each child (`key label`) whole, a row's last child followed by the next row from the first child's column, three rows at most (a terminal's: the rows its own text takes, as before), the last one's last fitting child followed by a dim `+N ↓` (N the children not shown; the cells of it and of a struck key kept on the last row), its hints by the right block's rule on its last row (dropped where they do not fit); Pick.head's key cells are the builder's (its head's first spans, as every head's), its act row one row from two cells right of the last spine: the acts, `|`, the other sources, what does not fit dropped from the right (the sources first) and a dim `…` ending it (M-l, M-h reach them); Band.findSpines takes the key cells on whatever row they are (it wanted them on the tag's last row, so a picker's band had no spines and its steps started at the pane's edge: fsearch's list rows); Band.cutRow holds a row to its room with `…`: a path (its directory faint: Find's rows) cut from the left (`…r/Store.zig`), anything else from the right, its marks and faint bytes moved with it; TEST FIRST: TagState.zig "a rolled level breaks between its children only: ..." (SPC's level at 60 columns: three rows, the second and third `│ ` then a child, no row wider than the tag, every child shown whole, the rest counted in the last row's `+N ↓`; SPC h's on one row), Pick.zig "a picker's act row is one row under the spines ..." (60 columns: `│ │ Walk Look ` ... ` …`, a dim `…`), Band.zig "a row longer than its room is cut with `…` ..."; the SPC test reads a level of three rows at most; core-test 1066/1236 (170 skipped); process-test: 3 goldens regenerated and read: leader (the rolled level's second and third rows `│ ` from its first child's column, no child split, the hints at the last row's right end), find (`␣ f`'s hints at the row's end), fsearch (the list picker's act row one row ending `Panes …`, its band rows under spines from two cells right of the last, the body a row up); a user met the split words at every width under ~160 columns
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNBFhdevVu48bvL9kCE
Diffstat (limited to 'core/Pick.zig')
-rw-r--r--core/Pick.zig103
1 files changed, 64 insertions, 39 deletions
diff --git a/core/Pick.zig b/core/Pick.zig
index 8fcc5945..52976f15 100644
--- a/core/Pick.zig
+++ b/core/Pick.zig
@@ -565,17 +565,8 @@ pub fn head(p: *Pardes, arena: std.mem.Allocator, pane: *Pane) !?TagState.Head {
const s = &p.view().tag_state;
var b = try TagState.Builder.of(p, arena, pane);
const text = &b.text;
- const spans = &b.spans;
- var cells: [4][2]u32 = undefined;
- var ncells: usize = 0;
// SPC's cell, then its keys': `␣ f`.
- if (pk.keys.len > 0) for (0..pk.keys.len + 1) |k| {
- const name = if (k == 0) "␣" else bindings.keyName(pk.keys.slice()[k - 1]);
- cells[ncells] = .{ @intCast(text.items.len), @intCast(text.items.len + name.len) };
- ncells += 1;
- try text.appendSlice(arena, name);
- try text.append(arena, ' ');
- };
+ if (pk.keys.len > 0) try b.keyCells(.leader, pk.keys.slice());
try text.appendSlice(arena, pk.word.slice());
try text.append(arena, ' ');
for (pk.refined[0..pk.nrefined]) |r| try text.print(arena, "{s} | ", .{r.query.slice()});
@@ -594,38 +585,43 @@ pub fn head(p: *Pardes, arena: std.mem.Allocator, pane: *Pane) !?TagState.Head {
const hints = text.items.len;
try b.styled("⏎ wear it · esc", .dim);
try b.right(counted, hints);
- for (cells[0..ncells]) |c| try spans.append(arena, .{ .lo = c[0], .hi = c[1], .style = .key });
- return .{ .text = text.items, .spans = spans.items, .cells = @intCast(ncells), .caret = caret };
+ var h = b.done();
+ h.caret = caret;
+ return h;
}
try b.right(counted, text.items.len);
- // The second row: the spines go on through it from the key cells,
- // then the other sources' words, each switching to it.
- try text.append(arena, '\n');
- const prefix = try pardes.tagline.prefixIn(p, arena, pane);
- const width = pardes.tagline.tagWidth(p, panes.paneIdOf(p, pane) orelse 0);
- const lead = File.displayWidth(p.settings.tab, prefix) % @max(1, width);
- var col: usize = 0;
- for (cells[0..ncells]) |c| {
- const at = lead + File.displayWidth(p.settings.tab, text.items[0..c[0]]);
- while (col < at) : (col += 1) try text.append(arena, ' ');
- try spans.append(arena, .{ .lo = @intCast(text.items.len), .hi = @intCast(text.items.len + "│".len), .style = .key });
- try text.appendSlice(arena, "│");
- col += 1;
- }
- const nspines: u8 = @intCast(spans.items.len);
- try text.appendSlice(arena, if (ncells == 0) "" else " ");
- for (acts) |act| if (offered(pk, act)) try text.print(arena, "{s} ", .{act.word});
- try text.appendSlice(arena, "|");
- var first = false;
- inline for (comptime std.enums.values(Source)) |src| if (src != .list and src != .messages and src != .themes) {
- if (src != pk.source) {
- if (!first) try text.append(arena, ' ');
- first = false;
- try text.appendSlice(arena, words.get(src).word);
- }
+ // The second row, one row (UX D2): under the spines from the key
+ // cells, from two cells right of the last, the acts, `|`, the other
+ // sources' words, each switching to it; what does not fit is dropped
+ // from the right (the sources first) and the row ends in a dim `…`
+ // (M-l and M-h reach them all).
+ try b.row(if (b.ncols > 0) b.cols[b.ncols - 1] + 2 else 0);
+ var offer: [acts.len + 1 + std.enums.values(Source).len][]const u8 = undefined;
+ var nw: usize = 0;
+ for (acts) |act| if (offered(pk, act)) {
+ offer[nw] = act.word;
+ nw += 1;
+ };
+ offer[nw] = "|";
+ nw += 1;
+ inline for (comptime std.enums.values(Source)) |src| if (src != .list and src != .messages and src != .themes and src != pk.source) {
+ offer[nw] = words.get(src).word;
+ nw += 1;
};
- for (cells[0..ncells]) |c| try spans.append(arena, .{ .lo = c[0], .hi = c[1], .style = .key });
- return .{ .text = text.items, .spans = spans.items, .cells = nspines, .caret = caret };
+ for (offer[0..nw], 0..) |word, i| {
+ const gap: usize = @intFromBool(i > 0);
+ const rest: usize = if (i + 1 < nw) 2 else 0;
+ if (b.col() + gap + File.displayWidth(p.settings.tab, word) + rest > b.width) {
+ try b.put(if (gap > 0) " " else "");
+ try b.styled("…", .dim);
+ break;
+ }
+ try b.put(if (gap > 0) " " else "");
+ try b.put(word);
+ }
+ var h = b.done();
+ h.caret = caret;
+ return h;
}
/// The band's rows: as many as the list will show, eleven at most, from
@@ -1553,6 +1549,35 @@ test "a picker from a held pane unrolls in a reader made for it: its rows in the
try std.testing.expectEqualStrings("pick", pk.query.slice());
}
+test "a picker's act row is one row under the spines, two cells right of the last: what does not fit dropped from the right, the sources first, a dim `…` ending it" {
+ const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 60, .rows = 40 });
+ defer p.deinit();
+ p.settings.jumps = .walk;
+ var tmp = std.testing.tmpDir(.{});
+ defer tmp.cleanup();
+ const a_path = try testFile(p, &tmp, "alpha.zig", "const alpha = 1;\n");
+ defer p.gpa.free(a_path);
+ _ = try p.setTestFile("held\n");
+ const asker = p.view().active;
+ Trail.keep(p.panes[asker].?);
+ p.stream.engine = .walk;
+ open(p, asker, .find, "", "", "");
+ const reader = p.paneBySerial(live(p).?.landing).?;
+ var frame = std.heap.ArenaAllocator.init(std.testing.allocator);
+ defer frame.deinit();
+ const a = frame.allocator();
+ const tag = try tagOf(p, a, reader);
+ var rows = std.mem.splitScalar(u8, tag, '\n');
+ try std.testing.expect(std.mem.startsWith(u8, rows.next().?, "␣ f Find "));
+ const acts_row = rows.next().?;
+ try std.testing.expect(rows.next() == null);
+ try std.testing.expect(std.mem.startsWith(u8, acts_row, "│ │ Walk Look "));
+ try std.testing.expect(std.mem.endsWith(u8, acts_row, " …"));
+ try std.testing.expect(File.displayWidth(p.settings.tab, acts_row) <= pardes.tagline.tagWidth(p, reader));
+ const h = (try head(p, a, p.panes[reader].?)).?;
+ try std.testing.expect(h.spans[h.spans.len - 1].style == .dim);
+}
+
test "a picker's keys: Tab marks and moves, M-a all and none, C-SPC refines and Backspace undoes it, M-h switches source keeping the query" {
const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 140, .rows = 50 });
defer p.deinit();