Skip to content

Commit

Permalink
Remove Option wrapper for Config.theme
Browse files Browse the repository at this point in the history
Does so by assuming empty string implyies default theme in Theme::new.
Paves the way to make Config::default() to be derivable.
  • Loading branch information
gibbz00 committed Feb 16, 2023
1 parent 53273ce commit 5e9d0a1
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
5 changes: 2 additions & 3 deletions helix-term/src/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -355,9 +355,8 @@ impl Application {
document.detect_language(self.editor.lang_configs_loader.clone());
}

if let Some(theme_name) = &self.config.load().theme {
self.editor.set_theme(Theme::new(theme_name)?);
}
self.editor
.set_theme(Theme::new(&self.config.load().theme)?);

Ok(())
};
Expand Down
4 changes: 2 additions & 2 deletions helix-term/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::collections::HashMap;
#[derive(Debug, Clone, PartialEq, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct Config {
pub theme: Option<String>,
pub theme: String,
#[serde(default = "default::default")]
pub keys: HashMap<Mode, KeyTrie>,
#[serde(default)]
Expand Down Expand Up @@ -43,7 +43,7 @@ impl Config {
impl Default for Config {
fn default() -> Config {
Config {
theme: None,
theme: String::default(),
keys: default::default(),
editor: helix_view::editor::EditorConfig::default(),
}
Expand Down
5 changes: 1 addition & 4 deletions helix-term/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,7 @@ async fn main_impl() -> Result<i32> {
.map(|v| matches!(v.as_str(), "truecolor" | "24bit"))
.unwrap_or(false),
);
let theme: Theme = match config.theme.as_deref() {
Some(theme_name) => check_config_load(Theme::new(theme_name), None, "theme"),
None => Theme::default(),
};
let theme_name = check_config_load(Theme::new(theme_name), None, "theme");

// TODO: use the thread local executor to spawn the application task separately from the work pool
let mut app = Application::new(args, config, theme, language_configurations)
Expand Down
12 changes: 8 additions & 4 deletions helix-view/src/theme.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,15 @@ impl Theme {
}

pub fn new(theme_name: &str) -> Result<Theme> {
let theme = Self::load(theme_name)?;
if !Self::get_true_color_support() && !theme.is_16_color() {
anyhow::bail!("Unsupported theme: theme requires true color support")
if theme_name.is_empty() {
Ok(Self::default())
} else {
let theme = Self::load(theme_name)?;
if !Self::get_true_color_support() && !theme.is_16_color() {
anyhow::bail!("Unsupported theme: true color support is required")
}
Ok(theme)
}
Ok(theme)
}

/// Recursively load a theme, merging with any inherited parent themes.
Expand Down

0 comments on commit 5e9d0a1

Please sign in to comment.