Skip to content

Commit

Permalink
fix: Merge default palette with user palette
Browse files Browse the repository at this point in the history
  • Loading branch information
sudormrfbin authored and archseer committed Sep 5, 2021
1 parent e40e6db commit e4e93e1
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 20 deletions.
4 changes: 3 additions & 1 deletion book/src/themes.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,9 @@ black = "#000000"
Remember that the `[palette]` table includes all keys after its header,
so you should define the palette after normal theme options.

If there is no `[palette]` section, a default palette which uses the terminal's default 16 colors are used:
The default palette uses the terminal's default 16 colors, and the colors names
are listed below. The `[palette]` section in the config file takes precedence
over it and is merged into the default palette.

| Color Name |
| --- |
Expand Down
45 changes: 26 additions & 19 deletions helix-view/src/theme.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,30 +143,37 @@ struct ThemePalette {

impl Default for ThemePalette {
fn default() -> Self {
Self::new(hashmap! {
"black".to_string() => Color::Black,
"red".to_string() => Color::Red,
"green".to_string() => Color::Green,
"yellow".to_string() => Color::Yellow,
"blue".to_string() => Color::Blue,
"magenta".to_string() => Color::Magenta,
"cyan".to_string() => Color::Cyan,
"gray".to_string() => Color::Gray,
"light-red".to_string() => Color::LightRed,
"light-green".to_string() => Color::LightGreen,
"light-yellow".to_string() => Color::LightYellow,
"light-blue".to_string() => Color::LightBlue,
"light-magenta".to_string() => Color::LightMagenta,
"light-cyan".to_string() => Color::LightCyan,
"light-gray".to_string() => Color::LightGray,
"white".to_string() => Color::White,
})
Self {
palette: hashmap! {
"black".to_string() => Color::Black,
"red".to_string() => Color::Red,
"green".to_string() => Color::Green,
"yellow".to_string() => Color::Yellow,
"blue".to_string() => Color::Blue,
"magenta".to_string() => Color::Magenta,
"cyan".to_string() => Color::Cyan,
"gray".to_string() => Color::Gray,
"light-red".to_string() => Color::LightRed,
"light-green".to_string() => Color::LightGreen,
"light-yellow".to_string() => Color::LightYellow,
"light-blue".to_string() => Color::LightBlue,
"light-magenta".to_string() => Color::LightMagenta,
"light-cyan".to_string() => Color::LightCyan,
"light-gray".to_string() => Color::LightGray,
"white".to_string() => Color::White,
},
}
}
}

impl ThemePalette {
pub fn new(palette: HashMap<String, Color>) -> Self {
Self { palette }
let ThemePalette {
palette: mut default,
} = ThemePalette::default();

default.extend(palette);
Self { palette: default }
}

pub fn hex_string_to_rgb(s: &str) -> Result<Color, String> {
Expand Down

0 comments on commit e4e93e1

Please sign in to comment.