on master help sign in
Improve error handling for config-reload (#3668)
9c627c6A-Walrus
helix-term/src/application.rs+29−19
@@ -366,29 +366,39 @@ impl Application {
366 self.editor.refresh_config();
366 self.editor.refresh_config();
367 }
367 }
368
368
369− fn refresh_config(&mut self) {
369+ /// Refresh theme after config change
370− let config = Config::load_default().unwrap_or_else(|err| {
370+ fn refresh_theme(&mut self, config: &Config) {
371− self.editor.set_error(err.to_string());
372− Config::default()
373− });
374−
375− // Refresh theme
376 if let Some(theme) = config.theme.clone() {
371 if let Some(theme) = config.theme.clone() {
377 let true_color = self.true_color();
372 let true_color = self.true_color();
378− self.editor.set_theme(
379− self.theme_loader
373+ match self.theme_loader.load(&theme) {
380− .load(&theme)
374+ Ok(theme) => {
381− .map_err(|e| {
375+ if true_color || theme.is_16_color() {
376+ self.editor.set_theme(theme);
377+ } else {
378+ self.editor
379+ .set_error("theme requires truecolor support, which is not available");
380+ }
381+ }
382+ Err(err) => {
382− log::warn!("failed to load theme `{}` - {}", theme, e);
383+ let err_string = format!("failed to load theme `{}` - {}", theme, err);
383− e
384+ self.editor.set_error(err_string);
384− })
385+ }
385− .ok()
386+ }
386− .filter(|theme| (true_color || theme.is_16_color()))
387− .unwrap_or_else(|| self.theme_loader.default_theme(true_color)),
388− );
389 }
387 }
388+ }
390
389
390+ fn refresh_config(&mut self) {
391+ match Config::load_default() {
392+ Ok(config) => {
393+ self.refresh_theme(&config);
394+
395+ // Store new config
391− self.config.store(Arc::new(config));
396+ self.config.store(Arc::new(config));
397+ }
398+ Err(err) => {
399+ self.editor.set_error(err.to_string());
400+ }
401+ }
392 }
402 }
393
403
394 fn true_color(&self) -> bool {
404 fn true_color(&self) -> bool {