mirror of https://github.com/helix-editor/helix
modification of types : str to enum
parent
b2d004304a
commit
57c8792f4a
|
@ -16,6 +16,7 @@ use helix_view::editor::{CloseError, ConfigEvent};
|
||||||
use helix_view::expansion;
|
use helix_view::expansion;
|
||||||
use serde_json::Value;
|
use serde_json::Value;
|
||||||
use ui::completers::{self, Completer};
|
use ui::completers::{self, Completer};
|
||||||
|
use crate::ui::ThemesType;
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct TypableCommand {
|
pub struct TypableCommand {
|
||||||
|
@ -2930,7 +2931,7 @@ pub const TYPABLE_COMMAND_LIST: &[TypableCommand] = &[
|
||||||
aliases: &[],
|
aliases: &[],
|
||||||
doc: "Change the editor theme (show current theme if no name specified).",
|
doc: "Change the editor theme (show current theme if no name specified).",
|
||||||
fun: theme,
|
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 {
|
signature: Signature {
|
||||||
positionals: (0, Some(1)),
|
positionals: (0, Some(1)),
|
||||||
..Signature::DEFAULT
|
..Signature::DEFAULT
|
||||||
|
@ -2941,7 +2942,7 @@ pub const TYPABLE_COMMAND_LIST: &[TypableCommand] = &[
|
||||||
aliases: &[],
|
aliases: &[],
|
||||||
doc: "Change the editor theme to a dark theme (show current theme if no name specified).",
|
doc: "Change the editor theme to a dark theme (show current theme if no name specified).",
|
||||||
fun: theme,
|
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 {
|
signature: Signature {
|
||||||
positionals: (0, Some(1)),
|
positionals: (0, Some(1)),
|
||||||
..Signature::DEFAULT
|
..Signature::DEFAULT
|
||||||
|
@ -2952,7 +2953,7 @@ pub const TYPABLE_COMMAND_LIST: &[TypableCommand] = &[
|
||||||
aliases: &[],
|
aliases: &[],
|
||||||
doc: "Change the editor theme to a light theme (show current theme if no name specified).",
|
doc: "Change the editor theme to a light theme (show current theme if no name specified).",
|
||||||
fun: theme,
|
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 {
|
signature: Signature {
|
||||||
positionals: (0, Some(1)),
|
positionals: (0, Some(1)),
|
||||||
..Signature::DEFAULT
|
..Signature::DEFAULT
|
||||||
|
|
|
@ -368,7 +368,14 @@ fn directory_content(path: &Path) -> Result<Vec<(PathBuf, bool)>, std::io::Error
|
||||||
Ok(content)
|
Ok(content)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub enum ThemesType {
|
||||||
|
Dark,
|
||||||
|
Light,
|
||||||
|
All
|
||||||
|
}
|
||||||
|
|
||||||
pub mod completers {
|
pub mod completers {
|
||||||
|
use super::ThemesType;
|
||||||
use super::Utf8PathBuf;
|
use super::Utf8PathBuf;
|
||||||
use crate::ui::prompt::Completion;
|
use crate::ui::prompt::Completion;
|
||||||
use helix_core::fuzzy::fuzzy_match;
|
use helix_core::fuzzy::fuzzy_match;
|
||||||
|
@ -399,12 +406,12 @@ pub mod completers {
|
||||||
.collect()
|
.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 {
|
let themes_dirs = match themes_type {
|
||||||
"dark" => vec!["themes/dark"],
|
ThemesType::Dark => vec!["themes/dark"],
|
||||||
"light" => vec!["themes/light"],
|
ThemesType::Light => vec!["themes/light"],
|
||||||
// The first element should not have any effect
|
// 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();
|
let mut names = Vec::new();
|
||||||
|
@ -419,10 +426,10 @@ pub mod completers {
|
||||||
};
|
};
|
||||||
|
|
||||||
match themes_type {
|
match themes_type {
|
||||||
"light" => (),
|
ThemesType::Light => (),
|
||||||
"dark" => { names.push("default".into());
|
ThemesType::Dark => { names.push("default".into());
|
||||||
},
|
},
|
||||||
_ => { names.push("base16_default".into());
|
ThemesType::All => { names.push("base16_default".into());
|
||||||
names.push("default".into());
|
names.push("default".into());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue