make selected and cursor text fg/bg configurable
Previously we only allowed changing the cursor bg color, now we get 4 different color settings for this!
This commit is contained in:
1 parent
3f6a1f758b
commit
90dd732aee
4 files changed
+38
-24
No files matched your search
@@ -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"]
|
||||
```
|
||||
|
||||
+18
-9
@@ -160,7 +160,11 @@ pub struct Palette {
|
||||
/// The background color to use when the attributes are reset to default
|
||||
pub background: Option<RgbColor>,
|
||||
/// The color of the cursor
|
||||
pub cursor: Option<RgbColor>,
|
||||
pub cursor_fg: Option<RgbColor>,
|
||||
pub cursor_bg: Option<RgbColor>,
|
||||
/// The color of selected text
|
||||
pub selection_fg: Option<RgbColor>,
|
||||
pub selection_bg: Option<RgbColor>,
|
||||
/// 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<Palette> 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;
|
||||
|
||||
@@ -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(),
|
||||
),
|
||||
};
|
||||
|
||||
|
||||
+13
-7
@@ -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,
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user