From dfdff1c3e76044c7ee2b4d9aa34177cb1af2f56f Mon Sep 17 00:00:00 2001 From: Gregory Anders Date: Tue, 7 Jan 2025 11:50:46 -0600 Subject: [PATCH] renderer: respect reverse with cursor-invert-fg-bg --- src/renderer/Metal.zig | 14 ++++++++++++-- src/renderer/OpenGL.zig | 14 ++++++++++++-- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/src/renderer/Metal.zig b/src/renderer/Metal.zig index 5ad45da8e3..65679f0819 100644 --- a/src/renderer/Metal.zig +++ b/src/renderer/Metal.zig @@ -2650,8 +2650,13 @@ fn rebuildCells( const style = cursor_style_ orelse break :cursor; const cursor_color = self.cursor_color orelse self.default_cursor_color orelse color: { if (self.cursor_invert) { + // Use the foreground color from the cell under the cursor, if any. const sty = screen.cursor.page_pin.style(screen.cursor.page_cell); - break :color sty.fg(color_palette, self.config.bold_is_bright) orelse self.foreground_color orelse self.default_foreground_color; + break :color (if (sty.flags.inverse) + // If the cell is reversed, use background color instead. + sty.bg(screen.cursor.page_cell, color_palette) + else + sty.fg(color_palette, self.config.bold_is_bright)) orelse self.foreground_color orelse self.default_foreground_color; } else { break :color self.foreground_color orelse self.default_foreground_color; } @@ -2680,8 +2685,13 @@ fn rebuildCells( }; const uniform_color = if (self.cursor_invert) blk: { + // Use the background color from the cell under the cursor, if any. const sty = screen.cursor.page_pin.style(screen.cursor.page_cell); - break :blk sty.bg(screen.cursor.page_cell, color_palette) orelse self.background_color orelse self.default_background_color; + break :blk (if (sty.flags.inverse) + // If the cell is reversed, use foreground color instead. + sty.fg(color_palette, self.config.bold_is_bright) + else + sty.bg(screen.cursor.page_cell, color_palette)) orelse self.background_color orelse self.default_background_color; } else if (self.config.cursor_text) |txt| txt else diff --git a/src/renderer/OpenGL.zig b/src/renderer/OpenGL.zig index 157354d1dc..115f994350 100644 --- a/src/renderer/OpenGL.zig +++ b/src/renderer/OpenGL.zig @@ -1737,8 +1737,13 @@ pub fn rebuildCells( const cursor_color = self.cursor_color orelse self.default_cursor_color orelse color: { if (self.cursor_invert) { + // Use the foreground color from the cell under the cursor, if any. const sty = screen.cursor.page_pin.style(screen.cursor.page_cell); - break :color sty.fg(color_palette, self.config.bold_is_bright) orelse self.foreground_color orelse self.default_foreground_color; + break :color (if (sty.flags.inverse) + // If the cell is reversed, use background color instead. + sty.bg(screen.cursor.page_cell, color_palette) + else + sty.fg(color_palette, self.config.bold_is_bright)) orelse self.foreground_color orelse self.default_foreground_color; } else { break :color self.foreground_color orelse self.default_foreground_color; } @@ -1748,8 +1753,13 @@ pub fn rebuildCells( for (cursor_cells.items) |*cell| { if (cell.mode.isFg() and cell.mode != .fg_color) { const cell_color = if (self.cursor_invert) blk: { + // Use the background color from the cell under the cursor, if any. const sty = screen.cursor.page_pin.style(screen.cursor.page_cell); - break :blk sty.bg(screen.cursor.page_cell, color_palette) orelse self.background_color orelse self.default_background_color; + break :blk (if (sty.flags.inverse) + // If the cell is reversed, use foreground color instead. + sty.fg(color_palette, self.config.bold_is_bright) + else + sty.bg(screen.cursor.page_cell, color_palette)) orelse self.background_color orelse self.default_background_color; } else if (self.config.cursor_text) |txt| txt else