modification of types : str to enum

pull/13314/head
Lucas Renaudineau 2025-05-05 15:14:26 +02:00
parent b2d004304a
commit 57c8792f4a
2 changed files with 18 additions and 10 deletions

View File

@ -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

View File

@ -368,7 +368,14 @@ fn directory_content(path: &Path) -> Result<Vec<(PathBuf, bool)>, 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<Completion> {
pub fn theme(_editor: &Editor, input: &str, themes_type : ThemesType) -> Vec<Completion> {
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());
}
};