Merge pull request #329 from hovsater/cursor-colors

Implement cursor text color option
This commit is contained in:
Mitchell Hashimoto
2023-08-26 09:38:35 -07:00
committed by GitHub
3 changed files with 28 additions and 6 deletions

View File

@ -71,6 +71,7 @@ pub const Config = struct {
/// The color of the cursor. If this is not set, a default will be chosen.
@"cursor-color": ?Color = null,
@"cursor-text": ?Color = null,
/// The opacity level (opposite of transparency) of the background.
/// A value of 1 is fully opaque and a value of 0 is fully transparent.

View File

@ -108,6 +108,7 @@ pub const DerivedConfig = struct {
font_thicken: bool,
font_features: std.ArrayList([]const u8),
cursor_color: ?terminal.color.RGB,
cursor_text: ?terminal.color.RGB,
background: terminal.color.RGB,
background_opacity: f64,
foreground: terminal.color.RGB,
@ -135,6 +136,11 @@ pub const DerivedConfig = struct {
else
null,
.cursor_text = if (config.@"cursor-text") |txt|
txt.toTerminalRGB()
else
null,
.background = config.background.toTerminalRGB(),
.foreground = config.foreground.toTerminalRGB(),
@ -1222,8 +1228,10 @@ fn rebuildCells(
}
if (cursor_cell) |*cell| {
// We always invert the cell color under the cursor.
cell.color = .{ 0, 0, 0, 255 };
cell.color = if (self.config.cursor_text) |txt|
.{ txt.r, txt.g, txt.b, 255 }
else
.{ 0, 0, 0, 255 };
self.cells.appendAssumeCapacity(cell.*);
}
}

View File

@ -237,6 +237,7 @@ pub const DerivedConfig = struct {
font_thicken: bool,
font_features: std.ArrayList([]const u8),
cursor_color: ?terminal.color.RGB,
cursor_text: ?terminal.color.RGB,
background: terminal.color.RGB,
background_opacity: f64,
foreground: terminal.color.RGB,
@ -264,6 +265,11 @@ pub const DerivedConfig = struct {
else
null,
.cursor_text = if (config.@"cursor-text") |txt|
txt.toTerminalRGB()
else
null,
.background = config.background.toTerminalRGB(),
.foreground = config.foreground.toTerminalRGB(),
@ -999,10 +1005,17 @@ pub fn rebuildCells(
}
if (cursor_cell) |*cell| {
if (self.config.cursor_text) |txt| {
cell.fg_r = txt.r;
cell.fg_g = txt.g;
cell.fg_b = txt.b;
cell.fg_a = 255;
} else {
cell.fg_r = 0;
cell.fg_g = 0;
cell.fg_b = 0;
cell.fg_a = 255;
}
self.cells.appendAssumeCapacity(cell.*);
}
}