on master help sign in
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.

commitab819d80f1391667f8ff6b149fa4fbe977f4607a authorPascal Kuthe <pascal.kuthe@semimod.de> dateThu 30 Mar 2023, 17:56 (4 years ago) parent67783dd
1 file changed+16−17
helix-term/src/application.rs+16−17
helix-term/src/application.rs+16−17
@@ -393,20 +393,23 @@ impl Application {
393393
394394 /// Refresh theme after config change
395395 fn refresh_theme(&mut self, config: &Config) -> Result<(), Error> {
396− if let Some(theme) = config.theme.clone() {
397− let true_color = self.true_color();
398− let theme = self
399− .theme_loader
400− .load(&theme)
401− .map_err(|err| anyhow::anyhow!("Failed to load theme `{}`: {}", theme, err))?;
402−
403− if true_color || theme.is_16_color() {
404− self.editor.set_theme(theme);
405− } else {
406− anyhow::bail!("theme requires truecolor support, which is not available")
407− }
408− }
396+ let true_color = config.editor.true_color || crate::true_color();
397+ let theme = config
398+ .theme
399+ .as_ref()
400+ .and_then(|theme| {
401+ self.theme_loader
402+ .load(theme)
403+ .map_err(|e| {
404+ log::warn!("failed to load theme `{}` - {}", theme, e);
405+ e
406+ })
407+ .ok()
408+ .filter(|theme| (true_color || theme.is_16_color()))
409+ })
410+ .unwrap_or_else(|| self.theme_loader.default_theme(true_color));
409411
412+ self.editor.set_theme(theme);
410413 Ok(())
411414 }
412415
@@ -431,10 +434,6 @@ impl Application {
431434 }
432435 }
433436
434− fn true_color(&self) -> bool {
435− self.config.load().editor.true_color || crate::true_color()
436− }
437−
438437 #[cfg(windows)]
439438 // no signal handling available on windows
440439 pub async fn handle_signals(&mut self, _signal: ()) {}