aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPascal Kuthe2023-03-30 15:56:10 +0000
committerBlaž Hrastnik2023-03-31 06:19:25 +0000
commitab819d80f1391667f8ff6b149fa4fbe977f4607a (patch)
treec02fd313489e1cd23b7f750be1497ae3bde260a6
parent67783ddfd4fc7f06bd6addaa6d65d49759934ace (diff)
Correctly reload theme on :config-reload
The current implementation didn't reload the theme if no no theme was explicitly configured (so the default theme was used). This commit brings `refresh_theme` in line with the initialization code.
-rw-r--r--helix-term/src/application.rs33
1 files changed, 16 insertions, 17 deletions
diff --git a/helix-term/src/application.rs b/helix-term/src/application.rs
index 4d903eec..130a74af 100644
--- a/helix-term/src/application.rs
+++ b/helix-term/src/application.rs
@@ -393,20 +393,23 @@ impl Application {
/// Refresh theme after config change
fn refresh_theme(&mut self, config: &Config) -> Result<(), Error> {
- if let Some(theme) = config.theme.clone() {
- let true_color = self.true_color();
- let theme = self
- .theme_loader
- .load(&theme)
- .map_err(|err| anyhow::anyhow!("Failed to load theme `{}`: {}", theme, err))?;
-
- if true_color || theme.is_16_color() {
- self.editor.set_theme(theme);
- } else {
- anyhow::bail!("theme requires truecolor support, which is not available")
- }
- }
+ let true_color = config.editor.true_color || crate::true_color();
+ let theme = config
+ .theme
+ .as_ref()
+ .and_then(|theme| {
+ self.theme_loader
+ .load(theme)
+ .map_err(|e| {
+ log::warn!("failed to load theme `{}` - {}", theme, e);
+ e
+ })
+ .ok()
+ .filter(|theme| (true_color || theme.is_16_color()))
+ })
+ .unwrap_or_else(|| self.theme_loader.default_theme(true_color));
+ self.editor.set_theme(theme);
Ok(())
}
@@ -431,10 +434,6 @@ impl Application {
}
}
- fn true_color(&self) -> bool {
- self.config.load().editor.true_color || crate::true_color()
- }
-
#[cfg(windows)]
// no signal handling available on windows
pub async fn handle_signals(&mut self, _signal: ()) {}