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/Band.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/Band.zig')
| -rw-r--r-- | core/Band.zig | 125 |
1 files changed, 120 insertions, 5 deletions
diff --git a/core/Band.zig b/core/Band.zig index 835c249f..5ddbe5af 100644 --- a/core/Band.zig +++ b/core/Band.zig @@ -39,6 +39,9 @@ pub const Row = struct { on: bool = false, /// Its first `key` bytes are a key: the key ink, bold. key: u8 = 0, + /// Its first `chord` bytes are a chord (Help's `SPC h t`): the key ink + /// at the text's weight. + chord: u8 = 0, dim: bool = false, /// The leaf its group ran last. under: bool = false, @@ -53,6 +56,14 @@ pub const Row = struct { /// tint; the `faint` bytes after them dimmed (a path's directory). pre: u16 = 0, faint: u16 = 0, + /// Said at the row's right end in the dim ink, two cells off its text + /// at least, and the first to give way (UX D5): `in use`. + meta: []const u8 = "", + /// Its bytes `quiet[0]..quiet[1]` in the dim ink: an empty register's + /// `—`, a value's `⏎`. + quiet: [2]u16 = .{ 0, 0 }, + /// Bytes that are keys, each in the key ink, bold: a register's verbs. + keys: []const u16 = &.{}, }; /// A column of rows. A level of more than 9 rows flows into two columns @@ -205,7 +216,9 @@ fn helpSteps(band: *Band, p: *Pardes, arena: std.mem.Allocator, s: *const TagSta const low = try std.ascii.allocLowerString(arena, leaf.row); _ = Names.match(q, leaf.row, low, 0, &marks, &nmarks); } - row.* = .{ .text = leaf.row, .on = i == s.rows.at, .marks = try arena.dupe(u16, marks[0..nmarks]), .index = @intCast(i), .dim = bindings.dimmed(p.panes[p.view().active].?, leaf.child) }; + // Its chord (`SPC h t`, before the first ` · `) in the key ink. + const chord = std.mem.indexOf(u8, leaf.row, " · ") orelse 0; + row.* = .{ .text = leaf.row, .on = i == s.rows.at, .chord = @intCast(@min(chord, 255)), .marks = try arena.dupe(u16, marks[0..nmarks]), .index = @intCast(i), .dim = bindings.dimmed(p.panes[p.view().active].?, leaf.child) }; } band.add(.{ .rows = rows }); var buf: [TagState.row_max]u8 = undefined; @@ -213,6 +226,18 @@ fn helpSteps(band: *Band, p: *Pardes, arena: std.mem.Allocator, s: *const TagSta band.add(try docStep(p, arena, at.root, at.path[0 .. at.path.len - 1], at.child)); } +/// What a register's doc step offers next, its letters keys (UX D11). +const verbs = "p after P before R replace y into"; +const verb_keys = blk: { + var out: [4]u16 = undefined; + var n: usize = 0; + for (0..verbs.len) |i| if (i == 0 or (i >= 2 and std.mem.eql(u8, verbs[i - 2 .. i], " "))) { + out[n] = i; + n += 1; + }; + break :blk out; +}; + /// `"` unrolled (SPEC §9): the registers, a row each (its key, what it /// is, its first line) around the cursor, or under `"a` its verbs; beside /// them the value of the one on the cursor (or named) in full, as many of @@ -230,17 +255,25 @@ fn registerSteps(band: *Band, p: *Pardes, arena: std.mem.Allocator, pane: *const if (path.len > 0) band.add(try levelStep(arena, pane, level, at, used)) else { const w = (Cursor{ .at = @intCast(at) }).window(@intCast(level.len)); const rows = try arena.alloc(Row, w.hi - w.lo); + // A row each (UX D11): `key value`, its name at the right; an + // empty one's `—` and a newline's `⏎` dim. for (rows, w.lo..) |*row, i| { const c = level[i]; const name = for (bindings.register_names) |r| { if (r.key == c.key) break r.name; } else "named"; + const key = bindings.keyName(c.key); + const shown = try bindings.registerShown(arena, p.settings.tab, bindings.registerValue(p, c.key)); + const text = try std.fmt.allocPrint(arena, "{s} {s}", .{ key, shown }); + const quiet = if (std.mem.eql(u8, shown, "—")) key.len + 2 else if (std.mem.endsWith(u8, shown, "⏎")) text.len - "⏎".len else text.len; row.* = .{ - .text = try std.fmt.allocPrint(arena, "{s} {s: <17} {s}{s}", .{ bindings.keyName(c.key), name, c.label, if (c.more) "…" else "" }), + .text = text, .on = i == at, - .key = 1, + .key = @intCast(key.len), .under = c.key == used, .index = @intCast(i), + .meta = name, + .quiet = .{ @intCast(quiet), @intCast(text.len) }, }; } band.add(.{ .rows = rows }); @@ -266,7 +299,7 @@ fn registerSteps(band: *Band, p: *Pardes, arena: std.mem.Allocator, pane: *const try rows.append(arena, .{ .text = look[0..end] }); rest = rest[end + 1 ..]; } - if (path.len == 0) try rows.append(arena, .{ .text = "next p after P before R replace y into", .dim = true }); + if (path.len == 0) try rows.append(arena, .{ .text = verbs, .dim = true, .keys = &verb_keys }); band.add(.{ .rows = rows.items, .doc = true }); } @@ -351,6 +384,8 @@ pub fn docStep(p: *Pardes, arena: std.mem.Allocator, root: bindings.Root, path: .role => bindings.docOf(root, c, try arena.alloc(u8, 160)), } else bindings.docOf(root, c, &.{}); try rows.append(arena, .{ .text = doc }); + // A leaf a language server answers, in a pane with none (SPEC §4.2). + if (bindings.dimmed(p.panes[p.view().active].?, c)) try rows.append(arena, .{ .text = "needs a language server", .dim = true }); var buf: [64]u8 = undefined; const here = try std.mem.concat(arena, u8, &.{ path, &.{c.key} }); try rows.append(arena, .{ .text = try std.fmt.allocPrint(arena, "keys {s}", .{bindings.chord(root, here, &buf)}) }); @@ -368,7 +403,7 @@ fn place(band: *Band, p: *Pardes, arena: std.mem.Allocator, pane: *Pane, id: usi for (band.steps[0..band.nsteps]) |*step| { if (step.doc) continue; var widest: usize = 0; - for (step.rows) |row| widest = @max(widest, File.displayWidth(tab, row.text)); + for (step.rows) |row| widest = @max(widest, File.displayWidth(tab, row.text) + if (row.meta.len > 0) 2 + File.displayWidth(tab, row.meta) else 0); const column: u16 = @intCast(@min(widest + 2, std.math.maxInt(u16) / 4, @max(min_width, band.columns -| x))); step.width = if (step.two) 2 * column + 1 else column; need += step.width + 2; @@ -486,14 +521,26 @@ pub fn line(band: *const Band, arena: std.mem.Allocator, tab: u16, y: u16) !Line col += @intCast(File.displayWidth(tab, lead)); try parts.append(arena, .{ .col = col, .width = per -| @as(u16, @intCast(File.displayWidth(tab, lead))), .row = row }); const room = per -| @as(u16, @intCast(File.displayWidth(tab, lead))); + const at = col; const cut = File.byteAtDisplay(tab, row.text, room); try text.appendSlice(arena, row.text[0..cut]); col += @intCast(File.displayWidth(tab, row.text[0..cut])); + if (metaShown(tab, row, room)) { + const meta: u16 = @intCast(File.displayWidth(tab, row.meta)); + while (col < at + room - meta) : (col += 1) try text.append(arena, ' '); + try text.appendSlice(arena, row.meta); + col += meta; + } } } return .{ .text = text.items, .parts = parts.items }; } +/// Whether row `row`'s meta fits `room` cells after its text. +pub fn metaShown(tab: u16, row: Row, room: u16) bool { + return row.meta.len > 0 and File.displayWidth(tab, row.text) + 2 + File.displayWidth(tab, row.meta) <= room; +} + /// The word under column `col` of band row `y` of pane `id`, at the /// tagline's pitch: what B2 executes and B3 looks at. pub fn wordAt(p: *Pardes, arena: std.mem.Allocator, id: usize, y: u16, col: u16) !?[]const u8 { @@ -653,3 +700,71 @@ test "a doc's paragraphs are rows of their own: no newline in a band's row" { }; try std.testing.expect(docs > 2); } + +test "a band is drawn in the theme's roles (UX D4): spines in the rule ink, a chord in the key ink, a matched letter bold in the match ink on its row's own ground, the cursor row's too; an LSP leaf with no server in the dim ink, never faint, its doc saying why" { + const Key = pardes.Key; + const Cells = struct { + /// The cell `word` starts at, a grapheme a cell. + fn find(cells: []const pardes.Cell, word: []const u8) ?usize { + var at: usize = 0; + while (at + word.len <= cells.len) : (at += 1) { + for (word, cells[at..][0..word.len]) |c, cell| { + if (cell.len != 1 or cell.text[0] != c) break; + } else return at; + } + return null; + } + }; + const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 140, .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 roles = &p.chromeTheme().roles; + const inks = roles.on(if (pardes.Trail.reading(p, pane)) .reading_focused else .focused); + const selected = roles.selectedOn(if (pardes.Trail.reading(p, pane)) .reading_focused else .focused); + // Help with `wrap` typed: `▶ SPC t w · Wrap · view` on the cursor row. + for ([_]u21{ ' ', '?', 'w', 'r', 'a', 'p' }) |c| p.update(.{ .key = .{ .cp = c } }); + _ = try p.render(a); + var layer = bandLayer(p, id).?; + var spines: usize = 0; + var cursor_row: ?usize = null; + for (0..layer.rows) |row| for (layer.cells[row * layer.cols ..][0..layer.cols]) |cell| { + try std.testing.expect(!cell.style.dim); + if (std.mem.eql(u8, cell.grapheme(), "│")) { + try std.testing.expectEqual(pardes.Color{ .rgb = inks.rule }, cell.style.fg); + spines += 1; + } + if (std.mem.eql(u8, cell.grapheme(), "▶")) cursor_row = row; + }; + try std.testing.expect(spines > 0); + const on = layer.cells[cursor_row.? * layer.cols ..][0..layer.cols]; + const s_cell = on[Cells.find(on, "SPC t w").?]; + try std.testing.expectEqual(pardes.Color{ .rgb = roles.key }, s_cell.style.fg); + try std.testing.expect(!s_cell.style.bold); + var matched: usize = 0; + for (on) |cell| if (std.meta.eql(cell.style.fg, pardes.Color{ .rgb = roles.match })) { + try std.testing.expect(cell.style.bold); + try std.testing.expectEqual(pardes.Color{ .rgb = selected.ground }, cell.style.bg); + matched += 1; + }; + try std.testing.expect(matched >= 4); + p.update(.{ .key = .{ .cp = Key.escape } }); + // SPC l unrolled in a text file no server speaks for: its leaves dim. + for ([_]u21{ ' ', 'l', Key.down }) |c| p.update(.{ .key = .{ .cp = c } }); + _ = try p.render(a); + layer = bandLayer(p, id).?; + var dimmed: usize = 0; + var why = false; + for (0..layer.rows) |row| { + const cells = layer.cells[row * layer.cols ..][0..layer.cols]; + if (Cells.find(cells, "needs a language server") != null) why = true; + const cell = cells[Cells.find(cells, "Hover") orelse continue]; + try std.testing.expect(!cell.style.dim); + try std.testing.expectEqual(pardes.Color{ .rgb = inks.dim }, cell.style.fg); + dimmed += 1; + } + try std.testing.expect(dimmed > 0 and why); +} |
