From 01ce658c7b40997e24ce5045b0e07f7b9ae98e71 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Wed, 25 Nov 2026 04:51:32 -0300 Subject: colors, draw, Band: the walk UI's colour roles (UX DESIGN.md D4): text, dim, rule on each of a tag's four grounds (plain, focused, reading, reading focused) and on each one's cursor-row selection, key, match, hit, hit current, err/warn/question/hint, worked out once a theme with its chrome (ChromeTheme.roles, Roles.of; never a frame) and each held to its floor where it is drawn (text 4.5:1, dim 3.5 never under 3, rule 2:1, key and match 4.5:1 on every tag ground and selection, selection 1.4:1 off a dark tag and 1.25 off a light one with its text at 4.5, hit 1.25 and current 1.6 off the page with the body's ink at 4.5, a message's ink 4.5 on the tags and the page; where a theme's own colours leave no room, the most they allow: solarized's mid-grey tag, a tag whose text has no contrast to spare); the reading tint derived as D4 says (the theme's own where it stands 0.04 off the tag in OKLab, else the tag toward paper yellow by 0.04 and 0.02 lighter on a dark tag, darker on a light one, less or the other way where its text would drop under 7:1 or its own, further where the bytes cannot show the step): neonotte84's #262737 (0.029 off its tag, invisible) is #29271d now; and every painter of the new UI on them: the band's spines and step rules in the rule ink (they were the box's 11.5:1, the brightest thing in the band), `▶` and `•` in the key ink, a key bold in it, Help's chord (`SPC h t`, Row.chord) in it at the text's weight, a matched letter bold in the match ink on its row's own ground (it was the search ground, the selection's colour on neonotte84: on the cursor row the matches vanished), a dim row and a path's directory in the dim ink of their ground (the cursor row's selection's on it), never the faint attribute (fg 12.5:1 fell to 4.5 and a dimmed register value to 1.58); the head's dim spans in the dim ink, a key bold in the key ink, an error in the err role, the picker's act-row spines in the rule ink (TagState.Style.rule), its other sources' words, its `|` and the themes' hint dim, the levels', describe-key's and Rename's hints dim (they were at full label ink, louder than the content), the head's text in the text role (at rest the tag keeps its own ink: byte for byte); a walk's forward steps and a search word no place lights in the dim ink (they were the line numbers' ink, 1.57:1 on a reading tag); Messages.ink is the roles' (marks, end-of-line ghosts, progress); an LSP leaf in a pane no language server speaks for is dim and its doc step says `needs a language server` (POLISH 3; SPEC §4.2); UX's derived values reproduced (tools/roles.py: neonotte84's text, dim #70768f, rule #4c5063, key, match #f1a271, reading, hit #36282a, current #523831 within 2 a channel; acme's dim, rule, reading, hit, current; acme's key #555583 and match #8f4800 a step darker than UX's #5c5c8d and #974d00, which hold on its tag and #9eeeee: a reading pane's band's selection is pushed off #f3f0cc, 1.12:1, and they read on it too); TEST FIRST: Band.zig "a band is drawn in the theme's roles" (fails on the base painter at its first spine: the box's ink), draw.zig "a tag out of rest draws its keys bold in the key ink and its hint in the dim ink, never faint", colors.zig "every theme's walk UI roles meet their floors" (every bundled theme, dark and light, every floor; 497 floors missed by the first derivation, each class fixed by the rule above) and "neonotte84's and acme's roles are the ones UX derived"; Trail.zig's §6.7 session test now wants the forward step in the dim ink; core-test 1066/1236 (170 skipped) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_016Y9MNBFhdevVu48bvL9kCE --- core/Band.zig | 77 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 76 insertions(+), 1 deletion(-) (limited to 'core/Band.zig') diff --git a/core/Band.zig b/core/Band.zig index 835c249f..a8d97bb4 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, @@ -205,7 +208,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; @@ -351,6 +356,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)}) }); @@ -653,3 +660,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); +} -- cgit v1.3 From 0e6c60d17dd5f0e48232a46096e3a7a92f8841cf Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Wed, 25 Nov 2026 05:27:43 -0300 Subject: Pick, Band, draw: the themes picker marks the theme in use (POLISH 12, UX DESIGN.md A15): its row says `in use` at its right end in the dim ink, whichever theme the window wears under the cursor, and the cursor opens on it as before; a band row's meta (Band.Row.meta: said right-aligned in its part, two cells off its text at least, the first to give way, as D5 asks; the step as wide as text and meta; Band.metaShown says whether it fits, so Band.line and draw.zig joinBand agree), placed from the part's own column (a step's rows start where the spines leave off, not always at its x); TEST FIRST: Pick.zig "the themes picker marks the theme in use" (fails without the mark at its `in use`; it holds the row's meta, one row only, the cells' dim ink on the cursor row's selection, and the mark staying on the theme in use while the window wears the next); core-test 1068/1238 (170 skipped) Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_016Y9MNBFhdevVu48bvL9kCE --- core/Band.zig | 17 ++++++++++++++++- core/Pick.zig | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++--- core/draw.zig | 5 +++++ 3 files changed, 78 insertions(+), 4 deletions(-) (limited to 'core/Band.zig') diff --git a/core/Band.zig b/core/Band.zig index a8d97bb4..e562da1d 100644 --- a/core/Band.zig +++ b/core/Band.zig @@ -56,6 +56,9 @@ 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 = "", }; /// A column of rows. A level of more than 9 rows flows into two columns @@ -375,7 +378,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; @@ -493,14 +496,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 { diff --git a/core/Pick.zig b/core/Pick.zig index 6026f11b..cb5f605d 100644 --- a/core/Pick.zig +++ b/core/Pick.zig @@ -458,7 +458,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, pre: u16 = 0, faint: u16 = 0, dim: bool = false, marks: []const u16 = &.{}, target: Target = .none }; +const Row = struct { text: []const u8, 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(); @@ -526,7 +526,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"; + }, .recent, .jumplist, .list, .grep, .all => { const t = look.parsePathLine(text); row.pre = @intCast(t.end); @@ -669,7 +672,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, .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, .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; @@ -1930,3 +1933,54 @@ test "n and N walk the newest list or search word, or the one Looked at (SPEC § p.update(.{ .key = .{ .cp = 'n', .text = "n" } }); try std.testing.expect(pane.places.current != null and !std.meta.eql(was, pane.places.current)); } + +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); +} diff --git a/core/draw.zig b/core/draw.zig index 673d3386..9f9abb58 100644 --- a/core/draw.zig +++ b/core/draw.zig @@ -945,6 +945,11 @@ fn joinBand(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, r: R }; b = next; } + // Its meta, right-aligned in the part (Band.line), dim. + if (pardes.Band.metaShown(tab, part.row, part.width) and part.col + part.width <= columns) { + const meta: u16 = @intCast(panes.File.displayWidth(tab, part.row.meta)); + for (part.col + part.width - meta..part.col + part.width) |x| t.at(@intCast(x), row).style.fg = .{ .rgb = on.dim }; + } } } const count = @as(usize, columns) * rows; -- cgit v1.3 From 038a94400d668406ed5fab9ad8c00e064365dbb1 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Wed, 25 Nov 2026 05:32:50 -0300 Subject: bindings, TagState, Band, draw: the registers as UX DESIGN.md D11 rules them: rolled, only the registers holding something (six of S's eleven items were `—`), each `key value` with its value in 20 cells at most (bindings.registerShown: its first line, a path cut from the left, `…proj/core/Query.zig`, where the useless end was cut before, other text from the right, `const best = rank(q…`, a newline that ends what shows said by a dim `⏎`, the value stopping there); unrolled, every register a row `key value` (the key bold in the key ink, the value in the text's, `—` for an empty one in the dim ink) with its name at the row's right end in the dim ink (Band.Row.meta), where the fixed name was at full ink and the value, the content, at 1.58:1; the doc step's verbs `p after P before R replace y into` dim with their letters bold in the key ink (Band.Row.keys; `next` gone); Band.Row.quiet, a byte range in the dim ink; TEST FIRST: bindings.zig's registers test holds D11 (fails on the parent at its rolled level, which shows `a const best = rank(q, nam… / —`): the rolled level with a path and a newline among its registers and the dim `⏎`, the unrolled rows, the empty register's `—` and the names in the dim ink, the verbs' letters bold in the key ink; core-test 1068/1238 (170 skipped) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_016Y9MNBFhdevVu48bvL9kCE --- core/Band.zig | 31 +++++++++++++++++++++--- core/TagState.zig | 20 ++++++++++++---- core/bindings.zig | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++----- core/draw.zig | 6 ++++- 4 files changed, 113 insertions(+), 14 deletions(-) (limited to 'core/Band.zig') diff --git a/core/Band.zig b/core/Band.zig index e562da1d..5ddbe5af 100644 --- a/core/Band.zig +++ b/core/Band.zig @@ -59,6 +59,11 @@ pub const Row = struct { /// 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 @@ -221,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 @@ -238,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 }); @@ -274,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 }); } diff --git a/core/TagState.zig b/core/TagState.zig index 0a59bd08..7a34ed77 100644 --- a/core/TagState.zig +++ b/core/TagState.zig @@ -588,19 +588,31 @@ pub fn head(p: *Pardes, arena: std.mem.Allocator, pane: *Pane) !?Head { var children: [bindings.max_children]bindings.Child = undefined; const level = bindings.level(p, cur.root, cur.path, &children); const used = s.used[node.group]; + // The registers rolled (UX D11): the ones holding something, each its + // value as a row shows it, a newline's `⏎` dim. + const registers = cur.root == .register and cur.path.len == 0; var width = panes.File.displayWidth(tab, b.text.items); + var put: usize = 0; for (level, 0..) |c, i| { - width += @as(usize, if (i == 0) 1 else 2) + panes.File.displayWidth(tab, bindings.keyName(c.key)) + 1 + panes.File.displayWidth(tab, c.label) + @intFromBool(c.group); + const value = if (registers) bindings.registerValue(p, c.key) else ""; + if (registers and value.len == 0) continue; + const label = if (registers) try bindings.registerShown(arena, tab, value) else c.label; + const cut = c.group or (c.more and !registers); + width += @as(usize, if (put == 0) 1 else 2) + panes.File.displayWidth(tab, bindings.keyName(c.key)) + 1 + panes.File.displayWidth(tab, label) + @intFromBool(cut); if (width + @as(usize, if (i + 1 < level.len) panes.File.displayWidth(tab, more) else 0) > room) { try b.put(more); break; } - try b.put(if (i == 0) " " else " "); + try b.put(if (put == 0) " " else " "); + put += 1; const lo: u32 = @intCast(b.text.items.len); try b.styled(bindings.keyName(c.key), .key); try b.put(" "); - try b.put(c.label); - if (c.group or c.more) try b.put("…"); + if (registers and std.mem.endsWith(u8, label, "⏎")) { + try b.put(label[0 .. label.len - "⏎".len]); + try b.styled("⏎", .dim); + } else try b.put(label); + if (cut) try b.put("…"); const hi: u32 = @intCast(b.text.items.len); if (bindings.dimmed(pane, c)) try b.spans.append(arena, .{ .lo = lo, .hi = hi, .style = .dim }); if (c.key == used) try b.spans.append(arena, .{ .lo = lo, .hi = hi, .style = .under }); diff --git a/core/bindings.zig b/core/bindings.zig index 2df51945..96ce1359 100644 --- a/core/bindings.zig +++ b/core/bindings.zig @@ -338,8 +338,30 @@ pub const register_names = [_]struct { key: u8, name: []const u8 }{ }; /// The display columns of a register's first line which-key shows; the -/// rest is `…`. -pub const register_cut = 24; +/// rest is `…` (UX D11: 20 cells, the `…` among them). +pub const register_cut = 20; + +/// A register's value as a row shows it (UX D11): its first line in +/// `register_cut` cells at most, a path cut from the left +/// (`…core/Query.zig`), other text from the right (`…` after it), a newline +/// that ends what shows said `⏎`; `—` when it holds nothing. Only its first +/// `4 * register_cut` bytes are read. +pub fn registerShown(arena: std.mem.Allocator, tab: u16, value: []const u8) ![]const u8 { + if (value.len == 0) return "—"; + const bound = if (value.len > 4 * register_cut) modal.graphemeStart(value, 4 * register_cut) else value.len; + const newline = std.mem.indexOfScalar(u8, value[0..bound], '\n'); + const line = value[0 .. newline orelse bound]; + const width = File.displayWidth(tab, line); + if (width <= register_cut and line.len == value.len) return line; + if (width < register_cut and newline != null) return std.mem.concat(arena, u8, &.{ line, "⏎" }); + // A path: one line, no spaces, a slash in it; its end says which file. + if (newline == null and bound == value.len and std.mem.indexOfAny(u8, line, " \t") == null and std.mem.indexOfScalar(u8, line, '/') != null) { + var start = File.rawAtDisplay(tab, line, width - (register_cut - 1)); + if (File.rawDisplayCol(tab, line, start) < width - (register_cut - 1)) start = modal.nextGrapheme(line, start); + return std.mem.concat(arena, u8, &.{ "…", line[start..] }); + } + return std.mem.concat(arena, u8, &.{ line[0..File.byteAtDisplay(tab, line, register_cut - 1)], "…" }); +} /// `"`'s level: a child a register, its label the first line of its value /// (`—` when empty), cut. Read when the level is (a key, a frame), never @@ -553,13 +575,15 @@ test "Help's rows: every leaf of every root, spelled as its chord, its word and for (flat) |f| try std.testing.expectEqual(f.row.len, f.lower.len); } -test "\" shows the registers rolled, each its first line; Down unrolls them beside the cursor's value; a register's key goes down to its verbs, Backspace back up, p pastes it" { +test "\" shows the registers rolled, the ones holding something, each its value cut to 20 cells (a path from the left, a newline a dim ⏎); Down unrolls them all, `key value` with the name at the right, beside the cursor's value and its verbs, their keys in the key ink; a register's key goes down to its verbs, Backspace back up, p pastes it (UX D11)" { const tagline = @import("tagline.zig"); const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 160, .rows = 40 }); defer p.deinit(); const pane = try p.setTestFile("one\ntwo\n"); try p.registers.put(p.gpa, 'a', "const best = rank(q, name) orelse continue;\nreturn best;", 0, 1, true); try p.registers.put(p.gpa, '"', "self.dirty = true;", 0, 1, true); + try p.registers.put(p.gpa, 'n', "ab\ncd", 0, 1, true); + try p.registers.put(p.gpa, 'p', "/tmp/claude-1000/wuS/r/proj/core/Query.zig", 0, 1, true); var frame = std.heap.ArenaAllocator.init(std.testing.allocator); defer frame.deinit(); const a = frame.allocator(); @@ -573,8 +597,13 @@ test "\" shows the registers rolled, each its first line; Down unrolls them besi try std.testing.expectEqual(p.clock.now_ns + 300 * std.time.ns_per_ms, p.view().tag_state.due_ns); p.clock.now_ns = p.view().tag_state.due_ns; const rolled = try tagline.tagText(p, a, pane); - try std.testing.expect(std.mem.indexOf(u8, rolled, " \" ▸ \" self.dirty = true; a const best = rank(q, nam… / —") != null); - try std.testing.expect(std.mem.indexOf(u8, rolled, "% /test.txt . o # 1 _ —") != null); + try std.testing.expect(std.mem.indexOf(u8, rolled, " \" ▸ \" self.dirty = true; a const best = rank(q… n ab⏎ p …proj/core/Query.zig % /test.txt . o # 1 ") != null); + // Its ⏎ in the dim ink. + const h = (try @import("TagState.zig").head(p, a, pane)).?; + const nl = std.mem.indexOf(u8, h.text, "ab⏎").? + 2; + for (h.spans) |span| { + if (span.lo == nl) break try std.testing.expectEqual(.dim, span.style); + } else return error.NoDimNewline; // Down unrolls: a row each, the cursor on the default, its value // beside them. p.update(.{ .key = .{ .cp = Key.down } }); @@ -584,8 +613,37 @@ test "\" shows the registers rolled, each its first line; Down unrolls them besi const layer = &p.surface.tag_layers[pardes.BAND_LAYER]; var band: std.ArrayList(u8) = .empty; for (0..layer.rows) |row| for (layer.cells[row * layer.cols ..][0..layer.cols]) |cell| try band.appendSlice(a, cell.grapheme()); - try std.testing.expect(std.mem.indexOf(u8, band.items, "▶ \" yank self.dirty = true;") != null); + try std.testing.expect(std.mem.indexOf(u8, band.items, "▶ \" self.dirty = true;") != null); + try std.testing.expect(std.mem.indexOf(u8, band.items, "/ —") != null); try std.testing.expect(std.mem.indexOf(u8, band.items, "\"\" · yank") != null); + try std.testing.expect(std.mem.indexOf(u8, band.items, "p after P before R replace y into") != null); + // The empty register's `—` and the names in the dim ink, the verbs' + // letters bold in the key ink. + const roles = &p.chromeTheme().roles; + const inks = roles.on(if (pardes.Trail.reading(p, pane)) .reading_focused else .focused); + const Cells = struct { + fn at(l: *const pardes.Layer, word: []const u8) ?*const pardes.Cell { + for (0..l.rows) |row| { + const cells = l.cells[row * l.cols ..][0..l.cols]; + var x: usize = 0; + while (x + word.len <= cells.len) : (x += 1) { + for (word, cells[x..][0..word.len]) |c, cell| { + if (cell.len != 1 or cell.text[0] != c) break; + } else return &cells[x]; + } + } + return null; + } + }; + try std.testing.expectEqual(pardes.Color{ .rgb = inks.dim }, Cells.at(layer, "last search").?.style.fg); + const verbs = Cells.at(layer, "p after").?; + try std.testing.expectEqual(pardes.Color{ .rgb = roles.key }, verbs.style.fg); + try std.testing.expect(verbs.style.bold); + for (0..layer.rows) |row| { + const cells = layer.cells[row * layer.cols ..][0..layer.cols]; + for (cells, 0..) |cell, x| if (std.mem.eql(u8, cell.grapheme(), "—") and x > 2 and std.mem.eql(u8, cells[x - 3].grapheme(), "/")) + try std.testing.expectEqual(pardes.Color{ .rgb = inks.dim }, cell.style.fg); + } // The next row's value in full, every line of it. p.update(.{ .key = .{ .cp = Key.down } }); _ = frame.reset(.retain_capacity); diff --git a/core/draw.zig b/core/draw.zig index 9f9abb58..1e53d1d0 100644 --- a/core/draw.zig +++ b/core/draw.zig @@ -934,7 +934,11 @@ fn joinBand(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, r: R // A chord (Help's `SPC h t`): keys, at the text's weight. if (b < part.row.chord) style.fg = .{ .rgb = chrome.roles.key }; if (b < part.row.pre) style.fg = .{ .rgb = if (active) chrome.tag_active_name_fg else chrome.tag_name_fg }; - if (part.row.dim or (b >= part.row.pre and b < part.row.pre + part.row.faint)) style.fg = .{ .rgb = on.dim }; + if (part.row.dim or (b >= part.row.pre and b < part.row.pre + part.row.faint) or (b >= part.row.quiet[0] and b < part.row.quiet[1])) style.fg = .{ .rgb = on.dim }; + for (part.row.keys) |k| if (k == b) { + style.fg = .{ .rgb = chrome.roles.key }; + style.bold = true; + }; if (part.row.under) style.ul = .single; // A matched letter: the match ink, bold, on the row's own // ground (never a ground of its own: on the cursor row's -- cgit v1.3