From 7a239835d2325b037aabfb449000945290cc7707 Mon Sep 17 00:00:00 2001 From: Raiden1411 <67233402+Raiden1411@users.noreply.github.com> Date: Sat, 18 Nov 2023 01:04:14 +0000 Subject: [PATCH] core: add config option to invert fg and bg of cell when selected --- src/config/Config.zig | 7 +++++++ src/renderer/OpenGL.zig | 6 ++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/config/Config.zig b/src/config/Config.zig index ecf596e59..a032f34fd 100644 --- a/src/config/Config.zig +++ b/src/config/Config.zig @@ -165,6 +165,13 @@ foreground: Color = .{ .r = 0xFF, .g = 0xFF, .b = 0xFF }, @"selection-foreground": ?Color = null, @"selection-background": ?Color = null, +/// Inverts the cell color from foreground to background, +/// and from background to foreground. +/// This option does not take in consideration the color +/// values defined for "selection-foreground" and "selection-background" +/// as it will use the foreground and background of the cell. +@"invert-selection-fg-bg": bool = false, + /// Color palette for the 256 color form that many terminal applications /// use. The syntax of this configuration is "N=HEXCODE" where "n" /// is 0 to 255 (for the 256 colors) and HEXCODE is a typical RGB diff --git a/src/renderer/OpenGL.zig b/src/renderer/OpenGL.zig index 12b20aec5..cdb898e8e 100644 --- a/src/renderer/OpenGL.zig +++ b/src/renderer/OpenGL.zig @@ -237,6 +237,7 @@ pub const DerivedConfig = struct { foreground: terminal.color.RGB, selection_background: ?terminal.color.RGB, selection_foreground: ?terminal.color.RGB, + invert_selection_fg_bg: bool, pub fn init( alloc_gpa: Allocator, @@ -275,6 +276,7 @@ pub const DerivedConfig = struct { .background = config.background.toTerminalRGB(), .foreground = config.foreground.toTerminalRGB(), + .invert_selection_fg_bg = config.@"invert-selection-fg-bg", .selection_background = if (config.@"selection-background") |bg| bg.toTerminalRGB() @@ -1088,8 +1090,8 @@ pub fn updateCell( const colors: BgFg = colors: { // If we are selected, we our colors are just inverted fg/bg const selection_res: ?BgFg = if (selected) .{ - .bg = self.config.selection_background orelse self.foreground_color, - .fg = self.config.selection_foreground orelse self.background_color, + .bg = if (self.config.invert_selection_fg_bg) cell.fg else self.config.selection_background orelse self.foreground_color, + .fg = if (self.config.invert_selection_fg_bg) cell.bg else self.config.selection_foreground orelse self.background_color, } else null; const res: BgFg = selection_res orelse if (!cell.attrs.inverse) .{