diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-25 04:51:32 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-25 04:57:31 -0300 |
| commit | 01ce658c7b40997e24ce5045b0e07f7b9ae98e71 (patch) | |
| tree | 84ae35642444bb5005ca8fa9da169e7f95ef1d49 /core/draw.zig | |
| parent | 3c4b2c99b1a969abad0a530fa99b70b2cb564af3 (diff) | |
| download | pardes-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/draw.zig')
| -rw-r--r-- | core/draw.zig | 103 |
1 files changed, 83 insertions, 20 deletions
diff --git a/core/draw.zig b/core/draw.zig index 68778667..2fc69feb 100644 --- a/core/draw.zig +++ b/core/draw.zig @@ -883,13 +883,17 @@ fn joinBand(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, r: R const layer = &s.tag_layers[pardes.BAND_LAYER]; if (r.w <= TAG_TEXT_INSET) return; const band = (try pardes.Band.of(p, arena, pane, id)) orelse return; - const th = p.theme(); const chrome = p.chromeTheme(); const tab = p.settings.tab; const rows = pane.band_rows; const columns = @max(band.columns, 1); - const bg = tagGround(p, pane, active); - const fg = if (active) chrome.tag_active_fg else chrome.tag_fg; + // The walk UI's inks on this tag's ground (colors.Roles, UX DESIGN.md + // D4), and on its cursor row's selection. + const ground = groundOf(p, pane, active); + const inks = chrome.roles.on(ground); + const selected = chrome.roles.selectedOn(ground); + const bg = inks.ground; + const fg = inks.text; const storage = try arena.alloc(Cell, @as(usize, columns) * rows); @memset(storage, .{}); var t: Surface = .{ .cols = columns, .rows = rows, .cells = storage, .tab = tab }; @@ -898,32 +902,41 @@ fn joinBand(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, r: R t.fill(0, row, columns, 1, .{ .bg = .{ .rgb = bg }, .font_role = .tagline }); const ln = try band.line(arena, tab, row); _ = t.print(0, row, columns, ln.text, .{ .fg = .{ .rgb = fg }, .bg = .{ .rgb = bg }, .font_role = .tagline }); - // The spines and the rules between steps: the key ink. + // The spines and the rules between steps in the rule ink; a row's + // `▶` (the cursor) and `•` (marked) in the key ink. var col: u16 = 0; var at: usize = 0; while (at < ln.text.len and col < columns) : (col += 1) { const next = modal.nextGrapheme(ln.text, at); - if (std.mem.eql(u8, ln.text[at..next], "│")) t.at(col, row).style.fg = .{ .rgb = chrome.box }; - if (std.mem.eql(u8, ln.text[at..next], "▶")) t.at(col, row).style.fg = .{ .rgb = chrome.box }; + const glyph = ln.text[at..next]; + if (std.mem.eql(u8, glyph, "│")) t.at(col, row).style.fg = .{ .rgb = inks.rule }; + if (std.mem.eql(u8, glyph, "▶") or std.mem.eql(u8, glyph, "•")) t.at(col, row).style.fg = .{ .rgb = chrome.roles.key }; at = next; } for (ln.parts) |part| { const end = @min(columns, part.col + part.width); - if (part.row.on and part.col < end) t.tint(part.col, row, end - part.col, th.tag_sel_bg orelse th.sel_bg, th.sel_fg); + const on = if (part.row.on) selected else inks; + if (part.row.on and part.col < end) t.tint(part.col, row, end - part.col, selected.ground, selected.text); var c = part.col; var b: usize = 0; while (b < part.row.text.len and c < end) : (c += 1) { const next = modal.nextGrapheme(part.row.text, b); const style = &t.at(c, row).style; if (b < part.row.key) { - style.fg = .{ .rgb = chrome.box }; + style.fg = .{ .rgb = chrome.roles.key }; style.bold = true; } + // 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.dim = true; + 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.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 + // selection one vanished). for (part.row.marks) |m| if (m == b) { - style.bg = .{ .rgb = chrome.search_bg }; + style.fg = .{ .rgb = chrome.roles.match }; + style.bold = true; }; b = next; } @@ -967,9 +980,14 @@ fn inkTag(p: *Pardes, s: *Surface, shown: tagline.Shown, lines: []const []const /// A pane's tag's ground: a reading pane's tint (its focus is its grip's), /// else the focused tag's or the tag's. fn tagGround(p: *Pardes, pane: *const Pane, active: bool) [3]u8 { - const chrome = p.chromeTheme(); - if (pardes.Trail.reading(p, pane)) return chrome.tag_reading_bg; - return if (active) chrome.tag_active_bg else chrome.tag_bg; + return p.chromeTheme().roles.on(groundOf(p, pane, active)).ground; +} + +/// Which of a tag's grounds pane `pane`'s is: its walk UI inks +/// (colors.Roles) are that ground's. +fn groundOf(p: *Pardes, pane: *const Pane, active: bool) colors.TagGround { + if (pardes.Trail.reading(p, pane)) return if (active) .reading_focused else .reading; + return if (active) .focused else .plain; } fn paintPaneTag(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, r: Rect, id: usize, active: bool) !void { @@ -981,7 +999,8 @@ fn paintPaneTag(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, const rows = pane.tag_rows - pane.band_rows; const page_rgb = th.bg orelse th.tag_bg; // Focus is visible along the tag without changing its live text grid. - const tag_bg = tagGround(p, pane, active); + const inks = chrome.roles.on(groundOf(p, pane, active)); + const tag_bg = inks.ground; const tag_fg = if (active) chrome.tag_active_fg else chrome.tag_fg; const tag_style: CellStyle = .{ .fg = .{ .rgb = tag_fg }, .bg = .{ .rgb = tag_bg }, .font_role = .tagline }; // Padding belongs to the same font row but keeps its default ink: a @@ -995,6 +1014,8 @@ fn paintPaneTag(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, const head = try TagState.head(p, arena, pane); const tail = if (head) |h| h.text else tagline.curTail(pane); const prefix_len = whole.len - tail.len; + // Out of rest, the walk UI's text ink (at rest the tag's own, unchanged). + const text_style: CellStyle = if (head == null) tag_style else .{ .fg = .{ .rgb = inks.text }, .bg = .{ .rgb = tag_bg }, .font_role = .tagline }; // A row per line shown, from `tag_top`: the tag's first line carries // the prefix, the rest are the tag's own text alone. const top = pane.tag_top; @@ -1028,7 +1049,7 @@ fn paintPaneTag(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, for (lines[0..rows], 0..) |line, row| { // The scroll is the caret's line's: a shorter row shows nothing. const start = @min(line.len, panes.File.rawAtDisplay(p.settings.tab, line, pane.tag_scroll)); - _ = s.print(tx, tag_y + @as(u16, @intCast(row)), tw, line[start..], tag_style); + _ = s.print(tx, tag_y + @as(u16, @intCast(row)), tw, line[start..], text_style); } // The pane's progress at its first row's right end, where the row has // room for it (SPEC §10.2). @@ -1048,9 +1069,9 @@ fn paintPaneTag(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, inkTag(p, s, shown, lines[0..rows], top, tx, tag_y, tw, name.lo, @min(name.hi, first_line.len), if (active) chrome.tag_active_name_fg else chrome.tag_name_fg); // A walk's forward steps, after the name, dimmed (Trail.zig). const ahead = tagline.forwardSpan(p, pane); - if (ahead[0] < ahead[1]) inkTag(p, s, shown, lines[0..rows], top, tx, tag_y, tw, ahead[0], @min(ahead[1], first_line.len), chrome.lineno); + if (ahead[0] < ahead[1]) inkTag(p, s, shown, lines[0..rows], top, tx, tag_y, tw, ahead[0], @min(ahead[1], first_line.len), inks.dim); // A search word its places no longer light, dimmed (Prompt.zig). - if (pardes.Prompt.unlit(p, pane)) |span| inkTag(p, s, shown, lines[0..rows], top, tx, tag_y, tw, span[0], @min(span[1], first_line.len), chrome.lineno); + if (pardes.Prompt.unlit(p, pane)) |span| inkTag(p, s, shown, lines[0..rows], top, tx, tag_y, tw, span[0], @min(span[1], first_line.len), inks.dim); // The head's keys in the key ink, its dimmed, underlined and struck // words (TagState.Span), over whichever rows they wrapped onto. if (head) |h| for (h.spans) |span| { @@ -1068,13 +1089,14 @@ fn paintPaneTag(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, const style = &s.at(tx + @as(u16, @intCast(col)), y).style; switch (span.style) { .key => { - style.fg = .{ .rgb = chrome.box }; + style.fg = .{ .rgb = chrome.roles.key }; style.bold = true; }, - .dim => style.dim = true, + .dim => style.fg = .{ .rgb = inks.dim }, .under => style.ul = .single, .strike => style.strikethrough = true, - .err => style.fg = .{ .rgb = chrome.diagnostic_error }, + .err => style.fg = .{ .rgb = chrome.roles.err }, + .rule => style.fg = .{ .rgb = inks.rule }, } } } @@ -1745,3 +1767,44 @@ test "progress is said at the right end of its tag: a pane's at its tag's, a ser s = try p.render(frame.allocator()); try std.testing.expect(std.mem.indexOf(u8, Row.of(s, tag_y, &buf), "\u{22ef}") == null); } + +test "a tag out of rest draws its keys bold in the key ink and its hint in the dim ink, never faint (UX D4)" { + const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 200, .rows = 30 }); + defer p.deinit(); + const pane = try p.setTestFile("one\n"); + 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); + // SPC's level rolled, after its delay: `␣ ▸ … l lsp… … ↓ unroll · ? help`. + p.clock.now_ns = 5 * std.time.ns_per_s; + p.clock.stepped_ns = p.clock.now_ns; + p.update(.{ .key = .{ .cp = ' ' } }); + p.advance(p.clock.now_ns); + p.clock.now_ns = p.view().tag_state.due_ns; + p.sync(); + const s = try p.render(a); + const r = p.view().rects[p.view().active]; + const row = s.cells[@as(usize, r.y) * s.cols ..][0 .. @as(usize, s.cols) * (pane.tag_rows - pane.band_rows)]; + const Row = struct { + fn find(cells: []const 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 hint = Row.find(row, "unroll").?; + try std.testing.expectEqual(Color{ .rgb = inks.dim }, row[hint].style.fg); + for (row) |cell| try std.testing.expect(!cell.style.dim); + var keys: usize = 0; + for (row) |cell| if (std.meta.eql(cell.style.fg, Color{ .rgb = roles.key })) { + try std.testing.expect(cell.style.bold); + keys += 1; + }; + try std.testing.expect(keys > 3); +} |
