diff options
author | Christian Duerr <contact@christianduerr.com> | 2021-10-22 06:33:34 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-10-22 06:33:34 +0000 |
commit | d8a98f88295e59d6518ae780a9857c033a83161c (patch) | |
tree | 8d12246249320520ae8f567236e96d31f988d128 | |
parent | f90dd12efd808c8dcb354bb0667d63dd298cf00c (diff) | |
download | alacritty-d8a98f88295e59d6518ae780a9857c033a83161c.tar.gz alacritty-d8a98f88295e59d6518ae780a9857c033a83161c.zip |
Fix cursor inversion logic
The existing cursor inversion logic was causing more problems than it
solved, without solving the problem of invisible cursor when inverting a
cell with matching foreground and background colors.
This patch reworks this logic and only inverts the cursor when the
foreground and background colors of the cursor are similar and the
cursor colors aren't set to fixed RGB values.
Fixes #4564.
Fixes #5550.
-rw-r--r-- | CHANGELOG.md | 1 | ||||
-rw-r--r-- | alacritty/src/display/content.rs | 25 |
2 files changed, 14 insertions, 12 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 59ad284e..f337f601 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - Line indicator obstructing vi mode cursor when scrolled into history - Vi mode search starting in the line below the vi cursor +- Invisible cursor with matching foreground/background colors ## 0.9.0 diff --git a/alacritty/src/display/content.rs b/alacritty/src/display/content.rs index 2deb3d3e..db73a73b 100644 --- a/alacritty/src/display/content.rs +++ b/alacritty/src/display/content.rs @@ -117,22 +117,23 @@ impl<'a> RenderableContent<'a> { } else { self.config.ui_config.colors.cursor }; - let mut cursor_color = + let cursor_color = self.terminal_content.colors[NamedColor::Cursor].map_or(color.background, CellRgb::Rgb); - let mut text_color = color.foreground; + let text_color = color.foreground; - // Invert the cursor if it has a fixed background close to the cell's background. - if matches!( - cursor_color, - CellRgb::Rgb(color) if color.contrast(cell.bg) < MIN_CURSOR_CONTRAST - ) { - cursor_color = CellRgb::CellForeground; - text_color = CellRgb::CellBackground; - } + let insufficient_contrast = (!matches!(cursor_color, CellRgb::Rgb(_)) + || !matches!(text_color, CellRgb::Rgb(_))) + && cell.fg.contrast(cell.bg) < MIN_CURSOR_CONTRAST; // Convert from cell colors to RGB. - let text_color = text_color.color(cell.fg, cell.bg); - let cursor_color = cursor_color.color(cell.fg, cell.bg); + let mut text_color = text_color.color(cell.fg, cell.bg); + let mut cursor_color = cursor_color.color(cell.fg, cell.bg); + + // Invert cursor color with insufficient contrast to prevent invisible cursors. + if insufficient_contrast { + cursor_color = self.config.ui_config.colors.primary.foreground; + text_color = self.config.ui_config.colors.primary.background; + } Some(RenderableCursor { is_wide: cell.flags.contains(Flags::WIDE_CHAR), |