diff options
author | James O. D. Hunt | 2022-10-26 02:59:50 +0000 |
---|---|---|
committer | GitHub | 2022-10-26 02:59:50 +0000 |
commit | ac0fe29867012ba0840ee7c8893b41d976d5ab38 (patch) | |
tree | 0034ee4dae556a32ea2066b712314561a9d7369d /helix-view/src | |
parent | ba9e50e93b43f102de352ead57c28d86c34a7c73 (diff) |
commands: Make no arg ':theme' show name (#3740)
Most commands that accept an argument show their current value if no
argument is specified. The `:theme` command previously displayed an
error message in the status bar if not provided with an argument:
```
Theme name not provided
```
It now shows the current theme name in the status bar if no argument is
specified.
Signed-off-by: James O. D. Hunt <jamesodhunt@gmail.com>
Signed-off-by: James O. D. Hunt <jamesodhunt@gmail.com>
Diffstat (limited to 'helix-view/src')
-rw-r--r-- | helix-view/src/theme.rs | 34 |
1 files changed, 21 insertions, 13 deletions
diff --git a/helix-view/src/theme.rs b/helix-view/src/theme.rs index 302844b7..f1219ec5 100644 --- a/helix-view/src/theme.rs +++ b/helix-view/src/theme.rs @@ -14,19 +14,14 @@ use toml::{map::Map, Value}; use crate::graphics::UnderlineStyle; pub use crate::graphics::{Color, Modifier, Style}; -pub static DEFAULT_THEME: Lazy<Theme> = Lazy::new(|| { - // let raw_theme: Value = toml::from_slice(include_bytes!("../../theme.toml")) - // .expect("Failed to parse default theme"); - // Theme::from(raw_theme) - - toml::from_slice(include_bytes!("../../theme.toml")).expect("Failed to parse default theme") +pub static DEFAULT_THEME: Lazy<Theme> = Lazy::new(|| Theme { + name: "default".into(), + ..toml::from_slice(include_bytes!("../../theme.toml")).expect("Failed to parse default theme") }); -pub static BASE16_DEFAULT_THEME: Lazy<Theme> = Lazy::new(|| { - // let raw_theme: Value = toml::from_slice(include_bytes!("../../base16_theme.toml")) - // .expect("Failed to parse base 16 default theme"); - // Theme::from(raw_theme) - toml::from_slice(include_bytes!("../../base16_theme.toml")) +pub static BASE16_DEFAULT_THEME: Lazy<Theme> = Lazy::new(|| Theme { + name: "base16_theme".into(), + ..toml::from_slice(include_bytes!("../../base16_theme.toml")) .expect("Failed to parse base 16 default theme") }); @@ -53,7 +48,12 @@ impl Loader { return Ok(self.base16_default()); } - self.load_theme(name, name, false).map(Theme::from) + let theme = self.load_theme(name, name, false).map(Theme::from)?; + + Ok(Theme { + name: name.into(), + ..theme + }) } // load the theme and its parent recursively and merge them @@ -180,8 +180,10 @@ impl Loader { } } -#[derive(Clone, Debug)] +#[derive(Clone, Debug, Default)] pub struct Theme { + name: String, + // UI styles are stored in a HashMap styles: HashMap<String, Style>, // tree-sitter highlight styles are stored in a Vec to optimize lookups @@ -200,6 +202,7 @@ impl From<Value> for Theme { styles, scopes, highlights, + ..Default::default() } } } @@ -217,6 +220,7 @@ impl<'de> Deserialize<'de> for Theme { styles, scopes, highlights, + ..Default::default() }) } } @@ -266,6 +270,10 @@ impl Theme { self.highlights[index] } + pub fn name(&self) -> &str { + &self.name + } + pub fn get(&self, scope: &str) -> Style { self.try_get(scope).unwrap_or_default() } |