diff --git a/src/config/Config.zig b/src/config/Config.zig index 28d3cea89..11890d5b5 100644 --- a/src/config/Config.zig +++ b/src/config/Config.zig @@ -165,6 +165,14 @@ foreground: Color = .{ .r = 0xFF, .g = 0xFF, .b = 0xFF }, @"selection-foreground": ?Color = null, @"selection-background": ?Color = null, +/// Swap the foreground and background colors of cells for selection. +/// This option overrides the "selection-foreground" and "selection-background" +/// options. +/// +/// If you select across cells with differing foregrounds and backgrounds, +/// the selection color will vary across the selection. +@"selection-invert-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/Metal.zig b/src/renderer/Metal.zig index 73a65a22d..d3eb22a1f 100644 --- a/src/renderer/Metal.zig +++ b/src/renderer/Metal.zig @@ -123,6 +123,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, @@ -161,6 +162,7 @@ pub const DerivedConfig = struct { .background = config.background.toTerminalRGB(), .foreground = config.foreground.toTerminalRGB(), + .invert_selection_fg_bg = config.@"selection-invert-fg-bg", .selection_background = if (config.@"selection-background") |bg| bg.toTerminalRGB() @@ -1304,13 +1306,8 @@ pub fn updateCell( // The colors for the cell. 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, - } else null; - - const res: BgFg = selection_res orelse if (!cell.attrs.inverse) .{ + // The normal cell result + const cell_res: BgFg = if (!cell.attrs.inverse) .{ // In normal mode, background and fg match the cell. We // un-optionalize the fg by defaulting to our fg color. .bg = if (cell.attrs.has_bg) cell.bg else null, @@ -1323,8 +1320,21 @@ pub fn updateCell( .fg = if (cell.attrs.has_bg) cell.bg else self.background_color, }; + // If we are selected, we our colors are just inverted fg/bg + const selection_res: ?BgFg = if (selected) .{ + .bg = if (self.config.invert_selection_fg_bg) + cell_res.fg + else + self.config.selection_background orelse self.foreground_color, + .fg = if (self.config.invert_selection_fg_bg) + cell_res.bg orelse self.background_color + else + self.config.selection_foreground orelse self.background_color, + } else null; + // If the cell is "invisible" then we just make fg = bg so that // the cell is transparent but still copy-able. + const res: BgFg = selection_res orelse cell_res; if (cell.attrs.invisible) { break :colors BgFg{ .bg = res.bg, diff --git a/src/renderer/OpenGL.zig b/src/renderer/OpenGL.zig index 12b20aec5..07e1d030c 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.@"selection-invert-fg-bg", .selection_background = if (config.@"selection-background") |bg| bg.toTerminalRGB() @@ -1086,13 +1088,8 @@ pub fn updateCell( // The colors for the cell. 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, - } else null; - - const res: BgFg = selection_res orelse if (!cell.attrs.inverse) .{ + // The normal cell result + const cell_res: BgFg = if (!cell.attrs.inverse) .{ // In normal mode, background and fg match the cell. We // un-optionalize the fg by defaulting to our fg color. .bg = if (cell.attrs.has_bg) cell.bg else null, @@ -1105,8 +1102,21 @@ pub fn updateCell( .fg = if (cell.attrs.has_bg) cell.bg else self.background_color, }; + // If we are selected, we our colors are just inverted fg/bg + const selection_res: ?BgFg = if (selected) .{ + .bg = if (self.config.invert_selection_fg_bg) + cell_res.fg + else + self.config.selection_background orelse self.foreground_color, + .fg = if (self.config.invert_selection_fg_bg) + cell_res.bg orelse self.background_color + else + self.config.selection_foreground orelse self.background_color, + } else null; + // If the cell is "invisible" then we just make fg = bg so that // the cell is transparent but still copy-able. + const res: BgFg = selection_res orelse cell_res; if (cell.attrs.invisible) { break :colors BgFg{ .bg = res.bg,