From d05741ba2444347d8ec21db0e3b020c63b844ca7 Mon Sep 17 00:00:00 2001 From: CJ van den Berg Date: Wed, 8 Apr 2026 11:31:58 +0200 Subject: [PATCH] refactor(terminal): use color module helper u24_to_u8s --- src/color.zig | 4 ++++ src/tui/terminal_view.zig | 13 ++++--------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/color.zig b/src/color.zig index 47be2ecc..c97c300e 100644 --- a/src/color.zig +++ b/src/color.zig @@ -106,6 +106,10 @@ pub const RGBf = struct { const GAMMA = 2.4; }; +pub fn u24_to_u8s(v: u24) [3]u8 { + return .{ @truncate(v >> 16), @truncate(v >> 8), @truncate(v) }; +} + pub fn max_contrast(v: u24, a: u24, b: u24) u24 { return RGB.max_contrast(RGB.from_u24(v), RGB.from_u24(a), RGB.from_u24(b)).to_u24(); } diff --git a/src/tui/terminal_view.zig b/src/tui/terminal_view.zig index 8f83e5f2..9204b655 100644 --- a/src/tui/terminal_view.zig +++ b/src/tui/terminal_view.zig @@ -18,7 +18,8 @@ const tui = @import("tui.zig"); const input = @import("input"); const keybind = @import("keybind"); pub const Mode = keybind.Mode; -const RGB = @import("color").RGB; +const color = @import("color"); +const RGB = color.RGB; pub const name = @typeName(Self); @@ -371,14 +372,8 @@ pub fn render(self: *Self, theme: *const Widget.Theme) bool { // Update the terminal's fg/bg color cache from the current theme so that // OSC 10/11 colour queries return accurate values. - if (theme.editor.fg) |fg| { - const c = fg.color; - self.vt.vt.fg_color = .{ @truncate(c >> 16), @truncate(c >> 8), @truncate(c) }; - } - if (theme.editor.bg) |bg| { - const c = bg.color; - self.vt.vt.bg_color = .{ @truncate(c >> 16), @truncate(c >> 8), @truncate(c) }; - } + if (theme.editor.fg) |fg| self.vt.vt.fg_color = color.u24_to_u8s(fg.color); + if (theme.editor.bg) |bg| self.vt.vt.bg_color = color.u24_to_u8s(bg.color); // Blit the terminal's front screen into our vaxis.Window. const software_cursor = !tui.has_native_cursor();