Skip to content

Commit

Permalink
Theme::new/update(theme_name: String -> &str)
Browse files Browse the repository at this point in the history
  • Loading branch information
gibbz00 committed Feb 16, 2023
1 parent 6fde0e1 commit 6335989
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 9 deletions.
3 changes: 1 addition & 2 deletions helix-term/src/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -381,8 +381,7 @@ impl Application {
}

if let Some(theme_name) = &self.config.load().theme {
self.editor
.set_theme(self.editor.theme.update(theme_name.clone())?);
self.editor.set_theme(self.editor.theme.update(theme_name)?);
}

Ok(())
Expand Down
5 changes: 2 additions & 3 deletions helix-term/src/commands/typed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -780,15 +780,14 @@ fn theme(
// Ensures that a preview theme gets cleaned up if the user backspaces until the prompt is empty.
cx.editor.unset_theme_preview();
} else if let Some(theme_name) = args.first() {
if let Ok(theme) = cx.editor.theme.update(theme_name.to_string()) {
if let Ok(theme) = cx.editor.theme.update(theme_name) {
cx.editor.set_theme_preview(theme);
};
};
}
PromptEvent::Validate => {
if let Some(theme_name) = args.first() {
cx.editor
.set_theme(cx.editor.theme.update(theme_name.to_string())?);
cx.editor.set_theme(cx.editor.theme.update(theme_name)?);
} else {
let name = cx.editor.theme.name().to_string();
cx.editor.set_status(name);
Expand Down
3 changes: 2 additions & 1 deletion helix-term/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ async fn main_impl() -> Result<i32> {
}
}
};
let theme = Theme::new(config.theme.clone(), true_color_support).unwrap_or_else(|err| {

let theme = Theme::new(config.theme.as_deref(), true_color_support).unwrap_or_else(|err| {
eprintln!("Bad theme config: {}", err);
eprintln!("Press <ENTER> to continue with default theme config");
let _wait_for_enter = std::io::Read::read(&mut std::io::stdin(), &mut []);
Expand Down
6 changes: 3 additions & 3 deletions helix-view/src/theme.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ pub struct Theme {
}

impl Theme {
pub fn new(theme_name: Option<String>, true_color_support: bool) -> Result<Theme> {
pub fn new(theme_name: Option<&str>, true_color_support: bool) -> Result<Theme> {
if let Some(theme_name) = theme_name {
let theme = Self::load(&theme_name)?;
let theme = Self::load(theme_name)?;
if !true_color_support && !theme.is_16_color() {
anyhow::bail!("Unsupported theme: theme requires true color support")
}
Expand All @@ -70,7 +70,7 @@ impl Theme {
}
}

pub fn update(&self, theme_name: String) -> Result<Theme> {
pub fn update(&self, theme_name: &str) -> Result<Theme> {
Self::new(Some(theme_name), self.true_color_support)
}

Expand Down

0 comments on commit 6335989

Please sign in to comment.