summaryrefslogtreecommitdiff
path: root/core/Pick.zig
diff options
context:
space:
mode:
Diffstat (limited to 'core/Pick.zig')
-rw-r--r--core/Pick.zig24
1 files changed, 17 insertions, 7 deletions
diff --git a/core/Pick.zig b/core/Pick.zig
index 321b16b7..8fcc5945 100644
--- a/core/Pick.zig
+++ b/core/Pick.zig
@@ -563,8 +563,9 @@ fn rowAt(p: *Pardes, pk: *const Pick, arena: std.mem.Allocator, i: usize) !Row {
pub fn head(p: *Pardes, arena: std.mem.Allocator, pane: *Pane) !?TagState.Head {
const pk = live(p) orelse return null;
const s = &p.view().tag_state;
- var text: std.ArrayList(u8) = .empty;
- var spans: std.ArrayList(TagState.Span) = .empty;
+ 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`.
@@ -581,16 +582,22 @@ pub fn head(p: *Pardes, arena: std.mem.Allocator, pane: *Pane) !?TagState.Head {
if (pk.spine == .edit) try text.print(arena, "{s} | Edit ", .{pk.query.slice()});
const caret: u32 = @intCast(text.items.len + s.field.caret);
try text.appendSlice(arena, s.field.text());
+ // The count at the row's right end (UX D3): `cursor/matches`, `0` with
+ // none, ` •M` marked.
+ const counted = text.items.len;
const n = count(p, pk);
- try text.print(arena, " {d}/{d}", .{ if (n == 0) 0 else s.rows.at + 1, n });
+ if (n == 0) try text.append(arena, '0') else try text.print(arena, "{d}/{d}", .{ s.rows.at + 1, n });
if (pk.marks.items.len > 0) try text.print(arena, " •{d}", .{pk.marks.items.len});
if (pk.names.busy() or p.stream.busyFor(pk.id)) try text.appendSlice(arena, " ⋯");
// Themes have no acts and no other sources: no second row.
if (pk.source == .themes) {
- try text.appendSlice(arena, " ⏎ wear it · esc");
+ 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 };
}
+ 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');
@@ -1528,7 +1535,8 @@ test "a picker from a held pane unrolls in a reader made for it: its rows in the
const tag = try tagOf(p, a, reader);
// Out of rest no path (UX D1): not the previewed file's, not Keep;
// the head starts the tag's text.
- try std.testing.expect(std.mem.startsWith(u8, tag, "␣ f Find pick 1/1\n"));
+ const first = tag[0..std.mem.indexOfScalar(u8, tag, '\n').?];
+ try std.testing.expect(std.mem.startsWith(u8, first, "␣ f Find pick ") and std.mem.endsWith(u8, first, " 1/1"));
try std.testing.expect(std.mem.indexOf(u8, tag, "│ Walk Look Split Newcol Grep Edit Copy Keep Drop | Grep Recent Panes Symbols All Jumplist") != null);
// The body previews the row's file, after a frame of its own.
p.update(.tick);
@@ -1570,7 +1578,8 @@ test "a picker's keys: Tab marks and moves, M-a all and none, C-SPC refines and
try std.testing.expectEqual(@as(u16, 2), s.rows.at);
var frame = std.heap.ArenaAllocator.init(std.testing.allocator);
defer frame.deinit();
- try std.testing.expect(std.mem.indexOf(u8, try tagOf(p, frame.allocator(), id), " Refs 3/4 •1\n") != null);
+ const refs = try tagOf(p, frame.allocator(), id);
+ try std.testing.expect(std.mem.indexOf(u8, refs, " Refs ") != null and std.mem.indexOf(u8, refs, " 3/4 •1\n") != null);
p.update(.{ .key = .{ .cp = 'a', .alt = true } });
try std.testing.expectEqual(@as(usize, 4), pk.marks.items.len);
p.update(.{ .key = .{ .cp = 'a', .alt = true } });
@@ -1588,7 +1597,8 @@ test "a picker's keys: Tab marks and moves, M-a all and none, C-SPC refines and
settle(p);
try std.testing.expectEqual(@as(usize, 1), count(p, pk));
_ = frame.reset(.retain_capacity);
- try std.testing.expect(std.mem.indexOf(u8, try tagOf(p, frame.allocator(), id), " Refs alpha | w 1/1\n") != null);
+ const refined = try tagOf(p, frame.allocator(), id);
+ try std.testing.expect(std.mem.indexOf(u8, refined, " Refs alpha | w ") != null and std.mem.indexOf(u8, refined, " 1/1\n") != null);
// Backspace twice: the `w` goes, then the refinement, its query back.
p.update(.{ .key = .{ .cp = Key.backspace } });
p.update(.{ .key = .{ .cp = Key.backspace } });