osc12: add function to set the terminal cursor color

This commit is contained in:
CJ van den Berg 2024-11-07 10:18:02 +01:00 committed by Tim Culverhouse
parent dc0a228a55
commit 22dcdb6bf3
2 changed files with 12 additions and 0 deletions

View file

@ -85,6 +85,7 @@ state: struct {
in_band_resize: bool = false,
changed_default_fg: bool = false,
changed_default_bg: bool = false,
changed_cursor_color: bool = false,
cursor: struct {
row: u16 = 0,
col: u16 = 0,
@ -163,6 +164,10 @@ pub fn resetState(self: *Vaxis, tty: AnyWriter) !void {
try tty.writeAll(ctlseqs.osc11_reset);
self.state.changed_default_bg = false;
}
if (self.state.changed_cursor_color) {
try tty.writeAll(ctlseqs.osc12_reset);
self.state.changed_cursor_color = false;
}
}
/// resize allocates a slice of cells equal to the number of cells
@ -929,6 +934,12 @@ pub fn setTerminalBackgroundColor(self: *Vaxis, tty: AnyWriter, rgb: [3]u8) !voi
self.state.changed_default_bg = true;
}
/// Set the terminal cursor color
pub fn setTerminalCursorColor(self: *Vaxis, tty: AnyWriter, rgb: [3]u8) !void {
try tty.print(ctlseqs.osc12_set, .{ rgb[0], rgb[0], rgb[1], rgb[1], rgb[2], rgb[2] });
self.state.changed_cursor_color = true;
}
/// Request a color report from the terminal. Note: not all terminals support
/// reporting colors. It is always safe to try, but you may not receive a
/// response.

View file

@ -137,4 +137,5 @@ pub const osc11_query = "\x1b]11;?\x1b\\"; // bg
pub const osc11_set = "\x1b]11;rgb:{x:0>2}{x:0>2}/{x:0>2}{x:0>2}/{x:0>2}{x:0>2}\x1b\\"; // set default terminal bg
pub const osc11_reset = "\x1b]111\x1b\\"; // reset bg to terminal default
pub const osc12_query = "\x1b]12;?\x1b\\"; // cursor color
pub const osc12_set = "\x1b]12;rgb:{x:0>2}{x:0>2}/{x:0>2}{x:0>2}/{x:0>2}{x:0>2}\x1b\\"; // set terminal cursor color
pub const osc12_reset = "\x1b]112\x1b\\"; // reset cursor to terminal default