summaryrefslogtreecommitdiff
path: root/src/colors.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-17 00:05:09 -0300
committerGabriel Schneider <[email protected]>2026-11-17 12:15:01 -0300
commitc50226bdad46ed69643079e7c6f3e8ade3a034a1 (patch)
treea6fc7ae80d7f5f26da1f9771f2fc9ef5a473a24f /src/colors.zig
parentfa504c392b5f3c04a7cfce74566e23cb94ddd6cf (diff)
downloadpardes-c50226bdad46ed69643079e7c6f3e8ade3a034a1.tar.gz
pardes-c50226bdad46ed69643079e7c6f3e8ade3a034a1.zip
colors: a style byte's four high bits are grounds a theme resolves, not a diff's: syntax.ground_add and ground_del (a row's hue), ground_emph (the stronger ground), ground_line (the faint one), the byte as it was; DiffTints moves from File.zig to colors.zig as Grounds (an add and a del Ground: row, emph, line, ink), the same Oklab mixes and marker contrast; the painter has one rule, a row's first byte says its ground (emph the stronger to the pane's edge, line the faint, neither none, its marker in the hue) and a later byte's emph is its cell's, so it stops asking the pane's colour algorithm (`row_tint = algo == .diff`) and works the grounds out once a frame only for a row that names a hue; highlightDiff marks an added or removed line's first byte emph, the strong row a .diff's rows always had; recolorDiffOutput reads the same Grounds; goldens unchanged (diffview, pagercolor, diffstack), render of the 50k-line file 11,723,421 user instructions a frame before and 11,724,208 after (+0.007%, perf stat over ReleaseFast pardes-perf, 210 frames less 10)
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
Diffstat (limited to 'src/colors.zig')
-rw-r--r--src/colors.zig37
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");