diff --git a/src/Vaxis.zig b/src/Vaxis.zig index 7024894..b3d4080 100644 --- a/src/Vaxis.zig +++ b/src/Vaxis.zig @@ -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. diff --git a/src/ctlseqs.zig b/src/ctlseqs.zig index 4e55448..61a005f 100644 --- a/src/ctlseqs.zig +++ b/src/ctlseqs.zig @@ -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