diff --git a/helix-term/src/commands/typed.rs b/helix-term/src/commands/typed.rs index 222f3880b..456c05a82 100644 --- a/helix-term/src/commands/typed.rs +++ b/helix-term/src/commands/typed.rs @@ -16,6 +16,7 @@ use helix_view::editor::{CloseError, ConfigEvent}; use helix_view::expansion; use serde_json::Value; use ui::completers::{self, Completer}; +use crate::ui::ThemesType; #[derive(Clone)] pub struct TypableCommand { @@ -2930,7 +2931,7 @@ pub const TYPABLE_COMMAND_LIST: &[TypableCommand] = &[ aliases: &[], doc: "Change the editor theme (show current theme if no name specified).", fun: theme, - completer: CommandCompleter::positional(&[|_editor, input| completers::theme(_editor, input, "all")]), + completer: CommandCompleter::positional(&[|_editor, input| completers::theme(_editor, input, ThemesType::All)]), signature: Signature { positionals: (0, Some(1)), ..Signature::DEFAULT @@ -2941,7 +2942,7 @@ pub const TYPABLE_COMMAND_LIST: &[TypableCommand] = &[ aliases: &[], doc: "Change the editor theme to a dark theme (show current theme if no name specified).", fun: theme, - completer: CommandCompleter::positional(&[|_editor, input| completers::theme(_editor, input, "dark")]), + completer: CommandCompleter::positional(&[|_editor, input| completers::theme(_editor, input, ThemesType::Dark)]), signature: Signature { positionals: (0, Some(1)), ..Signature::DEFAULT @@ -2952,7 +2953,7 @@ pub const TYPABLE_COMMAND_LIST: &[TypableCommand] = &[ aliases: &[], doc: "Change the editor theme to a light theme (show current theme if no name specified).", fun: theme, - completer: CommandCompleter::positional(&[|_editor, input| completers::theme(_editor, input, "light")]), + completer: CommandCompleter::positional(&[|_editor, input| completers::theme(_editor, input, ThemesType::Light)]), signature: Signature { positionals: (0, Some(1)), ..Signature::DEFAULT diff --git a/helix-term/src/ui/mod.rs b/helix-term/src/ui/mod.rs index a5cd7443e..f2ec58eeb 100644 --- a/helix-term/src/ui/mod.rs +++ b/helix-term/src/ui/mod.rs @@ -368,7 +368,14 @@ fn directory_content(path: &Path) -> Result, std::io::Error Ok(content) } +pub enum ThemesType { + Dark, + Light, + All +} + pub mod completers { + use super::ThemesType; use super::Utf8PathBuf; use crate::ui::prompt::Completion; use helix_core::fuzzy::fuzzy_match; @@ -399,12 +406,12 @@ pub mod completers { .collect() } - pub fn theme(_editor: &Editor, input: &str, themes_type : &str) -> Vec { + pub fn theme(_editor: &Editor, input: &str, themes_type : ThemesType) -> Vec { let themes_dirs = match themes_type { - "dark" => vec!["themes/dark"], - "light" => vec!["themes/light"], + ThemesType::Dark => vec!["themes/dark"], + ThemesType::Light => vec!["themes/light"], // The first element should not have any effect - _ => vec!["themes","themes/light","themes/dark"] + ThemesType::All => vec!["themes","themes/light","themes/dark"] }; let mut names = Vec::new(); @@ -419,10 +426,10 @@ pub mod completers { }; match themes_type { - "light" => (), - "dark" => { names.push("default".into()); + ThemesType::Light => (), + ThemesType::Dark => { names.push("default".into()); }, - _ => { names.push("base16_default".into()); + ThemesType::All => { names.push("base16_default".into()); names.push("default".into()); } };