From 94a716602888f5f92054d315fe54f46739e84905 Mon Sep 17 00:00:00 2001 From: Jan200101 Date: Sat, 25 May 2024 16:58:19 +0200 Subject: [PATCH 1/2] terminal: support using the bright palette for bold text --- src/config/Config.zig | 3 +++ src/renderer/Metal.zig | 6 ++++-- src/renderer/OpenGL.zig | 6 ++++-- src/terminal/style.zig | 11 ++++++++++- 4 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/config/Config.zig b/src/config/Config.zig index b783741b0..a9b700582 100644 --- a/src/config/Config.zig +++ b/src/config/Config.zig @@ -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 its bright 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 diff --git a/src/renderer/Metal.zig b/src/renderer/Metal.zig index 9c692f34d..173edfa1e 100644 --- a/src/renderer/Metal.zig +++ b/src/renderer/Metal.zig @@ -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, }; diff --git a/src/renderer/OpenGL.zig b/src/renderer/OpenGL.zig index 17274c4a3..409cb96a2 100644 --- a/src/renderer/OpenGL.zig +++ b/src/renderer/OpenGL.zig @@ -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, }; diff --git a/src/terminal/style.zig b/src/terminal/style.zig index 4011b4298..09657cbc0 100644 --- a/src/terminal/style.zig +++ b/src/terminal/style.zig @@ -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, }; } From 41afb62903b924466a56e83fa5ef9bcac04f5d13 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sat, 25 May 2024 14:19:23 -0700 Subject: [PATCH 2/2] very minor nitpicks --- src/config/Config.zig | 2 +- src/terminal/style.zig | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/config/Config.zig b/src/config/Config.zig index a9b700582..2d540e895 100644 --- a/src/config/Config.zig +++ b/src/config/Config.zig @@ -1030,7 +1030,7 @@ 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 its bright palette +/// 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. diff --git a/src/terminal/style.zig b/src/terminal/style.zig index 09657cbc0..7e3356bc8 100644 --- a/src/terminal/style.zig +++ b/src/terminal/style.zig @@ -92,10 +92,10 @@ pub const Style = struct { .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,