From 611760f98b287dfcd155637fa0996f048d038d3f Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sun, 20 Nov 2022 20:35:20 -0800 Subject: [PATCH] ability to customize cursor color --- src/config.zig | 3 +++ src/renderer/Metal.zig | 10 +++++++++- src/renderer/OpenGL.zig | 14 +++++++++++--- 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/src/config.zig b/src/config.zig index 6bb9ddff9..a6526ec43 100644 --- a/src/config.zig +++ b/src/config.zig @@ -52,6 +52,9 @@ pub const Config = struct { /// https://www.ditig.com/256-colors-cheat-sheet palette: Palette = .{}, + /// The color of the cursor. If this is not set, a default will be chosen. + @"cursor-color": ?Color = null, + /// The command to run, usually a shell. If this is not an absolute path, /// it'll be looked up in the PATH. If this is not set, a default will /// be looked up from your system. The rules for the default lookup are: diff --git a/src/renderer/Metal.zig b/src/renderer/Metal.zig index 44eed286b..0868218db 100644 --- a/src/renderer/Metal.zig +++ b/src/renderer/Metal.zig @@ -47,6 +47,7 @@ focused: bool, /// blinking. cursor_visible: bool, cursor_style: renderer.CursorStyle, +cursor_color: ?terminal.color.RGB, /// Default foreground color foreground: terminal.color.RGB, @@ -240,6 +241,7 @@ pub fn init(alloc: Allocator, options: renderer.Options) !Metal { .focused = true, .cursor_visible = true, .cursor_style = .box, + .cursor_color = if (options.config.@"cursor-color") |col| col.toTerminalRGB() else null, .background = options.config.background.toTerminalRGB(), .foreground = options.config.foreground.toTerminalRGB(), .selection_background = if (options.config.@"selection-background") |bg| @@ -921,6 +923,12 @@ fn addCursor(self: *Metal, screen: *terminal.Screen) void { screen.cursor.x, ); + const color = self.cursor_color orelse terminal.color.RGB{ + .r = 0xFF, + .g = 0xFF, + .b = 0xFF, + }; + self.cells.appendAssumeCapacity(.{ .mode = GPUCellMode.fromCursor(self.cursor_style), .grid_pos = .{ @@ -928,7 +936,7 @@ fn addCursor(self: *Metal, screen: *terminal.Screen) void { @intToFloat(f32, screen.cursor.y), }, .cell_width = if (cell.attrs.wide) 2 else 1, - .color = .{ 0xFF, 0xFF, 0xFF, 0xFF }, + .color = .{ color.r, color.g, color.b, 0xFF }, }); } diff --git a/src/renderer/OpenGL.zig b/src/renderer/OpenGL.zig index 41e4f81c5..db274a42e 100644 --- a/src/renderer/OpenGL.zig +++ b/src/renderer/OpenGL.zig @@ -70,6 +70,7 @@ font_shaper: font.Shaper, /// blinking. cursor_visible: bool, cursor_style: renderer.CursorStyle, +cursor_color: ?terminal.color.RGB, /// Default foreground color foreground: terminal.color.RGB, @@ -300,6 +301,7 @@ pub fn init(alloc: Allocator, options: renderer.Options) !OpenGL { .font_shaper = shaper, .cursor_visible = true, .cursor_style = .box, + .cursor_color = if (options.config.@"cursor-color") |col| col.toTerminalRGB() else null, .background = options.config.background.toTerminalRGB(), .foreground = options.config.foreground.toTerminalRGB(), .selection_background = if (options.config.@"selection-background") |bg| @@ -821,6 +823,12 @@ fn addCursor(self: *OpenGL, screen: *terminal.Screen) void { screen.cursor.x, ); + const color = self.cursor_color orelse terminal.color.RGB{ + .r = 0xFF, + .g = 0xFF, + .b = 0xFF, + }; + self.cells.appendAssumeCapacity(.{ .mode = GPUCellMode.fromCursor(self.cursor_style), .grid_col = @intCast(u16, screen.cursor.x), @@ -830,9 +838,9 @@ fn addCursor(self: *OpenGL, screen: *terminal.Screen) void { .fg_g = 0, .fg_b = 0, .fg_a = 0, - .bg_r = 0xFF, - .bg_g = 0xFF, - .bg_b = 0xFF, + .bg_r = color.r, + .bg_g = color.g, + .bg_b = color.b, .bg_a = 255, }); }