Option to render bold text in a different, fixed color #3134
-
I would like to have an option to render bold text in a different color. This is an extension to the The purpose of this feature is to make it easier to distinguish bold text. Eg: This is implemented in other terminals as well. Eg: The patch below shows a sample implementation of this feature for MacOS (Metal), but the same can be used for OpenGL as well Patchdiff --git a/src/config/Config.zig b/src/config/Config.zig
index a5ba71b2..d48e0b03 100644
--- a/src/config/Config.zig
+++ b/src/config/Config.zig
@@ -1887,6 +1887,9 @@ keybind: Keybinds = .{},
/// If `true`, the bold text will use the bright color palette.
@"bold-is-bright": bool = false,
+/// Set color to be used for foreground while rendering bold text.
+@"bold-color": ?Color = null,
+
/// 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 3f24c3d2..e8bf26ee 100644
--- a/src/renderer/Metal.zig
+++ b/src/renderer/Metal.zig
@@ -361,6 +361,7 @@ pub const DerivedConfig = struct {
selection_foreground: ?terminal.color.RGB,
invert_selection_fg_bg: bool,
bold_is_bright: bool,
+ bold_color: ?terminal.color.RGB,
min_contrast: f32,
padding_color: configpkg.WindowPaddingColor,
custom_shaders: configpkg.RepeatablePath,
@@ -432,6 +433,11 @@ pub const DerivedConfig = struct {
else
null,
+ .bold_color = if (config.@"bold-color") |bg|
+ bg.toTerminalRGB()
+ else
+ null,
+
.custom_shaders = custom_shaders,
.links = links,
.vsync = config.@"window-vsync",
@@ -2360,7 +2366,7 @@ fn rebuildCells(
false;
const bg_style = style.bg(cell, color_palette);
- const fg_style = style.fg(color_palette, self.config.bold_is_bright) orelse self.foreground_color;
+ const fg_style = style.fg(color_palette, self.foreground_color, self.config.bold_is_bright, self.config.bold_color);
// The final background color for the cell.
const bg = bg: {
@@ -2604,7 +2610,7 @@ fn rebuildCells(
const cursor_color = self.cursor_color orelse color: {
if (self.cursor_invert) {
const sty = screen.cursor.page_pin.style(screen.cursor.page_cell);
- break :color sty.fg(color_palette, self.config.bold_is_bright) orelse self.foreground_color;
+ break :color sty.fg(color_palette, self.foreground_color, self.config.bold_is_bright, self.config.bold_color);
} else {
break :color self.foreground_color;
}
diff --git a/src/terminal/style.zig b/src/terminal/style.zig
index 6c1f8b60..7313d5fc 100644
--- a/src/terminal/style.zig
+++ b/src/terminal/style.zig
@@ -123,10 +123,17 @@ pub const Style = struct {
pub fn fg(
self: Style,
palette: *const color.Palette,
+ default_color: color.RGB,
bold_is_bright: bool,
- ) ?color.RGB {
+ bold_color: ?color.RGB,
+ ) color.RGB {
return switch (self.fg_color) {
- .none => null,
+ .none => default: {
+ if (self.flags.bold) {
+ break :default bold_color orelse default_color;
+ }
+ break :default default_color;
+ },
.palette => |idx| palette: {
if (bold_is_bright and self.flags.bold) {
const bright_offset = @intFromEnum(color.Name.bright_black);
@@ -136,7 +143,12 @@ pub const Style = struct {
break :palette palette[idx];
},
- .rgb => |rgb| rgb,
+ .rgb => |rgb| rgb: {
+ if (self.flags.bold and rgb.eql(default_color)) {
+ break :rgb bold_color orelse rgb;
+ }
+ break :rgb rgb;
+ },
};
}
|
Beta Was this translation helpful? Give feedback.
Replies: 8 comments 12 replies
-
@Rohit-Bevinahally how can I achieve the same on Linux with Wayland? |
Beta Was this translation helpful? Give feedback.
-
On which commit is the patch based? |
Beta Was this translation helpful? Give feedback.
-
Linking to the corresponding issue I have created yesterday before finding this discussion, for link integrity: #3410 |
Beta Was this translation helpful? Give feedback.
-
On Mac, comparing Terminal.app vs Ghostty, Ghostty is not showing bright color for the directory blue. I'm using the same base color code for the blue in both apps. On Terminal.app I've enabled "Use bright colors for bold text", and on Ghostty I am using:
|
Beta Was this translation helpful? Give feedback.
-
I think the source has changed a lot since 1.0.0, and I can't get this patch to apply at all. EDIT: Scratch that, I've updated the patch to work on the latest #tip build:
|
Beta Was this translation helpful? Give feedback.
-
Done with #7168 |
Beta Was this translation helpful? Give feedback.
-
I have created a new PR to change the functionality to only affect the default foreground colour: #7871 |
Beta Was this translation helpful? Give feedback.
-
@roberthawdon @mitchellh can we please discuss the I'm using all my 16 'standard' colors deliberately and with current tip version when I set |
Beta Was this translation helpful? Give feedback.
I have created a new PR to change the functionality to only affect the default foreground colour: #7871