diff options
Diffstat (limited to 'core')
| -rw-r--r-- | core/Band.zig | 19 | ||||
| -rw-r--r-- | core/Pick.zig | 7 | ||||
| -rw-r--r-- | core/bindings.zig | 5 | ||||
| -rw-r--r-- | core/colors.zig | 257 | ||||
| -rw-r--r-- | core/draw.zig | 40 |
5 files changed, 59 insertions, 269 deletions
diff --git a/core/Band.zig b/core/Band.zig index d60e9831..228dcad0 100644 --- a/core/Band.zig +++ b/core/Band.zig @@ -782,7 +782,7 @@ test "Help's rows say the chord, two blanks and the word; the group is the row's var frame = std.heap.ArenaAllocator.init(std.testing.allocator); defer frame.deinit(); const a = frame.allocator(); - const selected = p.chromeTheme().roles.selectedOn(if (pardes.Trail.reading(p, pane)) .reading_focused else .focused); + const selected = &p.chrome().on(.focus).selection; for ([_]u21{ ' ', '?', 'w', 'r', 'a', 'p' }) |c| p.update(.{ .key = .{ .cp = c } }); const band = (try of(p, a, pane, id)).?; const step = band.steps[0]; @@ -1021,14 +1021,13 @@ test "a band is drawn in the theme's roles (UX D4): spines in the rule ink, a ch }; 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"); + _ = 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); + const inks = p.chrome().on(.focus); + const selected = &inks.selection; // 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); @@ -1043,19 +1042,19 @@ test "a band is drawn in the theme's roles (UX D4): spines in the rule ink, a ch } if (std.mem.eql(u8, cell.grapheme(), "▶")) { cursor_row = row; - // The cursor's `▶` in the key ink on the selection, which - // covers its lead too (UX D4, D5). - try std.testing.expectEqual(pardes.Color{ .rgb = roles.key }, cell.style.fg); + // The cursor's `▶` in the key ink held on the selection, which + // covers its lead too (UX D4, D5; DESIGN.md B1.3). + try std.testing.expectEqual(pardes.Color{ .rgb = selected.key }, cell.style.fg); try std.testing.expectEqual(pardes.Color{ .rgb = selected.ground }, cell.style.bg); } }; 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.expectEqual(pardes.Color{ .rgb = selected.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 })) { + for (on) |cell| if (std.meta.eql(cell.style.fg, pardes.Color{ .rgb = selected.match })) { try std.testing.expect(cell.style.bold); try std.testing.expectEqual(pardes.Color{ .rgb = selected.ground }, cell.style.bg); matched += 1; diff --git a/core/Pick.zig b/core/Pick.zig index c05ed084..c39e8ec9 100644 --- a/core/Pick.zig +++ b/core/Pick.zig @@ -2812,8 +2812,7 @@ test "the themes picker marks the theme in use: `in use` at its row's right end // 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); + const on = &p.chrome().on(.focus).selection; var found = false; for (0..layer.rows) |row| { const cells = layer.cells[row * layer.cols ..][0..layer.cols]; @@ -3499,11 +3498,9 @@ test "Symbols (UX DESIGN N): a Zig file's rows types, functions, fields, then th try std.testing.expectEqual(@as(u16, "Counts.".len), (try rowAt(p, live(p).?, a, 4)).faint); try std.testing.expectEqual(@as(u16, 0), (try rowAt(p, live(p).?, a, 11)).faint); // Drawn: `m Counts.lines : usize = 0` (not the cursor's row). - const pane = p.panes[p.paneBySerial(live(p).?.landing).?].?; _ = try p.render(a); const layer = &p.surface.tag_layers[pardes.BAND_LAYER]; - const roles = &p.chromeTheme().roles; - const inks = roles.on(if (Trail.reading(p, pane)) .reading_focused else .focused); + const inks = p.chrome().on(.focus); var found = false; for (0..layer.rows) |y| { const cells = layer.cells[y * layer.cols ..][0..layer.cols]; diff --git a/core/bindings.zig b/core/bindings.zig index 3884aca0..da8ed4dc 100644 --- a/core/bindings.zig +++ b/core/bindings.zig @@ -619,8 +619,7 @@ test "\" shows the registers rolled, the ones holding something, each its value 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 inks = p.chrome().on(.focus); const Cells = struct { fn at(l: *const pardes.Layer, word: []const u8) ?*const pardes.Cell { for (0..l.rows) |row| { @@ -637,7 +636,7 @@ test "\" shows the registers rolled, the ones holding something, each its value }; 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.expectEqual(pardes.Color{ .rgb = inks.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]; diff --git a/core/colors.zig b/core/colors.zig index 7be5f008..711abfad 100644 --- a/core/colors.zig +++ b/core/colors.zig @@ -411,8 +411,8 @@ fn clip(l: f32, a: f32, b: f32) [3]u8 { /// R0: `ink` held to `floor` on every one of `grounds` by its OKLab /// lightness alone, toward whichever end reads better, its hue kept and its -/// chroma as the gamut allows there: a red stays red where `pushAway` -/// washes it toward white. Found by halves, eight mixes; where no +/// chroma as the gamut allows there: a red stays red where a push toward +/// white would wash it out. Found by halves, eight mixes; where no /// lightness reads, the end. fn hold(ink: [3]u8, grounds: []const [3]u8, floor: f32) [3]u8 { if (leastContrast(ink, grounds) >= floor) return ink; @@ -605,8 +605,9 @@ pub const Chrome = struct { selection: Selection, }; /// A selection on a ground, and that ground halfway to it (OKLab): a - /// second range, a hovered word (B5). - pub const Selection = struct { ground: [3]u8, text: [3]u8, dim: [3]u8, secondary: [3]u8 }; + /// second range, a hovered word (B5); the key and match inks held on + /// the selection, a ground of its own (B1.3: a list's cursor row). + pub const Selection = struct { ground: [3]u8, text: [3]u8, dim: [3]u8, secondary: [3]u8, key: [3]u8, match: [3]u8 }; pub const Ground = enum(u1) { plain, focus }; pub const Severity = enum(u2) { @"error", warning, info, hint }; /// A diff's rows: a row's ground, its changed words', a faint line's, @@ -1012,6 +1013,8 @@ fn groundInks(th: *const Theme, ground: [3]u8, text: [3]u8, sel: [3]u8, sel_text .text = sel_text, .dim = towardOf(sel_text, sel, Chrome.dim_floor), .secondary = mixOklab(ground, sel, 0.5), + .key = hold(th.accent, &.{sel}, Chrome.text_floor), + .match = hold(hue, &.{sel}, Chrome.text_floor), }, }; } @@ -1430,9 +1433,8 @@ pub const ChromeTheme = struct { column_box_dim: [3]u8, scroll_track: [3]u8, scroll_thumb: [3]u8, - roles: Roles, /// Everything B4 derives (`Chrome`), what the surfaces move to; the - /// fields above and `roles` are the old derivations' values, kept for + /// fields above are the old derivations' values, kept for /// the surfaces that still read them until they do (the themes /// programme's L2 lines), so no frame moves before its surface does. resolved: Chrome, @@ -1487,7 +1489,6 @@ pub const ChromeTheme = struct { .column_box_dim = th.column_box_dim orelse mix(th.column_box orelse th.num, th.tag_bg), .scroll_track = th.scroll_track, .scroll_thumb = th.scroll_thumb, - .roles = .of(th, th.tag_bg, active_bg, reading), .resolved = resolved, .view = th.*, }; @@ -1515,176 +1516,12 @@ fn viewOf(theme: *const Theme, r: *const Chrome) LegacyTheme { }); } -/// A tag's ground in the walk UI (UX DESIGN.md D4): the plain tag's, the -/// focused one's tint, a reading pane's tint, focused or not (its ink is -/// the focused tag's while it has the keyboard). -pub const TagGround = enum { plain, focused, reading, reading_focused }; - -/// The inks drawn on one ground: labels and rows (`text`, 4.5:1 at least), -/// hints, meta and forward steps (`dim`, 3.5:1, never under 3), and the -/// spines and the rules between steps (`rule`, 2:1). -pub const RoleInks = struct { ground: [3]u8, text: [3]u8, dim: [3]u8, rule: [3]u8 }; - -/// The walk UI's colour roles (UX DESIGN.md D4), worked out from a theme -/// once, with its chrome (never a frame), each held to its floor on every -/// ground it is drawn on: a tag's four (`tag`) and a band's cursor row on -/// each of them (`selected`, its ground that tag's selection). -pub const Roles = struct { - tag: [4]RoleInks, - selected: [4]RoleInks, - /// The notice row's (the tagline's ground): its dim words. - notice: RoleInks, - /// Key cells, a level's or a row's key letters, `▶`, `•`, a target's - /// keys: 4.5:1 on every tag ground and on the selection. - key: [3]u8, - /// The letters a query matched: an ink, never a ground, 4.5:1 on every - /// tag ground and on the selection. - match: [3]u8, - /// A message's ink by its kind (Messages.ink): 4.5:1 on the tags and - /// the page. - err: [3]u8, - warn: [3]u8, - question: [3]u8, - hint: [3]u8, - - pub const text_floor: f32 = 4.5; - pub const dim_floor: f32 = 3; - pub const rule_floor: f32 = 1.8; - pub const rule_ceiling: f32 = 2.5; - pub const ink_floor: f32 = 4.5; - pub const reading_distance: f32 = 0.04; - - pub fn on(r: *const Roles, ground: TagGround) *const RoleInks { - return &r.tag[@backingInt(ground)]; - } - - pub fn selectedOn(r: *const Roles, ground: TagGround) *const RoleInks { - return &r.selected[@backingInt(ground)]; - } - - /// The selection's floor off a tag's ground: 1.4:1 on a dark tag, 1.25 - /// on a light one. - pub fn selectionFloor(ground: [3]u8) f32 { - return if (relativeLuminance(ground) < 0.18) 1.4 else 1.25; - } - - fn of(th: *const LegacyTheme, plain: [3]u8, focused: [3]u8, reading: [3]u8) Roles { - const grounds = [4][3]u8{ plain, focused, reading, reading }; - const plain_ink = th.tag_fg; - const focused_ink = th.tag_active_fg orelse th.tag_fg; - const texts = [4][3]u8{ plain_ink, focused_ink, plain_ink, focused_ink }; - var r: Roles = undefined; - for (&r.tag, &r.selected, grounds, texts) |*inks, *selected, ground, ink| { - inks.* = inksOn(ground, ink); - selected.* = inksOn(selectionOf(th.tag_sel_bg orelse th.sel_bg, ground, inks.text), inks.text); - } - r.notice = inksOn(th.tagline_bg orelse th.tag_bg, th.tagline_fg orelse th.tag_fg); - const tag_grounds = [_][3]u8{ plain, focused, reading, r.selected[0].ground, r.selected[1].ground, r.selected[2].ground, r.selected[3].ground }; - r.key = pushAway(th.box, &tag_grounds, ink_floor); - r.match = pushAway(matchHue(th), &tag_grounds, ink_floor); - const page = th.bg orelse null_page; - const message_grounds = [_][3]u8{ plain, focused, reading, page }; - const ink = th.fg orelse th.tag_fg; - r.err = pushAway(th.diagnostic_error orelse if (th.palette) |pal| pal[1] else ink, &message_grounds, ink_floor); - r.warn = pushAway(th.diagnostic_warning orelse ink, &message_grounds, ink_floor); - r.question = pushAway(th.diagnostic_info orelse ink, &message_grounds, ink_floor); - r.hint = pushAway(th.diagnostic_hint orelse ink, &message_grounds, ink_floor); - return r; - } -}; - -/// A tag's text, dim and rule inks on `ground`, from its ink (pushed to the -/// text floor where it has less). -fn inksOn(ground: [3]u8, ink: [3]u8) RoleInks { - const text = pushAway(ink, &.{ground}, Roles.text_floor); - return .{ .ground = ground, .text = text, .dim = toward(text, ground, 3.5), .rule = toward(text, ground, 2) }; -} - -/// `ink` mixed toward `ground` (OKLab) by hundredths as far as it still -/// reads at `floor` on it: found by halves (its contrast falls as it nears -/// the ground), seven mixes where a walk took up to a hundred (the first -/// frame's bodyChrome derives them too). -fn toward(ink: [3]u8, ground: [3]u8, floor: f32) [3]u8 { - const a = toOklab(ink); - const b = toOklab(ground); - var best = ink; - var lo: u32 = 0; - var hi: u32 = 101; - while (hi - lo > 1) { - const mid = (lo + hi) / 2; - const t = @as(f32, @floatFromInt(mid)) / 100; - const c = fromOklab(.{ a[0] + (b[0] - a[0]) * t, a[1] + (b[1] - a[1]) * t, a[2] + (b[2] - a[2]) * t }); - if (contrast(c, ground) >= floor) { - lo = mid; - best = c; - } else hi = mid; - } - return best; -} - -/// `ink` pushed by fiftieths toward white or black, whichever reads better -/// on all its grounds, until it reads at `floor` on every one; where no ink -/// does (solarized's mid-grey tag), that end, the most any ink reaches. -pub fn pushAway(ink: [3]u8, grounds: []const [3]u8, floor: f32) [3]u8 { - const white: [3]u8 = @splat(255); - const black: [3]u8 = @splat(0); - if (leastContrast(ink, grounds) >= floor) return ink; - const end = if (leastContrast(white, grounds) >= leastContrast(black, grounds)) white else black; - const a = toOklab(ink); - const b = toOklab(end); - var step: f32 = 0; - while (step <= 50) : (step += 1) { - const t = step / 50; - const c = fromOklab(.{ a[0] + (b[0] - a[0]) * t, a[1] + (b[1] - a[1]) * t, a[2] + (b[2] - a[2]) * t }); - if (leastContrast(c, grounds) >= floor) return c; - } - return end; -} - fn leastContrast(ink: [3]u8, grounds: []const [3]u8) f32 { var least: f32 = 21; for (grounds) |g| least = @min(least, contrast(ink, g)); return least; } -/// The match's hue: the search's ink where it is a hue of its own (a port's -/// is often the page's or the tag's, set for the search's ground), else the -/// theme's warm accent. -fn matchHue(th: *const LegacyTheme) [3]u8 { - const own = th.search_fg orelse return th.num; - const lab = toOklab(own); - return if (@sqrt(lab[1] * lab[1] + lab[2] * lab[2]) >= name_tint_chroma) own else th.num; -} - -/// The selection a band's cursor row is drawn on over `ground`: the -/// theme's where it stands off it, else moved by hundredths toward the -/// text, then away from it, to the first that does with the text still at -/// 4.5:1 on it; where none does (a tag whose text has no contrast to -/// spare), the one furthest off it. -fn selectionOf(own: [3]u8, ground: [3]u8, text: [3]u8) [3]u8 { - var best = own; - var best_off: f32 = 0; - const away: [3]u8 = if (relativeLuminance(text) > relativeLuminance(own)) @splat(0) else @splat(255); - if (contrast(own, ground) >= Roles.selectionFloor(ground) and contrast(text, own) >= Roles.text_floor) return own; - const o = toOklab(own); - for ([2][3]u8{ text, away }) |end| { - const e = toOklab(end); - var step: f32 = 0; - while (step <= 100) : (step += 1) { - const t = step / 100; - const c = fromOklab(.{ o[0] + (e[0] - o[0]) * t, o[1] + (e[1] - o[1]) * t, o[2] + (e[2] - o[2]) * t }); - if (contrast(text, c) < Roles.text_floor) break; - const off = contrast(c, ground) / Roles.selectionFloor(ground); - if (off >= 1) return c; - if (off > best_off) { - best = c; - best_off = off; - } - } - } - return best; -} - /// A reading pane's tag (UX DESIGN.md D4): the theme's own where it stands /// off the tag, else the tag shifted toward paper yellow by 0.04 in OKLab /// and lighter by half that on a dark tag (darker on a light), so it reads @@ -1692,7 +1529,8 @@ fn selectionOf(own: [3]u8, ground: [3]u8, text: [3]u8) [3]u8 { /// contrast, and further where the bytes cannot show so small a step (a /// near-black tag). fn readingOf(th: *const LegacyTheme) [3]u8 { - if (th.tag_reading_bg) |own| if (oklabDistance(toOklab(own), toOklab(th.tag_bg)) >= Roles.reading_distance) return own; + const reading_distance = 0.04; + if (th.tag_reading_bg) |own| if (oklabDistance(toOklab(own), toOklab(th.tag_bg)) >= reading_distance) return own; const tag = toOklab(th.tag_bg); const paper = toOklab(.{ 0xdc, 0xc8, 0x78 }); const da = paper[1] - tag[1]; @@ -1704,11 +1542,11 @@ fn readingOf(th: *const LegacyTheme) [3]u8 { const inks = [2][3]u8{ th.tag_fg, th.tag_active_fg orelse th.tag_fg }; var best = th.tag_bg; var best_text: f32 = -21; - var reach = Roles.reading_distance; + var reach: f32 = reading_distance; while (reach <= 0.2) : (reach *= 1.25) { for ([_]f32{ sign * 0.5, 0, away * 0.5, away, away * 1.5 }) |lean| { const c = fromOklab(.{ tag[0] + lean * reach, tag[1] + da / n * reach, tag[2] + db / n * reach }); - if (oklabDistance(toOklab(c), tag) < Roles.reading_distance) continue; + if (oklabDistance(toOklab(c), tag) < reading_distance) continue; // Each ink by its own floor: 7:1, or what it has on the tag. var text: f32 = 21; for (inks) |ink| text = @min(text, contrast(ink, c) - (@min(7, contrast(ink, th.tag_bg)) - 0.01)); @@ -2461,64 +2299,6 @@ test "every theme tints its names off the tag's ink, and they read on both groun } } -test "every theme's walk UI roles meet their floors on every ground they are drawn on, dark and light" { - // Where a theme's own colours leave no room for a floor, the most it - // allows: an ink's on a mid-grey tag (solarized's) is the better of - // white and black there; a ground's is where the ink it carries would - // drop under its floor. - const white: [3]u8 = @splat(255); - const black: [3]u8 = @splat(0); - const Reach = struct { - fn of(grounds: []const [3]u8) f32 { - return @max(leastContrast(white, grounds), leastContrast(black, grounds)); - } - }; - const a = std.testing.allocator; - const Check = struct { what: []const u8, got: f32, floor: f32 }; - var checks: std.ArrayList(Check) = .empty; - defer checks.deinit(a); - var failed: usize = 0; - for (&themes) |*ring_theme| { - const view = ChromeTheme.ofTheme(ring_theme).view; - const th = &view; - checks.clearRetainingCapacity(); - const chrome = ChromeTheme.fromTheme(th); - const r = &chrome.roles; - const page = th.bg orelse null_page; - const tags = [_][3]u8{ r.tag[0].ground, r.tag[1].ground, r.tag[2].ground, r.selected[0].ground, r.selected[1].ground, r.selected[2].ground, r.selected[3].ground }; - const messages = [_][3]u8{ r.tag[0].ground, r.tag[1].ground, r.tag[2].ground, page }; - for (r.tag ++ r.selected ++ [1]RoleInks{r.notice}) |inks| { - const text = contrast(inks.text, inks.ground); - try checks.append(a, .{ .what = "text", .got = text, .floor = @min(Roles.text_floor, Reach.of(&.{inks.ground})) }); - try checks.append(a, .{ .what = "dim", .got = contrast(inks.dim, inks.ground), .floor = @min(Roles.dim_floor, text) }); - try checks.append(a, .{ .what = "dim under text", .got = text - contrast(inks.dim, inks.ground), .floor = 0 }); - } - try checks.append(a, .{ .what = "key", .got = leastContrast(r.key, &tags), .floor = @min(Roles.ink_floor, Reach.of(&tags)) }); - try checks.append(a, .{ .what = "match", .got = leastContrast(r.match, &tags), .floor = @min(Roles.ink_floor, Reach.of(&tags)) }); - for (r.tag) |inks| { - try checks.append(a, .{ .what = "rule", .got = contrast(inks.rule, inks.ground), .floor = Roles.rule_floor }); - try checks.append(a, .{ .what = "rule ceiling", .got = Roles.rule_ceiling - contrast(inks.rule, inks.ground), .floor = 0 }); - } - for ([_][3]u8{ r.err, r.warn, r.question, r.hint }) |ink| - try checks.append(a, .{ .what = "message", .got = leastContrast(ink, &messages), .floor = @min(Roles.ink_floor, Reach.of(&messages)) }); - // A selection off its tag by 1.4:1 (1.25 light) with the text at - // 4.5:1 on it, where the text has that much over the tag. - for (r.tag, r.selected) |inks, selected| { - const floor = Roles.selectionFloor(inks.ground); - const room = contrast(inks.text, inks.ground) >= floor * Roles.text_floor * 1.03; - try checks.append(a, .{ .what = "selection", .got = contrast(selected.ground, inks.ground), .floor = if (room) floor else 0 }); - } - try checks.append(a, .{ .what = "reading", .got = oklabDistance(toOklab(chrome.tag_reading_bg), toOklab(th.tag_bg)), .floor = Roles.reading_distance }); - for ([_][3]u8{ th.tag_fg, th.tag_active_fg orelse th.tag_fg }) |ink| - try checks.append(a, .{ .what = "text on reading", .got = contrast(ink, chrome.tag_reading_bg), .floor = @min(7, contrast(ink, th.tag_bg)) - 0.02 }); - for (checks.items) |c| if (c.got < c.floor - 0.005) { - failed += 1; - std.debug.print("{s}: {s} {d:.2} under {d:.2}\n", .{ th.name, c.what, c.got, c.floor }); - }; - } - try std.testing.expectEqual(0, failed); -} - test "neonotte84's and acme's inks on the plain tag, their reading mark and their hits are B4's (DESIGN.md B4, D4's goldens re-pinned where B4 moves them)" { const Want = struct { name: []const u8, text: [3]u8, dim: [3]u8, rule: [3]u8, key: [3]u8, match: [3]u8, mode: [3]u8, hit: [3]u8, hit_current: [3]u8 }; const wants = [_]Want{ @@ -2745,8 +2525,21 @@ fn ringFailures(th: *const Theme, c: *const Chrome, designed_here: bool) std.Enu const most = leastContrast(hold(th.keyword, &both, 21), &both); low = low or leastContrast(g.kind, &both) < @min(4.5, most) - 0.01; low = low or contrast(g.selection.text, g.selection.ground) < @min(4.5, reach(g.selection.ground)); + // The keys and the matched letters on its selection, a ground of + // its own (a list's cursor row, B1.3). + for ([2][3]u8{ g.selection.key, g.selection.match }) |i| low = low or contrast(i, g.selection.ground) < @min(4.5, reach(g.selection.ground)); if (low) f.insert(.inks); } + // A message's mark on each fill a grid's grip has, at rest and reading + // on the plain tag too, where a window's grip is hollow (Grip.marks): + // 4.5:1 where its hue reaches it there. + for (c.grip.marks, [4][3]u8{ c.grip.focus, c.grip.dirty, c.grip.ring, c.grip.mode }, 0..) |m, fill, i| { + const both = [2][3]u8{ fill, c.tag[0].ground }; + const grounds = if (i < @intFromEnum(Chrome.Fill.ring)) both[0..1] else both[0..]; + for (m.severity[0..3], c.tag[0].severity[0..3]) |mark, own| { + if (leastContrast(mark, grounds) < @min(4.5, leastContrast(hold(own, grounds, 21), grounds)) - 0.01) f.insert(.inks); + } + } return f; } diff --git a/core/draw.zig b/core/draw.zig index 3d4c47b6..822bfb67 100644 --- a/core/draw.zig +++ b/core/draw.zig @@ -919,17 +919,15 @@ fn joinBand(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, r: R const rows = drawn.band; if (r.w <= TAG_TEXT_INSET) return; const band = (try pardes.Band.of(p, arena, pane, id)) orelse return; - const chrome = p.chromeTheme(); + const chrome = p.chrome(); const tab = p.settings.tab; const columns = @max(band.columns, 1); - // 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: colors.TagGround = if (pardes.Trail.reading(p, pane)) (if (active) .reading_focused else .reading) else if (active) .focused else .plain; - const inks = chrome.roles.on(ground); - const selected = chrome.roles.selectedOn(ground); - // A symbol's kind mark (colors.Chrome.Inks.kind): held on this tag's - // ground and on its cursor row's selection. - const kind = p.chrome().on(if (active) .focus else .plain).kind; + // The inks of its tag's ground, focused or not, whatever its mode + // (DESIGN.md B6, G1'), and of its cursor row's selection, a ground of + // its own (B1.3). + const g: colors.Chrome.Ground = if (active) .focus else .plain; + const inks = chrome.on(g); + const selected = &inks.selection; const bg = inks.ground; const fg = inks.text; const storage = try arena.alloc(Cell, @as(usize, columns) * rows); @@ -948,17 +946,21 @@ fn joinBand(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, r: R const next = modal.nextGrapheme(ln.text, at); 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 }; + if (std.mem.eql(u8, glyph, "▶") or std.mem.eql(u8, glyph, "•")) t.at(col, row).style.fg = .{ .rgb = inks.key }; at = next; } for (ln.parts) |part| { const end = @min(columns, part.col + part.width); - const on = if (part.row.on) selected else inks; + const dim = if (part.row.on) selected.dim else inks.dim; + const key = if (part.row.on) selected.key else inks.key; // The cursor's row across its step's width, its lead too (UX // D5), the lead's `▶` keeping the key ink (D4). if (part.row.on and part.col < end) { const lead = part.col -| 2; t.tint(lead, row, part.col - lead, selected.ground, null); + for (lead..part.col) |x| if (std.meta.eql(t.at(@intCast(x), row).style.fg, Color{ .rgb = inks.key })) { + t.at(@intCast(x), row).style.fg = .{ .rgb = selected.key }; + }; t.tint(part.col, row, end - part.col, selected.ground, selected.text); } var c = part.col; @@ -967,16 +969,16 @@ fn joinBand(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, r: R const next = modal.nextGrapheme(part.row.text, b); const style = &t.at(c, row).style; if (b < part.row.key) { - style.fg = .{ .rgb = chrome.roles.key }; + style.fg = .{ .rgb = 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) or (b >= part.row.quiet[0] and b < part.row.quiet[1])) style.fg = .{ .rgb = on.dim }; - if (b < part.row.kind) style.fg = .{ .rgb = kind }; + if (b < part.row.chord) style.fg = .{ .rgb = key }; + if (b < part.row.pre) style.fg = .{ .rgb = chrome.name[@intFromEnum(g)] }; + 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 = dim }; + if (b < part.row.kind) style.fg = .{ .rgb = inks.kind }; for (part.row.keys) |k| if (k == b) { - style.fg = .{ .rgb = chrome.roles.key }; + style.fg = .{ .rgb = key }; style.bold = true; }; if (part.row.under) style.ul = .single; @@ -984,7 +986,7 @@ fn joinBand(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, r: R // ground (never a ground of its own: on the cursor row's // selection one vanished). for (part.row.marks) |m| if (m == b) { - style.fg = .{ .rgb = chrome.roles.match }; + style.fg = .{ .rgb = if (part.row.on) selected.match else inks.match }; style.bold = true; }; b = next; @@ -992,7 +994,7 @@ fn joinBand(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, r: R // 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 }; + for (part.col + part.width - meta..part.col + part.width) |x| t.at(@intCast(x), row).style.fg = .{ .rgb = dim }; } } } |
