diff options
author | A-Walrus | 2022-09-10 13:32:49 +0000 |
---|---|---|
committer | GitHub | 2022-09-10 13:32:49 +0000 |
commit | 9c627c65e55ab71e236d70406feb5d55bd8703bb (patch) | |
tree | 97d97ecbe04df1e751e85bcd65315f8d0a97c17f /helix-term/src/application.rs | |
parent | 75e6a6432747eae6d2255afc52f20ced6902519b (diff) |
Improve error handling for config-reload (#3668)
* Don't change config to default when refreshing invalid config
* Propely handle theme errors with config-reload
* Extract refresh theme into seperate function
Diffstat (limited to 'helix-term/src/application.rs')
-rw-r--r-- | helix-term/src/application.rs | 48 |
1 files changed, 29 insertions, 19 deletions
diff --git a/helix-term/src/application.rs b/helix-term/src/application.rs index 9653b373..ec698321 100644 --- a/helix-term/src/application.rs +++ b/helix-term/src/application.rs @@ -366,29 +366,39 @@ impl Application { self.editor.refresh_config(); } - fn refresh_config(&mut self) { - let config = Config::load_default().unwrap_or_else(|err| { - self.editor.set_error(err.to_string()); - Config::default() - }); - - // Refresh theme + /// Refresh theme after config change + fn refresh_theme(&mut self, config: &Config) { if let Some(theme) = config.theme.clone() { let true_color = self.true_color(); - self.editor.set_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)), - ); + match self.theme_loader.load(&theme) { + Ok(theme) => { + if true_color || theme.is_16_color() { + self.editor.set_theme(theme); + } else { + self.editor + .set_error("theme requires truecolor support, which is not available"); + } + } + Err(err) => { + let err_string = format!("failed to load theme `{}` - {}", theme, err); + self.editor.set_error(err_string); + } + } } + } - self.config.store(Arc::new(config)); + fn refresh_config(&mut self) { + match Config::load_default() { + Ok(config) => { + self.refresh_theme(&config); + + // Store new config + self.config.store(Arc::new(config)); + } + Err(err) => { + self.editor.set_error(err.to_string()); + } + } } fn true_color(&self) -> bool { |