config: add selection-foreground/background
parent
a4e40c7567
commit
de16e4a92b
|
|
@ -978,6 +978,20 @@ palette: Palette = .{},
|
||||||
/// Available since: 1.1.0
|
/// Available since: 1.1.0
|
||||||
@"split-divider-color": ?Color = null,
|
@"split-divider-color": ?Color = null,
|
||||||
|
|
||||||
|
/// The foreground and background color for search matches. This only applies
|
||||||
|
/// to non-focused search matches, also known as candidate matches.
|
||||||
|
///
|
||||||
|
/// Valid values:
|
||||||
|
///
|
||||||
|
/// - Hex (`#RRGGBB` or `RRGGBB`)
|
||||||
|
/// - Named X11 color
|
||||||
|
/// - "cell-foreground" to match the cell foreground color
|
||||||
|
/// - "cell-background" to match the cell background color
|
||||||
|
///
|
||||||
|
/// The default value is
|
||||||
|
@"search-foreground": TerminalColor = .{ .color = .{ .r = 0, .g = 0, .b = 0 } },
|
||||||
|
@"search-background": TerminalColor = .{ .color = .{ .r = 0xFF, .g = 0xE0, .b = 0x82 } },
|
||||||
|
|
||||||
/// The command to run, usually a shell. If this is not an absolute path, it'll
|
/// The command to run, usually a shell. If this is not an absolute path, it'll
|
||||||
/// be looked up in the `PATH`. If this is not set, a default will be looked up
|
/// be looked up in the `PATH`. If this is not set, a default will be looked up
|
||||||
/// from your system. The rules for the default lookup are:
|
/// from your system. The rules for the default lookup are:
|
||||||
|
|
|
||||||
|
|
@ -537,6 +537,8 @@ pub fn Renderer(comptime GraphicsAPI: type) type {
|
||||||
foreground: terminal.color.RGB,
|
foreground: terminal.color.RGB,
|
||||||
selection_background: ?configpkg.Config.TerminalColor,
|
selection_background: ?configpkg.Config.TerminalColor,
|
||||||
selection_foreground: ?configpkg.Config.TerminalColor,
|
selection_foreground: ?configpkg.Config.TerminalColor,
|
||||||
|
search_background: configpkg.Config.TerminalColor,
|
||||||
|
search_foreground: configpkg.Config.TerminalColor,
|
||||||
bold_color: ?configpkg.BoldColor,
|
bold_color: ?configpkg.BoldColor,
|
||||||
faint_opacity: u8,
|
faint_opacity: u8,
|
||||||
min_contrast: f32,
|
min_contrast: f32,
|
||||||
|
|
@ -608,6 +610,8 @@ pub fn Renderer(comptime GraphicsAPI: type) type {
|
||||||
|
|
||||||
.selection_background = config.@"selection-background",
|
.selection_background = config.@"selection-background",
|
||||||
.selection_foreground = config.@"selection-foreground",
|
.selection_foreground = config.@"selection-foreground",
|
||||||
|
.search_background = config.@"search-background",
|
||||||
|
.search_foreground = config.@"search-foreground",
|
||||||
|
|
||||||
.custom_shaders = custom_shaders,
|
.custom_shaders = custom_shaders,
|
||||||
.bg_image = bg_image,
|
.bg_image = bg_image,
|
||||||
|
|
@ -2552,24 +2556,30 @@ pub fn Renderer(comptime GraphicsAPI: type) type {
|
||||||
.{};
|
.{};
|
||||||
|
|
||||||
// True if this cell is selected
|
// True if this cell is selected
|
||||||
const selected: bool = selected: {
|
const selected: enum {
|
||||||
|
false,
|
||||||
|
selection,
|
||||||
|
search,
|
||||||
|
} = selected: {
|
||||||
// If we're highlighted, then we're selected. In the
|
// If we're highlighted, then we're selected. In the
|
||||||
// future we want to use a different style for this
|
// future we want to use a different style for this
|
||||||
// but this to get started.
|
// but this to get started.
|
||||||
for (highlights.items) |hl| {
|
for (highlights.items) |hl| {
|
||||||
if (x >= hl[0] and x <= hl[1]) {
|
if (x >= hl[0] and x <= hl[1]) {
|
||||||
break :selected true;
|
break :selected .search;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const sel = selection orelse break :selected false;
|
const sel = selection orelse break :selected .false;
|
||||||
const x_compare = if (wide == .spacer_tail)
|
const x_compare = if (wide == .spacer_tail)
|
||||||
x -| 1
|
x -| 1
|
||||||
else
|
else
|
||||||
x;
|
x;
|
||||||
|
|
||||||
break :selected x_compare >= sel[0] and
|
if (x_compare >= sel[0] and
|
||||||
x_compare <= sel[1];
|
x_compare <= sel[1]) break :selected .selection;
|
||||||
|
|
||||||
|
break :selected .false;
|
||||||
};
|
};
|
||||||
|
|
||||||
// The `_style` suffixed values are the colors based on
|
// The `_style` suffixed values are the colors based on
|
||||||
|
|
@ -2586,25 +2596,26 @@ pub fn Renderer(comptime GraphicsAPI: type) type {
|
||||||
});
|
});
|
||||||
|
|
||||||
// The final background color for the cell.
|
// The final background color for the cell.
|
||||||
const bg = bg: {
|
const bg = switch (selected) {
|
||||||
if (selected) {
|
// If we have an explicit selection background color
|
||||||
// If we have an explicit selection background color
|
// specified in the config, use that.
|
||||||
// specified int he config, use that
|
//
|
||||||
if (self.config.selection_background) |v| {
|
// If no configuration, then our selection background
|
||||||
break :bg switch (v) {
|
// is our foreground color.
|
||||||
.color => |color| color.toTerminalRGB(),
|
.selection => if (self.config.selection_background) |v| switch (v) {
|
||||||
.@"cell-foreground" => if (style.flags.inverse) bg_style else fg_style,
|
.color => |color| color.toTerminalRGB(),
|
||||||
.@"cell-background" => if (style.flags.inverse) fg_style else bg_style,
|
.@"cell-foreground" => if (style.flags.inverse) bg_style else fg_style,
|
||||||
};
|
.@"cell-background" => if (style.flags.inverse) fg_style else bg_style,
|
||||||
}
|
} else state.colors.foreground,
|
||||||
|
|
||||||
// If no configuration, then our selection background
|
.search => switch (self.config.search_background) {
|
||||||
// is our foreground color.
|
.color => |color| color.toTerminalRGB(),
|
||||||
break :bg state.colors.foreground;
|
.@"cell-foreground" => if (style.flags.inverse) bg_style else fg_style,
|
||||||
}
|
.@"cell-background" => if (style.flags.inverse) fg_style else bg_style,
|
||||||
|
},
|
||||||
|
|
||||||
// Not selected
|
// Not selected
|
||||||
break :bg if (style.flags.inverse != isCovering(cell.codepoint()))
|
.false => if (style.flags.inverse != isCovering(cell.codepoint()))
|
||||||
// Two cases cause us to invert (use the fg color as the bg)
|
// Two cases cause us to invert (use the fg color as the bg)
|
||||||
// - The "inverse" style flag.
|
// - The "inverse" style flag.
|
||||||
// - A "covering" glyph; we use fg for bg in that
|
// - A "covering" glyph; we use fg for bg in that
|
||||||
|
|
@ -2616,7 +2627,7 @@ pub fn Renderer(comptime GraphicsAPI: type) type {
|
||||||
fg_style
|
fg_style
|
||||||
else
|
else
|
||||||
// Otherwise they cancel out.
|
// Otherwise they cancel out.
|
||||||
bg_style;
|
bg_style,
|
||||||
};
|
};
|
||||||
|
|
||||||
const fg = fg: {
|
const fg = fg: {
|
||||||
|
|
@ -2628,23 +2639,24 @@ pub fn Renderer(comptime GraphicsAPI: type) type {
|
||||||
// - Cell is selected, inverted, and set to cell-foreground
|
// - Cell is selected, inverted, and set to cell-foreground
|
||||||
// - Cell is selected, not inverted, and set to cell-background
|
// - Cell is selected, not inverted, and set to cell-background
|
||||||
// - Cell is inverted and not selected
|
// - Cell is inverted and not selected
|
||||||
if (selected) {
|
break :fg switch (selected) {
|
||||||
// Use the selection foreground if set
|
.selection => if (self.config.selection_foreground) |v| switch (v) {
|
||||||
if (self.config.selection_foreground) |v| {
|
.color => |color| color.toTerminalRGB(),
|
||||||
break :fg switch (v) {
|
.@"cell-foreground" => if (style.flags.inverse) final_bg else fg_style,
|
||||||
.color => |color| color.toTerminalRGB(),
|
.@"cell-background" => if (style.flags.inverse) fg_style else final_bg,
|
||||||
.@"cell-foreground" => if (style.flags.inverse) final_bg else fg_style,
|
} else state.colors.background,
|
||||||
.@"cell-background" => if (style.flags.inverse) fg_style else final_bg,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
break :fg state.colors.background;
|
.search => switch (self.config.search_foreground) {
|
||||||
}
|
.color => |color| color.toTerminalRGB(),
|
||||||
|
.@"cell-foreground" => if (style.flags.inverse) final_bg else fg_style,
|
||||||
|
.@"cell-background" => if (style.flags.inverse) fg_style else final_bg,
|
||||||
|
},
|
||||||
|
|
||||||
break :fg if (style.flags.inverse)
|
.false => if (style.flags.inverse)
|
||||||
final_bg
|
final_bg
|
||||||
else
|
else
|
||||||
fg_style;
|
fg_style,
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
// Foreground alpha for this cell.
|
// Foreground alpha for this cell.
|
||||||
|
|
@ -2662,7 +2674,7 @@ pub fn Renderer(comptime GraphicsAPI: type) type {
|
||||||
const default: u8 = 255;
|
const default: u8 = 255;
|
||||||
|
|
||||||
// Cells that are selected should be fully opaque.
|
// Cells that are selected should be fully opaque.
|
||||||
if (selected) break :bg_alpha default;
|
if (selected != .false) break :bg_alpha default;
|
||||||
|
|
||||||
// Cells that are reversed should be fully opaque.
|
// Cells that are reversed should be fully opaque.
|
||||||
if (style.flags.inverse) break :bg_alpha default;
|
if (style.flags.inverse) break :bg_alpha default;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue