diff --git a/book/src/generated/typable-cmd.md b/book/src/generated/typable-cmd.md index 653acf60cac1f..f29cc2c799e1d 100644 --- a/book/src/generated/typable-cmd.md +++ b/book/src/generated/typable-cmd.md @@ -28,7 +28,7 @@ | `:quit-all!`, `:qa!` | Force close all views ignoring unsaved changes. | | `:cquit`, `:cq` | Quit with exit code (default 1). Accepts an optional integer exit code (:cq 2). | | `:cquit!`, `:cq!` | Force quit with exit code (default 1) ignoring unsaved changes. Accepts an optional integer exit code (:cq! 2). | -| `:theme` | Change the editor theme. | +| `:theme` | Change the editor theme (show current theme if no name specified). | | `:clipboard-yank` | Yank main selection into system clipboard. | | `:clipboard-yank-join` | Yank joined selections into system clipboard. A separator can be provided as first argument. Default value is newline. | | `:primary-clipboard-yank` | Yank main selection into system primary clipboard. | diff --git a/helix-term/src/commands/typed.rs b/helix-term/src/commands/typed.rs index f005d9bf62450..c2f1f25ea6262 100644 --- a/helix-term/src/commands/typed.rs +++ b/helix-term/src/commands/typed.rs @@ -725,16 +725,21 @@ fn theme( }; } PromptEvent::Validate => { - let theme_name = args.first().with_context(|| "Theme name not provided")?; - let theme = cx - .editor - .theme_loader - .load(theme_name) - .with_context(|| "Theme does not exist")?; - if !(true_color || theme.is_16_color()) { - bail!("Unsupported theme: theme requires true color support"); + if let Some(theme_name) = args.first() { + let theme = cx + .editor + .theme_loader + .load(theme_name) + .with_context(|| "Theme does not exist")?; + if !(true_color || theme.is_16_color()) { + bail!("Unsupported theme: theme requires true color support"); + } + cx.editor.set_theme(theme); + } else { + let name = cx.editor.theme.name().to_string(); + + cx.editor.set_status(name); } - cx.editor.set_theme(theme); } }; @@ -1720,7 +1725,7 @@ pub const TYPABLE_COMMAND_LIST: &[TypableCommand] = &[ TypableCommand { name: "theme", aliases: &[], - doc: "Change the editor theme.", + doc: "Change the editor theme (show current theme if no name specified).", fun: theme, completer: Some(completers::theme), }, diff --git a/helix-view/src/theme.rs b/helix-view/src/theme.rs index fa5fa702804b0..6b8ff972db63b 100644 --- a/helix-view/src/theme.rs +++ b/helix-view/src/theme.rs @@ -12,11 +12,14 @@ use toml::Value; pub use crate::graphics::{Color, Modifier, Style}; -pub static DEFAULT_THEME: Lazy = Lazy::new(|| { - toml::from_slice(include_bytes!("../../theme.toml")).expect("Failed to parse default theme") +pub static DEFAULT_THEME: Lazy = Lazy::new(|| Theme { + name: "theme".into(), + ..toml::from_slice(include_bytes!("../../theme.toml")).expect("Failed to parse default theme") }); -pub static BASE16_DEFAULT_THEME: Lazy = Lazy::new(|| { - toml::from_slice(include_bytes!("../../base16_theme.toml")) + +pub static BASE16_DEFAULT_THEME: Lazy = Lazy::new(|| Theme { + name: "base16_theme".into(), + ..toml::from_slice(include_bytes!("../../base16_theme.toml")) .expect("Failed to parse base 16 default theme") }); @@ -52,7 +55,13 @@ impl Loader { }; let data = std::fs::read(&path)?; - toml::from_slice(data.as_slice()).context("Failed to deserialize theme") + + let theme = Theme { + name: name.into(), + ..toml::from_slice(data.as_slice()).context("Failed to deserialize theme")? + }; + + Ok(theme) } pub fn read_names(path: &Path) -> Vec { @@ -96,8 +105,10 @@ impl Loader { } } -#[derive(Clone, Debug)] +#[derive(Clone, Debug, Default)] pub struct Theme { + name: String, + // UI styles are stored in a HashMap styles: HashMap, // tree-sitter highlight styles are stored in a Vec to optimize lookups @@ -147,6 +158,7 @@ impl<'de> Deserialize<'de> for Theme { scopes, styles, highlights, + ..Default::default() }) } } @@ -157,6 +169,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() }