diff --git a/src/config/Config.zig b/src/config/Config.zig index a032f34fd..df3bce170 100644 --- a/src/config/Config.zig +++ b/src/config/Config.zig @@ -165,12 +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, +/// 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" diff --git a/src/renderer/Metal.zig b/src/renderer/Metal.zig index 981fe8f81..d3eb22a1f 100644 --- a/src/renderer/Metal.zig +++ b/src/renderer/Metal.zig @@ -162,7 +162,7 @@ pub const DerivedConfig = struct { .background = config.background.toTerminalRGB(), .foreground = config.foreground.toTerminalRGB(), - .invert_selection_fg_bg = config.@"invert-selection-fg-bg", + .invert_selection_fg_bg = config.@"selection-invert-fg-bg", .selection_background = if (config.@"selection-background") |bg| bg.toTerminalRGB() @@ -1306,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 = 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) .{ + // 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, @@ -1325,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 cdb898e8e..07e1d030c 100644 --- a/src/renderer/OpenGL.zig +++ b/src/renderer/OpenGL.zig @@ -276,7 +276,7 @@ pub const DerivedConfig = struct { .background = config.background.toTerminalRGB(), .foreground = config.foreground.toTerminalRGB(), - .invert_selection_fg_bg = config.@"invert-selection-fg-bg", + .invert_selection_fg_bg = config.@"selection-invert-fg-bg", .selection_background = if (config.@"selection-background") |bg| bg.toTerminalRGB() @@ -1088,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 = 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) .{ + // 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, @@ -1107,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,