mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-16 08:46:08 +03:00
renderer: address issue with inverted cells
This commit is contained in:
@ -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"
|
||||
|
@ -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,
|
||||
|
@ -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,
|
||||
|
Reference in New Issue
Block a user