diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/config/mod.rs | 12 | ||||
-rw-r--r-- | src/term/mod.rs | 15 |
2 files changed, 25 insertions, 2 deletions
diff --git a/src/config/mod.rs b/src/config/mod.rs index 4b9e1f8e..b8dd9f82 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -1285,6 +1285,8 @@ pub struct Colors { pub primary: PrimaryColors, #[serde(deserialize_with = "failure_default")] pub cursor: CursorColors, + #[serde(deserialize_with = "failure_default")] + pub selection: SelectionColors, #[serde(deserialize_with = "deserialize_normal_colors")] pub normal: AnsiColors, #[serde(deserialize_with = "deserialize_bright_colors")] @@ -1300,6 +1302,7 @@ impl Default for Colors { Colors { primary: Default::default(), cursor: Default::default(), + selection: Default::default(), normal: default_normal_colors(), bright: default_bright_colors(), dim: Default::default(), @@ -1422,6 +1425,15 @@ pub struct CursorColors { } #[serde(default)] +#[derive(Debug, Copy, Clone, Default, Deserialize, PartialEq, Eq)] +pub struct SelectionColors { + #[serde(deserialize_with = "deserialize_optional_color")] + pub text: Option<Rgb>, + #[serde(deserialize_with = "deserialize_optional_color")] + pub background: Option<Rgb>, +} + +#[serde(default)] #[derive(Debug, Deserialize, PartialEq, Eq)] pub struct PrimaryColors { #[serde(deserialize_with = "rgb_from_hex")] diff --git a/src/term/mod.rs b/src/term/mod.rs index fc59ffd6..f48ad699 100644 --- a/src/term/mod.rs +++ b/src/term/mod.rs @@ -455,17 +455,28 @@ impl<'a> Iterator for RenderableCellsIter<'a> { (cell, selected) }; - // Apply inversion and lookup RGB values + // Lookup RGB values let mut fg_rgb = self.compute_fg_rgb(cell.fg, &cell); let mut bg_rgb = self.compute_bg_rgb(cell.bg); - let bg_alpha = if selected ^ cell.inverse() { + let selection_background = self.config.colors().selection.background; + let bg_alpha = if let (true, Some(col)) = (selected, selection_background) { + // Override selection background with config colors + bg_rgb = col; + 1.0 + } else if selected ^ cell.inverse() { + // Invert cell fg and bg colors mem::swap(&mut fg_rgb, &mut bg_rgb); self.compute_bg_alpha(cell.fg) } else { self.compute_bg_alpha(cell.bg) }; + // Override selection text with config colors + if let (true, Some(col)) = (selected, self.config.colors().selection.text) { + fg_rgb = col; + } + return Some(RenderableCell { line: cell.line, column: cell.column, |