diff options
Diffstat (limited to 'src/colors.zig')
| -rw-r--r-- | src/colors.zig | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/src/colors.zig b/src/colors.zig index 1713ba24..e2e00ea8 100644 --- a/src/colors.zig +++ b/src/colors.zig @@ -322,6 +322,43 @@ pub fn synInk(th: *const Theme, sy: @import("syntax.zig").Syn) ?[3]u8 { }; } +/// The grounds a style byte's high bits name (syntax.ground_add and the +/// rest) in a theme: a row added or removed on a ground a little way from +/// the page toward the theme's green or red (its own ANSI ones where it has +/// a palette), a stronger one, a faint one, and the row's marker in that +/// hue, pushed toward the ink until it reads on the row's ground. Syntax +/// colours are drawn over a ground unchanged. +pub const Grounds = struct { + add: Ground, + del: Ground, + + pub const Ground = struct { row: [3]u8, emph: [3]u8, line: [3]u8, ink: [3]u8 }; + + pub fn of(th: *const Theme) Grounds { + const page = th.bg orelse th.tag_bg; + const ink = th.fg orelse th.tag_fg; + const green: [3]u8 = if (th.palette) |pal| pal[2] else .{ 0x2e, 0xa0, 0x43 }; + const red: [3]u8 = if (th.palette) |pal| pal[1] else .{ 0xcf, 0x22, 0x2e }; + return .{ .add = ground(page, ink, green), .del = ground(page, ink, red) }; + } + + fn ground(page: [3]u8, ink: [3]u8, hue: [3]u8) Ground { + const row = mixOklab(page, hue, 0.18); + var marker = hue; + var step: usize = 0; + while (step < 4 and contrast(marker, row) < 3) : (step += 1) marker = mixOklab(marker, ink, 0.4); + return .{ .row = row, .emph = mixOklab(page, hue, 0.28), .line = mixOklab(page, hue, 0.07), .ink = marker }; + } + + /// The ground of a byte's hue, if it has one. + pub fn forStyle(g: *const Grounds, style: u8) ?Ground { + const syntax = @import("syntax.zig"); + if (style & syntax.ground_add != 0) return g.add; + if (style & syntax.ground_del != 0) return g.del; + return null; + } +}; + /// One family, its twelve backgrounds a theme each (`curated`). const seoul256 = @import("themes/seoul256.zig"); |
