Skip to content

Commit 5e9d0a1

Browse files
committed
Remove Option wrapper for Config.theme
Does so by assuming empty string implyies default theme in Theme::new. Paves the way to make Config::default() to be derivable.
1 parent 53273ce commit 5e9d0a1

File tree

4 files changed

+13
-13
lines changed

4 files changed

+13
-13
lines changed

helix-term/src/application.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -355,9 +355,8 @@ impl Application {
355355
document.detect_language(self.editor.lang_configs_loader.clone());
356356
}
357357

358-
if let Some(theme_name) = &self.config.load().theme {
359-
self.editor.set_theme(Theme::new(theme_name)?);
360-
}
358+
self.editor
359+
.set_theme(Theme::new(&self.config.load().theme)?);
361360

362361
Ok(())
363362
};

helix-term/src/config.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use std::collections::HashMap;
77
#[derive(Debug, Clone, PartialEq, Deserialize)]
88
#[serde(deny_unknown_fields)]
99
pub struct Config {
10-
pub theme: Option<String>,
10+
pub theme: String,
1111
#[serde(default = "default::default")]
1212
pub keys: HashMap<Mode, KeyTrie>,
1313
#[serde(default)]
@@ -43,7 +43,7 @@ impl Config {
4343
impl Default for Config {
4444
fn default() -> Config {
4545
Config {
46-
theme: None,
46+
theme: String::default(),
4747
keys: default::default(),
4848
editor: helix_view::editor::EditorConfig::default(),
4949
}

helix-term/src/main.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,7 @@ async fn main_impl() -> Result<i32> {
6464
.map(|v| matches!(v.as_str(), "truecolor" | "24bit"))
6565
.unwrap_or(false),
6666
);
67-
let theme: Theme = match config.theme.as_deref() {
68-
Some(theme_name) => check_config_load(Theme::new(theme_name), None, "theme"),
69-
None => Theme::default(),
70-
};
67+
let theme_name = check_config_load(Theme::new(theme_name), None, "theme");
7168

7269
// TODO: use the thread local executor to spawn the application task separately from the work pool
7370
let mut app = Application::new(args, config, theme, language_configurations)

helix-view/src/theme.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,15 @@ impl Theme {
6161
}
6262

6363
pub fn new(theme_name: &str) -> Result<Theme> {
64-
let theme = Self::load(theme_name)?;
65-
if !Self::get_true_color_support() && !theme.is_16_color() {
66-
anyhow::bail!("Unsupported theme: theme requires true color support")
64+
if theme_name.is_empty() {
65+
Ok(Self::default())
66+
} else {
67+
let theme = Self::load(theme_name)?;
68+
if !Self::get_true_color_support() && !theme.is_16_color() {
69+
anyhow::bail!("Unsupported theme: true color support is required")
70+
}
71+
Ok(theme)
6772
}
68-
Ok(theme)
6973
}
7074

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

0 commit comments

Comments
 (0)