diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-25 08:30:30 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-25 08:47:11 -0300 |
| commit | 58d7434f56a9fef3098cfc191fbd1cb32ec09cfb (patch) | |
| tree | c69ff77501f3fdc5b308632c38ba29de2d9c968b /core/Pick.zig | |
| parent | 59e1178acaabaa5ef16ed829b854542c21394d6f (diff) | |
| parent | eb8ecb8a451ae32d590c42755614b801f9cc0c09 (diff) | |
| download | pardes-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/Pick.zig')
| -rw-r--r-- | core/Pick.zig | 180 |
1 files changed, 122 insertions, 58 deletions
diff --git a/core/Pick.zig b/core/Pick.zig index 41a62201..c5b639cd 100644 --- a/core/Pick.zig +++ b/core/Pick.zig @@ -270,10 +270,9 @@ fn unroll(p: *Pardes, pk: *Pick, query: []const u8) void { s.rows = .{ .at = @intCast(@min(pk.at, std.math.maxInt(u16))) }; pk.unrolled = true; pk.shown = no_row; - // The whole window previews a theme: no pane dimmed (SPEC §3.6). + // The whole window previews a theme. if (pk.source == .themes) s.previewing = .full; if (p.paneBySerial(pk.landing)) |id| { - s.previewing.set(id); const pane = p.panes[id].?; pk.aside_row = pane.body.cur_row; pk.aside_col = pane.body.cur_col; @@ -606,78 +605,80 @@ 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; - try text.append(arena, ' '); - var cells: [4][2]u32 = undefined; - var ncells: usize = 0; + var b = try TagState.Builder.of(p, arena, pane); + const text = &b.text; // 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()}); 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 and actions have no acts and no other sources: no second row. if (pk.source == .themes or pk.source == .actions) { - const hint: u32 = @intCast(text.items.len); - try text.appendSlice(arena, if (pk.source == .themes) " ⏎ wear it · esc" else " ⏎ or 1-9 apply it · esc"); - // The key cells first: the band's spines hang from them. - for (cells[0..ncells]) |c| try spans.append(arena, .{ .lo = c[0], .hi = c[1], .style = .key }); - try spans.append(arena, .{ .lo = hint, .hi = @intCast(text.items.len), .style = .dim }); - return .{ .text = text.items, .spans = spans.items, .cells = @intCast(ncells), .caret = caret }; + const hints = text.items.len; + try b.styled(if (pk.source == .themes) "⏎ wear it · esc" else "⏎ or 1-9 apply it · esc", .dim); + try b.right(counted, hints); + var h = b.done(); + h.caret = caret; + return h; } - // 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 = .rule }); - 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}); - // The other sources' words, and the `|` before them, dim (UX D4). - const sources: u32 = @intCast(text.items.len); - try text.appendSlice(arena, "|"); - var first = false; - inline for (comptime std.enums.values(Source)) |src| if (src != .list and src != .messages and src != .themes and src != .actions) { - if (src != pk.source) { - if (!first) try text.append(arena, ' '); - first = false; - try text.appendSlice(arena, words.get(src).word); - } + try b.right(counted, text.items.len); + // 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, the `|` and the sources dim + // (UX D4); 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; }; - try spans.append(arena, .{ .lo = sources, .hi = @intCast(text.items.len), .style = .dim }); - 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 }; + const nacts = nw; + offer[nw] = "|"; + nw += 1; + inline for (comptime std.enums.values(Source)) |src| if (src != .list and src != .messages and src != .themes and src != .actions and src != pk.source) { + offer[nw] = words.get(src).word; + nw += 1; + }; + 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 ""); + if (i >= nacts) try b.styled(word, .dim) 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 -/// what the source has (not what the query keeps: typing never moves the -/// body). +/// The band's rows (UX D6): as many as the list will show, from what the +/// source has (not what the query keeps: typing never moves the body), +/// four at least, eleven at most, and 40 % of the host's column at most +/// (its panes' rows, which a borrow moves between them, never changes). pub fn bandRows(p: *const Pardes) u16 { const pk = live(p) orelse return 0; const have = if (!fuzzy(pk)) Band.Cursor.shown else pk.names.cands.items.len; - const rows: usize = @max(1, @min(Band.Cursor.shown, have)); + const v = p.view(); + const at = @import("layout.zig").findPane(p, TagState.hostOf(p) orelse return 0) orelse return 0; + var column: usize = 0; + for (v.cols[at.col].panes[0..v.cols[at.col].n]) |id| column += v.rects[id].h; + const rows: usize = @max(1, @min(Band.Cursor.shown, @max(4, have), column * 2 / 5)); // Its second step's rows too: the sources, the acts and what they act on. return @intCast(switch (pk.spine) { .sources => @max(rows, spine_rows.len), @@ -1751,7 +1752,10 @@ test "a picker from a held pane unrolls in a reader made for it: its rows in the defer frame.deinit(); const a = frame.allocator(); const tag = try tagOf(p, a, reader); - try std.testing.expect(std.mem.indexOf(u8, tag, " ␣ f Find pick 1/1\n") != null); + // Out of rest no path (UX D1): not the previewed file's, not Keep; + // the head starts the tag's text. + 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); @@ -1768,6 +1772,64 @@ 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 band is sized from its list at open, 4 rows at least, and typing never moves it" { + const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 100, .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].?); + // In the test's directory: its two files listed. + p.gpa.free(p.panes[asker].?.file.?.path); + p.panes[asker].?.file.?.path = try std.Io.Dir.path.join(p.gpa, &.{ std.Io.Dir.path.dirname(a_path).?, "held.txt" }); + p.stream.engine = .walk; + open(p, asker, .find, "", "", ""); + settle(p); + const reader = p.paneBySerial(live(p).?.landing).?; + p.sync(); + const rows = p.panes[reader].?.band_rows; + // One or two files listed: four rows, ground under them. + try std.testing.expectEqual(@as(u16, 4), rows); + for ("zzq") |c| p.update(.{ .key = .{ .cp = c, .text = &[_]u8{c} } }); + settle(p); + p.sync(); + try std.testing.expectEqual(@as(usize, 0), count(p, live(p).?)); + try std.testing.expectEqual(rows, p.panes[reader].?.band_rows); +} + 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(); @@ -1793,7 +1855,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 } }); @@ -1811,7 +1874,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 } }); |
