Merge pull request #1793 from Jan200101/PR/bold-is-bright

terminal: support using the bright palette for bold text
This commit is contained in:
Mitchell Hashimoto
2024-05-25 17:20:03 -04:00
committed by GitHub
4 changed files with 21 additions and 5 deletions

View File

@ -1030,6 +1030,9 @@ keybind: Keybinds = .{},
/// notifications using certain escape sequences such as OSC 9 or OSC 777.
@"desktop-notifications": bool = true,
/// If `true`, the bold text will use the bright color palette.
@"bold-is-bright": bool = false,
/// This will be used to set the `TERM` environment variable.
/// HACK: We set this with an `xterm` prefix because vim uses that to enable key
/// protocols (specifically this will enable `modifyOtherKeys`), among other

View File

@ -323,6 +323,7 @@ pub const DerivedConfig = struct {
selection_background: ?terminal.color.RGB,
selection_foreground: ?terminal.color.RGB,
invert_selection_fg_bg: bool,
bold_is_bright: bool,
min_contrast: f32,
custom_shaders: std.ArrayListUnmanaged([:0]const u8),
links: link.Set,
@ -375,6 +376,7 @@ pub const DerivedConfig = struct {
.background = config.background.toTerminalRGB(),
.foreground = config.foreground.toTerminalRGB(),
.invert_selection_fg_bg = config.@"selection-invert-fg-bg",
.bold_is_bright = config.@"bold-is-bright",
.min_contrast = @floatCast(config.@"minimum-contrast"),
.selection_background = if (config.@"selection-background") |bg|
@ -2118,12 +2120,12 @@ fn updateCell(
// In normal mode, background and fg match the cell. We
// un-optionalize the fg by defaulting to our fg color.
.bg = style.bg(cell, palette),
.fg = style.fg(palette) orelse self.foreground_color,
.fg = style.fg(palette, self.config.bold_is_bright) orelse self.foreground_color,
} else .{
// In inverted mode, the background MUST be set to something
// (is never null) so it is either the fg or default fg. The
// fg is either the bg or default background.
.bg = style.fg(palette) orelse self.foreground_color,
.bg = style.fg(palette, self.config.bold_is_bright) orelse self.foreground_color,
.fg = style.bg(cell, palette) orelse self.background_color,
};

View File

@ -243,6 +243,7 @@ pub const DerivedConfig = struct {
selection_background: ?terminal.color.RGB,
selection_foreground: ?terminal.color.RGB,
invert_selection_fg_bg: bool,
bold_is_bright: bool,
min_contrast: f32,
custom_shaders: std.ArrayListUnmanaged([:0]const u8),
links: link.Set,
@ -294,6 +295,7 @@ pub const DerivedConfig = struct {
.background = config.background.toTerminalRGB(),
.foreground = config.foreground.toTerminalRGB(),
.invert_selection_fg_bg = config.@"selection-invert-fg-bg",
.bold_is_bright = config.@"bold-is-bright",
.min_contrast = @floatCast(config.@"minimum-contrast"),
.selection_background = if (config.@"selection-background") |bg|
@ -1337,12 +1339,12 @@ fn updateCell(
// In normal mode, background and fg match the cell. We
// un-optionalize the fg by defaulting to our fg color.
.bg = style.bg(cell, palette),
.fg = style.fg(palette) orelse self.foreground_color,
.fg = style.fg(palette, self.config.bold_is_bright) orelse self.foreground_color,
} else .{
// In inverted mode, the background MUST be set to something
// (is never null) so it is either the fg or default fg. The
// fg is either the bg or default background.
.bg = style.fg(palette) orelse self.foreground_color,
.bg = style.fg(palette, self.config.bold_is_bright) orelse self.foreground_color,
.fg = style.bg(cell, palette) orelse self.background_color,
};

View File

@ -85,10 +85,19 @@ pub const Style = struct {
pub fn fg(
self: Style,
palette: *const color.Palette,
bold_is_bright: bool,
) ?color.RGB {
return switch (self.fg_color) {
.none => null,
.palette => |idx| palette[idx],
.palette => |idx| palette: {
if (bold_is_bright and self.flags.bold) {
const bright_offset = @intFromEnum(color.Name.bright_black);
if (idx < bright_offset)
break :palette palette[idx + bright_offset];
}
break :palette palette[idx];
},
.rgb => |rgb| rgb,
};
}