Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Default theme palette using 16 terminal colors #699

Merged
merged 2 commits into from
Sep 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions book/src/themes.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,26 @@ black = "#000000"

Remember that the `[palette]` table includes all keys after its header,
so you should define the palette after normal theme options.

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 |
| --- |
| `black` |
| `red` |
| `green` |
| `yellow` |
| `blue` |
| `magenta` |
| `cyan` |
| `gray` |
| `light-red` |
| `light-green` |
| `light-yellow` |
| `light-blue` |
| `light-magenta` |
| `light-cyan` |
| `light-gray` |
| `white` |
6 changes: 3 additions & 3 deletions helix-view/src/graphics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,13 +224,13 @@ pub enum Color {
Magenta,
Cyan,
Gray,
DarkGray,
LightRed,
LightGreen,
LightYellow,
LightBlue,
LightMagenta,
LightCyan,
LightGray,
White,
Rgb(u8, u8, u8),
Indexed(u8),
Expand All @@ -250,14 +250,14 @@ impl From<Color> for crossterm::style::Color {
Color::Blue => CColor::DarkBlue,
Color::Magenta => CColor::DarkMagenta,
Color::Cyan => CColor::DarkCyan,
Color::Gray => CColor::Grey,
Color::DarkGray => CColor::DarkGrey,
Color::Gray => CColor::DarkGrey,
Color::LightRed => CColor::Red,
Color::LightGreen => CColor::Green,
Color::LightBlue => CColor::Blue,
Color::LightYellow => CColor::Yellow,
Color::LightMagenta => CColor::Magenta,
Color::LightCyan => CColor::Cyan,
Color::LightGray => CColor::Grey,
Color::White => CColor::White,
Color::Indexed(i) => CColor::AnsiValue(i),
Color::Rgb(r, g, b) => CColor::Rgb { r, g, b },
Expand Down
29 changes: 27 additions & 2 deletions helix-view/src/theme.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use std::{
};

use anyhow::Context;
use helix_core::hashmap;
use log::warn;
use once_cell::sync::Lazy;
use serde::{Deserialize, Deserializer};
Expand Down Expand Up @@ -142,13 +143,37 @@ struct ThemePalette {

impl Default for ThemePalette {
fn default() -> Self {
Self::new(HashMap::new())
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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't all of this the same as

let theme = ThemePalette::default();
theme.palette(palette);
theme

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But there is no palette method on ThemePalette ? Also we are merging the user palette onto the default palette so that the defaults can be overridden.

Self { palette: default }
}

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