diff --git a/README.md b/README.md index 0b08bfd17..5381cb5d2 100644 --- a/README.md +++ b/README.md @@ -127,7 +127,7 @@ usual hex notation; eg: `#000000` is equivalent to `black`: [colors] foreground = "silver" background = "black" -cursor = "springgreen" +cursor_bg = "springgreen" ansi = ["black", "maroon", "green", "olive", "navy", "purple", "teal", "silver"] brights = ["grey", "red", "lime", "yellow", "blue", "fuchsia", "aqua", "white"] ``` diff --git a/src/config.rs b/src/config.rs index 74d1d667e..bfbfe5bb8 100644 --- a/src/config.rs +++ b/src/config.rs @@ -160,7 +160,11 @@ pub struct Palette { /// The background color to use when the attributes are reset to default pub background: Option, /// The color of the cursor - pub cursor: Option, + pub cursor_fg: Option, + pub cursor_bg: Option, + /// The color of selected text + pub selection_fg: Option, + pub selection_bg: Option, /// A list of 8 colors corresponding to the basic ANSI palette pub ansi: Option<[RgbColor; 8]>, /// A list of 8 colors corresponding to bright versions of the @@ -171,15 +175,20 @@ pub struct Palette { impl From for term::color::ColorPalette { fn from(cfg: Palette) -> term::color::ColorPalette { let mut p = term::color::ColorPalette::default(); - if let Some(foreground) = cfg.foreground { - p.foreground = foreground; - } - if let Some(background) = cfg.background { - p.background = background; - } - if let Some(cursor) = cfg.cursor { - p.cursor = cursor; + macro_rules! apply_color { + ($name:ident) => { + if let Some($name) = cfg.$name { + p.$name = $name; + } + }; } + apply_color!(foreground); + apply_color!(background); + apply_color!(cursor_fg); + apply_color!(cursor_bg); + apply_color!(selection_fg); + apply_color!(selection_bg); + if let Some(ansi) = cfg.ansi { for (idx, col) in ansi.iter().enumerate() { p.colors[idx] = *col; diff --git a/src/opengl/render.rs b/src/opengl/render.rs index d11d26237..c641bbf93 100644 --- a/src/opengl/render.rs +++ b/src/opengl/render.rs @@ -864,16 +864,15 @@ impl Renderer { let (fg_color, bg_color) = match (selected, is_cursor) { // Normally, render the cell as configured (false, false) => (fg_color, bg_color), - // Cursor cell always renders with background over cursor color + // Cursor cell overrides colors (_, true) => ( - self.palette.background.to_linear_tuple_rgba(), - self.palette.cursor.to_linear_tuple_rgba(), + self.palette.cursor_fg.to_linear_tuple_rgba(), + self.palette.cursor_bg.to_linear_tuple_rgba(), ), - // Selection text colors the background + // Selected text overrides colors (true, false) => ( - fg_color, - // TODO: configurable selection color - self.palette.cursor.to_linear_tuple_rgba(), + self.palette.selection_fg.to_linear_tuple_rgba(), + self.palette.selection_bg.to_linear_tuple_rgba(), ), }; diff --git a/term/src/color.rs b/term/src/color.rs index 0996c6aca..09999d0bc 100644 --- a/term/src/color.rs +++ b/term/src/color.rs @@ -119,7 +119,10 @@ pub struct ColorPalette { pub colors: [RgbColor; 256], pub foreground: RgbColor, pub background: RgbColor, - pub cursor: RgbColor, + pub cursor_fg: RgbColor, + pub cursor_bg: RgbColor, + pub selection_fg: RgbColor, + pub selection_bg: RgbColor, } impl ColorPalette { @@ -131,10 +134,6 @@ impl ColorPalette { &ColorAttribute::Rgb(color) => color, } } - - pub fn cursor(&self) -> RgbColor { - self.cursor - } } impl Default for ColorPalette { @@ -268,13 +267,20 @@ impl Default for ColorPalette { let foreground = colors[249]; // Grey70 let background = colors[AnsiColor::Black as usize]; - let cursor = RgbColor::new(0x52, 0xad, 0x70); + let cursor_bg = RgbColor::new(0x52, 0xad, 0x70); + let cursor_fg = colors[AnsiColor::Black as usize]; + + let selection_fg = colors[AnsiColor::Black as usize]; + let selection_bg = RgbColor::new(0xff, 0xfa, 0xcd); ColorPalette { colors, foreground, background, - cursor, + cursor_fg, + cursor_bg, + selection_fg, + selection_bg, } } }