summaryrefslogtreecommitdiff
path: root/core/Band.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-25 04:51:32 -0300
committerGabriel Schneider <[email protected]>2026-11-25 04:57:31 -0300
commit01ce658c7b40997e24ce5045b0e07f7b9ae98e71 (patch)
tree84ae35642444bb5005ca8fa9da169e7f95ef1d49 /core/Band.zig
parent3c4b2c99b1a969abad0a530fa99b70b2cb564af3 (diff)
downloadpardes-01ce658c7b40997e24ce5045b0e07f7b9ae98e71.tar.gz
pardes-01ce658c7b40997e24ce5045b0e07f7b9ae98e71.zip
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)
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.zig77
1 files changed, 76 insertions, 1 deletions
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);
+}