Skip to content

Commit 02bb285

Browse files
author
Lucas Renaudineau
committed
Separation of the themes dark/light.
Fixes #11990
1 parent d24e4fc commit 02bb285

File tree

162 files changed

+59
-9
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

162 files changed

+59
-9
lines changed

helix-term/src/commands/typed.rs

+23-1
Original file line numberDiff line numberDiff line change
@@ -2930,7 +2930,29 @@ pub const TYPABLE_COMMAND_LIST: &[TypableCommand] = &[
29302930
aliases: &[],
29312931
doc: "Change the editor theme (show current theme if no name specified).",
29322932
fun: theme,
2933-
completer: CommandCompleter::positional(&[completers::theme]),
2933+
completer: CommandCompleter::positional(&[|_editor, input| completers::theme(_editor, input, "all")]),
2934+
signature: Signature {
2935+
positionals: (0, Some(1)),
2936+
..Signature::DEFAULT
2937+
},
2938+
},
2939+
TypableCommand {
2940+
name: "theme-dark",
2941+
aliases: &[],
2942+
doc: "Change the editor theme to a dark theme (show current theme if no name specified).",
2943+
fun: theme,
2944+
completer: CommandCompleter::positional(&[|_editor, input| completers::theme(_editor, input, "dark")]),
2945+
signature: Signature {
2946+
positionals: (0, Some(1)),
2947+
..Signature::DEFAULT
2948+
},
2949+
},
2950+
TypableCommand {
2951+
name: "theme-light",
2952+
aliases: &[],
2953+
doc: "Change the editor theme to a light theme (show current theme if no name specified).",
2954+
fun: theme,
2955+
completer: CommandCompleter::positional(&[|_editor, input| completers::theme(_editor, input, "light")]),
29342956
signature: Signature {
29352957
positionals: (0, Some(1)),
29362958
..Signature::DEFAULT

helix-term/src/ui/mod.rs

+26-6
Original file line numberDiff line numberDiff line change
@@ -399,13 +399,33 @@ pub mod completers {
399399
.collect()
400400
}
401401

402-
pub fn theme(_editor: &Editor, input: &str) -> Vec<Completion> {
403-
let mut names = theme::Loader::read_names(&helix_loader::config_dir().join("themes"));
402+
pub fn theme(_editor: &Editor, input: &str, themes_type : &str) -> Vec<Completion> {
403+
let themes_dirs = match themes_type {
404+
"dark" => vec!["themes/dark"],
405+
"light" => vec!["themes/light"],
406+
// The first element should not have any effect
407+
_ => vec!["themes","themes/light","themes/dark"]
408+
};
409+
410+
let mut names = Vec::new();
404411
for rt_dir in helix_loader::runtime_dirs() {
405-
names.extend(theme::Loader::read_names(&rt_dir.join("themes")));
406-
}
407-
names.push("default".into());
408-
names.push("base16_default".into());
412+
for themes_dir in &themes_dirs {
413+
names.extend(theme::Loader::read_names(&rt_dir.join(themes_dir)));
414+
};
415+
};
416+
417+
for themes_dir in &themes_dirs {
418+
names.extend(theme::Loader::read_names(&helix_loader::config_dir().join(themes_dir)));
419+
};
420+
421+
match themes_type {
422+
"light" => (),
423+
"dark" => { names.push("default".into());
424+
},
425+
_ => { names.push("base16_default".into());
426+
names.push("default".into());
427+
}
428+
};
409429
names.sort();
410430
names.dedup();
411431

helix-view/src/theme.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,25 @@ pub struct Loader {
4040
/// Theme directories to search from highest to lowest priority
4141
theme_dirs: Vec<PathBuf>,
4242
}
43+
4344
impl Loader {
4445
/// Creates a new loader that can load themes from multiple directories.
4546
///
4647
/// The provided directories should be ordered from highest to lowest priority.
47-
/// The directories will have their "themes" subdirectory searched.
48+
/// The directories will have their "themes/dark", "themes/light" and "themes" subdirectory searched.
4849
pub fn new(dirs: &[PathBuf]) -> Self {
50+
let theme_dirs: Vec<_> = dirs.iter()
51+
.flat_map(|p| {
52+
vec![p.join("themes/dark"), p.join("themes/light"), p.join("themes")]
53+
})
54+
.collect();
55+
4956
Self {
50-
theme_dirs: dirs.iter().map(|p| p.join("themes")).collect(),
57+
theme_dirs,
5158
}
5259
}
5360

61+
5462
/// Loads a theme searching directories in priority order.
5563
pub fn load(&self, name: &str) -> Result<Theme> {
5664
let (theme, warnings) = self.load_with_warnings(name)?;
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)