on master help sign in
commands: Make no arg ':theme' show name (#3740)
ac0fe29James O. D. Hunt
book/src/generated/typable-cmd.md+1−1
@@ -28,7 +28,7 @@
28| `:quit-all!`, `:qa!` | Force close all views ignoring unsaved changes. |
28| `:quit-all!`, `:qa!` | Force close all views ignoring unsaved changes. |
29| `:cquit`, `:cq` | Quit with exit code (default 1). Accepts an optional integer exit code (:cq 2). |
29| `:cquit`, `:cq` | Quit with exit code (default 1). Accepts an optional integer exit code (:cq 2). |
30| `:cquit!`, `:cq!` | Force quit with exit code (default 1) ignoring unsaved changes. Accepts an optional integer exit code (:cq! 2). |
30| `:cquit!`, `:cq!` | Force quit with exit code (default 1) ignoring unsaved changes. Accepts an optional integer exit code (:cq! 2). |
31−| `:theme` | Change the editor theme. |
31+| `:theme` | Change the editor theme (show current theme if no name specified). |
32| `:clipboard-yank` | Yank main selection into system clipboard. |
32| `:clipboard-yank` | Yank main selection into system clipboard. |
33| `:clipboard-yank-join` | Yank joined selections into system clipboard. A separator can be provided as first argument. Default value is newline. |
33| `:clipboard-yank-join` | Yank joined selections into system clipboard. A separator can be provided as first argument. Default value is newline. |
34| `:primary-clipboard-yank` | Yank main selection into system primary clipboard. |
34| `:primary-clipboard-yank` | Yank main selection into system primary clipboard. |
helix-term/src/commands/typed.rs+15−10
@@ -772,16 +772,21 @@ fn theme(
772 };
772 };
773 }
773 }
774 PromptEvent::Validate => {
774 PromptEvent::Validate => {
775− let theme_name = args.first().with_context(|| "Theme name not provided")?;
775+ if let Some(theme_name) = args.first() {
776− let theme = cx
776+ let theme = cx
777− .editor
777+ .editor
778− .theme_loader
778+ .theme_loader
779− .load(theme_name)
779+ .load(theme_name)
780− .with_context(|| "Theme does not exist")?;
780+ .with_context(|| "Theme does not exist")?;
781− if !(true_color || theme.is_16_color()) {
781+ if !(true_color || theme.is_16_color()) {
782− bail!("Unsupported theme: theme requires true color support");
782+ bail!("Unsupported theme: theme requires true color support");
783+ }
784+ cx.editor.set_theme(theme);
785+ } else {
786+ let name = cx.editor.theme.name().to_string();
787+
788+ cx.editor.set_status(name);
783 }
789 }
784− cx.editor.set_theme(theme);
785 }
790 }
786 };
791 };
787
792
@@ -1866,7 +1871,7 @@ pub const TYPABLE_COMMAND_LIST: &[TypableCommand] = &[
1866 TypableCommand {
1871 TypableCommand {
1867 name: "theme",
1872 name: "theme",
1868 aliases: &[],
1873 aliases: &[],
1869− doc: "Change the editor theme.",
1874+ doc: "Change the editor theme (show current theme if no name specified).",
1870 fun: theme,
1875 fun: theme,
1871 completer: Some(completers::theme),
1876 completer: Some(completers::theme),
1872 },
1877 },
helix-view/src/theme.rs+21−13
@@ -14,19 +14,14 @@ use toml::{map::Map, Value};
14use crate::graphics::UnderlineStyle;
14use crate::graphics::UnderlineStyle;
15pub use crate::graphics::{Color, Modifier, Style};
15pub use crate::graphics::{Color, Modifier, Style};
16
16
17−pub static DEFAULT_THEME: Lazy<Theme> = Lazy::new(|| {
17+pub static DEFAULT_THEME: Lazy<Theme> = Lazy::new(|| Theme {
18− // let raw_theme: Value = toml::from_slice(include_bytes!("../../theme.toml"))
18+ name: "default".into(),
19− // .expect("Failed to parse default theme");
20− // Theme::from(raw_theme)
21−
22− toml::from_slice(include_bytes!("../../theme.toml")).expect("Failed to parse default theme")
19+ ..toml::from_slice(include_bytes!("../../theme.toml")).expect("Failed to parse default theme")
23});
20});
24−pub static BASE16_DEFAULT_THEME: Lazy<Theme> = Lazy::new(|| {
25− // let raw_theme: Value = toml::from_slice(include_bytes!("../../base16_theme.toml"))
26− // .expect("Failed to parse base 16 default theme");
27− // Theme::from(raw_theme)
28
21
22+pub static BASE16_DEFAULT_THEME: Lazy<Theme> = Lazy::new(|| Theme {
23+ name: "base16_theme".into(),
29− toml::from_slice(include_bytes!("../../base16_theme.toml"))
24+ ..toml::from_slice(include_bytes!("../../base16_theme.toml"))
30 .expect("Failed to parse base 16 default theme")
25 .expect("Failed to parse base 16 default theme")
31});
26});
32
27
@@ -53,7 +48,12 @@ impl Loader {
53 return Ok(self.base16_default());
48 return Ok(self.base16_default());
54 }
49 }
55
50
56− self.load_theme(name, name, false).map(Theme::from)
51+ let theme = self.load_theme(name, name, false).map(Theme::from)?;
52+
53+ Ok(Theme {
54+ name: name.into(),
55+ ..theme
56+ })
57 }
57 }
58
58
59 // load the theme and its parent recursively and merge them
59 // load the theme and its parent recursively and merge them
@@ -180,8 +180,10 @@ impl Loader {
180 }
180 }
181}
181}
182
182
183−#[derive(Clone, Debug)]
183+#[derive(Clone, Debug, Default)]
184pub struct Theme {
184pub struct Theme {
185+ name: String,
186+
185 // UI styles are stored in a HashMap
187 // UI styles are stored in a HashMap
186 styles: HashMap<String, Style>,
188 styles: HashMap<String, Style>,
187 // tree-sitter highlight styles are stored in a Vec to optimize lookups
189 // tree-sitter highlight styles are stored in a Vec to optimize lookups
@@ -200,6 +202,7 @@ impl From<Value> for Theme {
200 styles,
202 styles,
201 scopes,
203 scopes,
202 highlights,
204 highlights,
205+ ..Default::default()
203 }
206 }
204 }
207 }
205}
208}
@@ -217,6 +220,7 @@ impl<'de> Deserialize<'de> for Theme {
217 styles,
220 styles,
218 scopes,
221 scopes,
219 highlights,
222 highlights,
223+ ..Default::default()
220 })
224 })
221 }
225 }
222}
226}
@@ -266,6 +270,10 @@ impl Theme {
266 self.highlights[index]
270 self.highlights[index]
267 }
271 }
268
272
273+ pub fn name(&self) -> &str {
274+ &self.name
275+ }
276+
269 pub fn get(&self, scope: &str) -> Style {
277 pub fn get(&self, scope: &str) -> Style {
270 self.try_get(scope).unwrap_or_default()
278 self.try_get(scope).unwrap_or_default()
271 }
279 }