diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-25 07:26:39 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-25 07:36:10 -0300 |
| commit | c225fe093d7b4cb23bd5f66c7369f93beb5cfb18 (patch) | |
| tree | d0f484b696d284d00f075713c79f0100ebf07832 /core/Pick.zig | |
| parent | 1ee22df4c6c8fb2fd63325fcec616ea8aedad147 (diff) | |
| parent | 415b4e2683d03624f5600c23bfabde749a1a207c (diff) | |
| download | pardes-c225fe093d7b4cb23bd5f66c7369f93beb5cfb18.tar.gz pardes-c225fe093d7b4cb23bd5f66c7369f93beb5cfb18.zip | |
walk UI M5: the polish round's P3 (uppppkkk 1ee22df4c6c8: code actions as a picker, /kbdin as typed, Esc at once, `]` targets in one pass and cached, a pane keeps its number when it walks, B3 on an answer word) and P2 (zvkrxzwq 415b4e2683d0: the colour roles of UX DESIGN.md D4, the tui reading box, the themes picker's `in use`, registers D11, painted targets D10, the preview legible D7, prompts D14, 29 goldens, the roles derived faster) merged, both on G3's kytxrnnk, resolved by meaning: Pick.zig's five conflicts: Row carries P3's `key` (an action's digit) and P2's `meta` (`in use`), rowAt keeps P2's themes arm and P3's actions arm, steps passes both to Band.Row, head's no-second-row branch is P3's (themes and actions) with P2's hints as a dim span (`⏎ or 1-9 apply it · esc` dim as `⏎ wear it · esc` is), and both lines' tests at the file's end; body_layer.zig merged without a conflict and agrees: P3's treeTargets cache answers targetLine's `]f` `]c` `]T` arms, and P2's paintTargets paints whatever targetLine answers in place of the line's number, so the cached lines are the painted ones; the `g` target and the `]g` motion both ask jj.nextChange (body_layer targetLine, normal.zig goto_change), whose P2 change finds the last unsaved edit with the Changes layer off, so they agree; Band.zig is P2's alone: its Row.meta (right-aligned, dim, the first to give way) is the "right-aligned row meta" P3 left as not done, nothing more to build for it; an action's rows are drawn by P2's painter (Band.Row.key: the digit bold in the roles' key ink) and its ghost lines stand on colors.Grounds add/del, which D4's add/del role is (as the Changes layer), so neither needed wiring; A MERGE FAULT FOUND BY A TEST FIRST: P2's D7 preview (Pick.landingLine, Pick.sentence) held for every picker that previews but themes, and P3's actions picker previews: its body got the hit ground and `▸` on the caret's line (the line the edit starts, or for an edit that only puts lines in, the untouched line under them) and the notice row said `⏎ lands here · its text is the preview · S-⏎ a new pane` where Enter applies an edit and lands nowhere; both now leave out actions as they leave out themes (an action's preview is its edit on the Changes grounds, the head says what Enter does); TEST: Pick.zig's code actions test asks no landing line, no `▸` before the line the edit changes, no sentence on the notice row, and no hit ground on the line under an edit that puts a line in (fails on the merge at Pick.zig:2188, landingLine answered the caret's line); find.golden (the conflict) resolved by meaning and checked by process-test: snap nomatch's and topbar's notice rows are P2's D7 sentence with P3's count `1 message` (the walked pane's two Find echoes one entry), cancel's is P3's row; leader.golden (P3's, CodeAction's new doc) passes as P3 wrote it; docs/typ/builtins-tui.json is P3's, current (core-test's builtins_json test passes); core-test 1072/1242 (170 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 | 175 |
1 files changed, 170 insertions, 5 deletions
diff --git a/core/Pick.zig b/core/Pick.zig index ab63cc5d..3bc8c858 100644 --- a/core/Pick.zig +++ b/core/Pick.zig @@ -484,7 +484,7 @@ const Target = union(enum) { none, place: struct { path: []const u8, at: look.Sp /// Row `i` as the band shows it and what it points at, its text in /// `arena`. -const Row = struct { text: []const u8, key: u8 = 0, pre: u16 = 0, faint: u16 = 0, dim: bool = false, marks: []const u16 = &.{}, target: Target = .none }; +const Row = struct { text: []const u8, key: u8 = 0, pre: u16 = 0, faint: u16 = 0, dim: bool = false, marks: []const u16 = &.{}, target: Target = .none, meta: []const u8 = "" }; fn rowAt(p: *Pardes, pk: *const Pick, arena: std.mem.Allocator, i: usize) !Row { const dir = pk.dir.slice(); @@ -552,7 +552,10 @@ fn rowAt(p: *Pardes, pk: *const Pick, arena: std.mem.Allocator, i: usize) !Row { const f = owner.file orelse return row; row.target = .{ .place = .{ .path = f.path, .at = .{ .line = cand.ref } } }; }, - .themes => {}, + // The theme in use says so, whichever the window wears (POLISH 12). + .themes => if (p.custom_theme == null and cand.ref == p.settings.theme) { + row.meta = "in use"; + }, // An action: its digit a key; its place the first line its edit // changes, which the body is moved to while it is previewed. .actions => { @@ -628,7 +631,9 @@ pub fn head(p: *Pardes, arena: std.mem.Allocator, pane: *Pane) !?TagState.Head { 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"); + try spans.append(arena, .{ .lo = hint, .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 = @intCast(ncells), .caret = caret }; } @@ -642,13 +647,15 @@ pub fn head(p: *Pardes, arena: std.mem.Allocator, pane: *Pane) !?TagState.Head { 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 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) { @@ -658,6 +665,7 @@ pub fn head(p: *Pardes, arena: std.mem.Allocator, pane: *Pane) !?TagState.Head { try text.appendSlice(arena, words.get(src).word); } }; + 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 }; } @@ -703,7 +711,7 @@ pub fn steps(p: *Pardes, arena: std.mem.Allocator) ![]Band.Step { const rows = try arena.alloc(Band.Row, w.hi - w.lo); for (rows, w.lo..) |*row, i| { const r = try rowAt(p, pk, arena, i); - row.* = .{ .text = r.text, .key = r.key, .on = i == s.rows.at, .mark = marked(pk, idOf(pk, i)) != null, .dim = r.dim, .pre = r.pre, .faint = r.faint, .marks = r.marks, .index = @intCast(i) }; + row.* = .{ .text = r.text, .key = r.key, .on = i == s.rows.at, .mark = marked(pk, idOf(pk, i)) != null, .dim = r.dim, .pre = r.pre, .faint = r.faint, .marks = r.marks, .index = @intCast(i), .meta = r.meta }; } out[0] = .{ .rows = rows }; return out; @@ -711,6 +719,47 @@ pub fn steps(p: *Pardes, arena: std.mem.Allocator) ![]Band.Step { // ---- the preview ---- +/// The line (from 0) pane `pane`'s body lands the live picker's cursor row +/// on, while it is that picker's landing pane previewing that row's file +/// (UX D7: drawn on the hit ground, body_layer.zig); null else. +pub fn landingLine(p: *Pardes, arena: std.mem.Allocator, pane: *const Pane) ?usize { + const pk = live(p) orelse return null; + // A theme or an action lands nowhere: the window wearing it, its + // edit on the Changes grounds are their previews. + if (!pk.previews or pk.landing != pane.serial or pk.source == .themes or pk.source == .actions) return null; + const s = &p.view().tag_state; + if (pk.shown != s.rows.at or count(p, pk) == 0) return null; + const row = rowAt(p, pk, arena, s.rows.at) catch return null; + const place = switch (row.target) { + .place => |t| t, + else => return null, + }; + const f = pane.file orelse return null; + if (!std.mem.eql(u8, f.path, place.path)) return null; + return @intCast(@max(0, pane.body.cur_row)); +} + +/// The notice row's sentence while a picker previews (UX D7), written to +/// `w`: where Enter lands (`here`, or the owner's reader by its address, +/// a word to Look at), that the body is the preview, and Shift-Enter's new +/// pane; the address's bytes in what was written, or null with no picker +/// previewing. +pub fn sentence(p: *const Pardes, w: *std.Io.Writer) ?[2]usize { + const pk = live(p) orelse return null; + if (!pk.previews or pk.source == .themes or pk.source == .actions) return null; + if (pk.landing == pk.owner) { + w.writeAll("⏎ lands here") catch return null; + } else { + w.writeAll("⏎ lands in ") catch return null; + } + const lo = w.end; + if (pk.landing != pk.owner) w.print("@p{d}", .{pk.owner}) catch return null; + const hi = w.end; + if (pk.landing != pk.owner) w.writeAll("'s reader") catch return null; + w.writeAll(" · its text is the preview · S-⏎ a new pane") catch return null; + return .{ lo, hi }; +} + /// The landing pane's body showing the current row's place (SPEC §5.3): /// a file at its line, the query's matches lit for a Grep. Its own text is /// set aside the first time, put back when the picker rolls up. A file an @@ -776,7 +825,7 @@ fn preview(p: *Pardes, pk: *Pick) void { pane.body.cur_col = 0; return; } - look.focusPaneLine(p, id, at, .center); + look.focusPaneLine(p, id, at, .third); // A Grep's matches in the file lit, as its own pane would have them. if (pk.source == .grep) pane.places.search(p, pane, .list, pk.id, std.mem.trim(u8, s.field.text(), " "), true, null, false); } @@ -2135,6 +2184,13 @@ test "code actions: a picker in the asking pane's tag, the one under the cursor try std.testing.expectEqual(pardes.Color{ .rgb = grounds.del.row }, shot.at(x, y + 1).style.bg); try std.testing.expectEqual(pardes.Color{ .rgb = grounds.add.row }, shot.at(x, y + 2).style.bg); try std.testing.expectEqualStrings("one\ntwo add\nthree\n", pane.file.?.content); + // An action lands nowhere: no landing line, no `▸` before the line it + // changes, no sentence of where Enter lands (UX D7's are a jump's; an + // action's preview is its edit on the Changes grounds). + try std.testing.expect(landingLine(p, frame.allocator(), pane) == null); + try std.testing.expect(!std.mem.eql(u8, "▸", shot.at(x - 1, y + 1).grapheme())); + var notice: [pardes.Messages.notice_row_cap]u8 = undefined; + try std.testing.expect(!pardes.Messages.noticeRow(p, 100, ¬ice).quiet_left); // Up: the line put in at the top, before line 1, nothing deleted. p.update(.{ .key = .{ .cp = Key_.up } }); settle(p); @@ -2146,6 +2202,7 @@ test "code actions: a picker in the asking pane's tag, the one under the cursor try std.testing.expectEqual(pardes.Color{ .rgb = grounds.add.row }, shot.at(x, y).style.bg); try std.testing.expectEqualStrings("o", shot.at(x, y + 1).grapheme()); try std.testing.expect(!std.meta.eql(pardes.Color{ .rgb = grounds.del.row }, shot.at(x, y + 1).style.bg)); + try std.testing.expect(!std.meta.eql(pardes.Color{ .rgb = p.chromeTheme().roles.hit }, shot.at(x, y + 1).style.bg)); // `3`: the rename applied, the tag at rest; one undo takes it back. p.update(.{ .key = .{ .cp = '3', .text = "3" } }); try std.testing.expectEqual(TagState.Kind.rest, s.kind); @@ -2160,3 +2217,111 @@ test "code actions: a picker in the asking pane's tag, the one under the cursor try std.testing.expectEqualStrings("one\ntwo add\nthree\n", pane.file.?.content); try std.testing.expectEqualStrings("Actions: extract: no edit to apply", p.messages.saidBy(pane)); } + +test "the themes picker marks the theme in use: `in use` at its row's right end in the dim ink, the cursor on it when it opens, the mark staying on it while the window wears another (POLISH 12, UX A15)" { + const Key_ = pardes.Key; + const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 120, .rows = 40 }); + defer p.deinit(); + const pane = try p.setTestFile("one\n"); + const id = p.view().active; + var frame = std.heap.ArenaAllocator.init(std.testing.allocator); + defer frame.deinit(); + const a = frame.allocator(); + const was = p.settings.theme; + for (" tt") |c| p.update(.{ .key = .{ .cp = c } }); + const s = &p.view().tag_state; + try std.testing.expectEqual(@as(u16, @intCast(was)), s.rows.at); + const Find = struct { + fn row(band: Band, text: []const u8) ?Band.Row { + for (band.steps[0..band.nsteps]) |step| for (step.rows) |r| if (std.mem.eql(u8, r.text, text)) return r; + return null; + } + }; + var band = (try Band.of(p, a, pane, id)).?; + const worn = Find.row(band, pardes.colors.themes[was].name).?; + try std.testing.expectEqualStrings("in use", worn.meta); + try std.testing.expect(worn.on); + // One row says it. + var said: usize = 0; + for (band.steps[0..band.nsteps]) |step| for (step.rows) |r| { + said += @intFromBool(r.meta.len > 0); + }; + try std.testing.expectEqual(@as(usize, 1), said); + // Drawn at the row's right end, in the dim ink of the selection it is on. + _ = try p.render(a); + const layer = &p.surface.tag_layers[pardes.BAND_LAYER]; + const roles = &p.chromeTheme().roles; + const on = roles.selectedOn(if (pardes.Trail.reading(p, pane)) .reading_focused else .focused); + var found = false; + for (0..layer.rows) |row| { + const cells = layer.cells[row * layer.cols ..][0..layer.cols]; + var at: usize = 0; + while (at + 6 <= cells.len) : (at += 1) { + if (!std.mem.eql(u8, cells[at].grapheme(), "i") or !std.mem.eql(u8, cells[at + 1].grapheme(), "n") or !std.mem.eql(u8, cells[at + 3].grapheme(), "u")) continue; + try std.testing.expectEqual(pardes.Color{ .rgb = on.dim }, cells[at].style.fg); + found = true; + } + } + try std.testing.expect(found); + // The window wearing the next: the mark stays on the theme in use. + p.update(.{ .key = .{ .cp = if (was + 1 < pardes.colors.themes.len) Key_.down else Key_.up } }); + band = (try Band.of(p, a, pane, id)).?; + try std.testing.expectEqualStrings("in use", Find.row(band, pardes.colors.themes[was].name).?.meta); +} + +test "a picker's preview is legible as one (UX D7): its landing line on the hit ground with `▸` in the gutter, a third of the body above it, and the notice row saying where Enter lands" { + const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 140, .rows = 50 }); + defer p.deinit(); + p.settings.jumps = .walk; + var tmp = std.testing.tmpDir(.{}); + defer tmp.cleanup(); + var text: std.ArrayList(u8) = .empty; + defer text.deinit(std.testing.allocator); + for (1..81) |i| try text.print(std.testing.allocator, "line {d} of the file\n", .{i}); + const path = try testFile(p, &tmp, "long.zig", text.items); + defer p.gpa.free(path); + _ = try p.setTestFile("held\n"); + const asker = p.view().active; + Trail.keep(p.panes[asker].?); + const rows = try std.fmt.allocPrint(std.testing.allocator, "{s}:40:6 line 40 of the file\n", .{path}); + defer std.testing.allocator.free(rows); + open(p, asker, .list, "Refs", "", rows); + const pk = live(p).?; + const reader = p.paneBySerial(pk.landing).?; + p.update(.tick); + const pane = p.panes[reader].?; + try std.testing.expectEqualStrings(path, pane.file.?.path); + var frame = std.heap.ArenaAllocator.init(std.testing.allocator); + defer frame.deinit(); + const s = try p.render(frame.allocator()); + const r = p.view().rects[reader]; + const body_y = p.bodyTop(pane, r); + // Line 40 a third of the way down: ⌈rows/3⌉ rows of context above it. + var at: ?u16 = null; + for (0..pane.rows) |row| if (pane.wrapAt(p.settings.tab, @intCast(row)).line == 39) { + at = @intCast(row); + break; + }; + try std.testing.expectEqual(@as(?u16, @intCast((pane.rows + 2) / 3)), at); + const y = body_y + at.?; + const roles = &p.chromeTheme().roles; + const tx = r.x + pardes.config.GUTTER; + const gutter = File.gutterWidth(pane); + // Its text on the hit ground across the row; the row above as it was. + for (gutter..r.w - pardes.config.GUTTER) |x| try std.testing.expectEqual(pardes.Color{ .rgb = roles.hit }, s.at(tx + @as(u16, @intCast(x)), y).style.bg); + try std.testing.expect(!std.meta.eql(s.at(tx + gutter + 2, y - 1).style.bg, pardes.Color{ .rgb = roles.hit })); + // `▸` in the key ink in the gutter's cell after the number. + const mark = s.at(tx + gutter - 1, y); + try std.testing.expectEqualStrings("▸", mark.grapheme()); + try std.testing.expectEqual(pardes.Color{ .rgb = roles.key }, mark.style.fg); + // The notice row: where Enter lands, the owner's address a word in it. + var buf: [pardes.Messages.notice_row_cap]u8 = undefined; + const said = pardes.Messages.noticeRow(p, 120, &buf); + const want = try std.fmt.allocPrint(frame.allocator(), "⏎ lands in @p{d}'s reader · its text is the preview · S-⏎ a new pane", .{p.panes[asker].?.serial}); + try std.testing.expect(std.mem.startsWith(u8, said.text, want)); + try std.testing.expect(said.quiet_left); + try std.testing.expectEqualStrings(try std.fmt.allocPrint(frame.allocator(), "@p{d}", .{p.panes[asker].?.serial}), said.text[said.word[0]..said.word[1]]); + // At rest: no ground, no mark, the row back to its own. + p.update(.{ .key = .{ .cp = pardes.Key.escape } }); + try std.testing.expect(!pardes.Messages.noticeRow(p, 120, &buf).quiet_left); +} |
