Skip to content

Themes separation #13314

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion helix-term/src/commands/typed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2930,7 +2930,29 @@ pub const TYPABLE_COMMAND_LIST: &[TypableCommand] = &[
aliases: &[],
doc: "Change the editor theme (show current theme if no name specified).",
fun: theme,
completer: CommandCompleter::positional(&[completers::theme]),
completer: CommandCompleter::positional(&[|_editor, input| completers::theme(_editor, input, "all")]),
signature: Signature {
positionals: (0, Some(1)),
..Signature::DEFAULT
},
},
TypableCommand {
name: "theme-dark",
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")]),
signature: Signature {
positionals: (0, Some(1)),
..Signature::DEFAULT
},
},
TypableCommand {
name: "theme-light",
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")]),
signature: Signature {
positionals: (0, Some(1)),
..Signature::DEFAULT
Expand Down
32 changes: 26 additions & 6 deletions helix-term/src/ui/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -399,13 +399,33 @@ pub mod completers {
.collect()
}

pub fn theme(_editor: &Editor, input: &str) -> Vec<Completion> {
let mut names = theme::Loader::read_names(&helix_loader::config_dir().join("themes"));
pub fn theme(_editor: &Editor, input: &str, themes_type : &str) -> Vec<Completion> {
let themes_dirs = match themes_type {
"dark" => vec!["themes/dark"],
"light" => vec!["themes/light"],
// The first element should not have any effect
_ => vec!["themes","themes/light","themes/dark"]
};

let mut names = Vec::new();
for rt_dir in helix_loader::runtime_dirs() {
names.extend(theme::Loader::read_names(&rt_dir.join("themes")));
}
names.push("default".into());
names.push("base16_default".into());
for themes_dir in &themes_dirs {
names.extend(theme::Loader::read_names(&rt_dir.join(themes_dir)));
};
};

for themes_dir in &themes_dirs {
names.extend(theme::Loader::read_names(&helix_loader::config_dir().join(themes_dir)));
};

match themes_type {
"light" => (),
"dark" => { names.push("default".into());
},
_ => { names.push("base16_default".into());
names.push("default".into());
}
};
names.sort();
names.dedup();

Expand Down
12 changes: 10 additions & 2 deletions helix-view/src/theme.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,25 @@ pub struct Loader {
/// Theme directories to search from highest to lowest priority
theme_dirs: Vec<PathBuf>,
}

impl Loader {
/// Creates a new loader that can load themes from multiple directories.
///
/// The provided directories should be ordered from highest to lowest priority.
/// The directories will have their "themes" subdirectory searched.
/// The directories will have their "themes/dark", "themes/light" and "themes" subdirectory searched.
pub fn new(dirs: &[PathBuf]) -> Self {
let theme_dirs: Vec<_> = dirs.iter()
.flat_map(|p| {
vec![p.join("themes/dark"), p.join("themes/light"), p.join("themes")]
})
.collect();

Self {
theme_dirs: dirs.iter().map(|p| p.join("themes")).collect(),
theme_dirs,
}
}


/// Loads a theme searching directories in priority order.
pub fn load(&self, name: &str) -> Result<Theme> {
let (theme, warnings) = self.load_with_warnings(name)?;
Expand Down
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.
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.