Implement cursor text in addition to color

This commit is contained in:
Kevin Hovsäter
2023-08-25 14:52:29 +02:00
parent 73ff43590c
commit 8b9a11db4b
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. /// The color of the cursor. If this is not set, a default will be chosen.
@"cursor-color": ?Color = null, @"cursor-color": ?Color = null,
@"cursor-text": ?Color = null,
/// The opacity level (opposite of transparency) of the background. /// The opacity level (opposite of transparency) of the background.
/// A value of 1 is fully opaque and a value of 0 is fully transparent. /// 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_thicken: bool,
font_features: std.ArrayList([]const u8), font_features: std.ArrayList([]const u8),
cursor_color: ?terminal.color.RGB, cursor_color: ?terminal.color.RGB,
cursor_text: ?terminal.color.RGB,
background: terminal.color.RGB, background: terminal.color.RGB,
background_opacity: f64, background_opacity: f64,
foreground: terminal.color.RGB, foreground: terminal.color.RGB,
@ -135,6 +136,11 @@ pub const DerivedConfig = struct {
else else
null, null,
.cursor_text = if (config.@"cursor-text") |txt|
txt.toTerminalRGB()
else
null,
.background = config.background.toTerminalRGB(), .background = config.background.toTerminalRGB(),
.foreground = config.foreground.toTerminalRGB(), .foreground = config.foreground.toTerminalRGB(),
@ -1222,8 +1228,10 @@ fn rebuildCells(
} }
if (cursor_cell) |*cell| { if (cursor_cell) |*cell| {
// We always invert the cell color under the cursor. cell.color = if (self.config.cursor_text) |txt|
cell.color = .{ 0, 0, 0, 255 }; .{ txt.r, txt.g, txt.b, 255 }
else
.{ 0, 0, 0, 255 };
self.cells.appendAssumeCapacity(cell.*); self.cells.appendAssumeCapacity(cell.*);
} }
} }

View File

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