Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

osc12: add function to set the terminal cursor color #112

Merged
merged 1 commit into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/Vaxis.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions src/ctlseqs.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading