From 0b9ae4ce936dfafbf5ea1929a170c97391cdea0b Mon Sep 17 00:00:00 2001 From: Kirill Chibisov Date: Wed, 13 Mar 2019 02:11:32 +0300 Subject: Add config option to change selection color --- src/config/mod.rs | 12 ++++++++++++ src/term/mod.rs | 15 +++++++++++++-- 2 files changed, 25 insertions(+), 2 deletions(-) (limited to 'src') 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(), @@ -1421,6 +1424,15 @@ pub struct CursorColors { pub cursor: Option, } +#[serde(default)] +#[derive(Debug, Copy, Clone, Default, Deserialize, PartialEq, Eq)] +pub struct SelectionColors { + #[serde(deserialize_with = "deserialize_optional_color")] + pub text: Option, + #[serde(deserialize_with = "deserialize_optional_color")] + pub background: Option, +} + #[serde(default)] #[derive(Debug, Deserialize, PartialEq, Eq)] pub struct PrimaryColors { 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, -- cgit