diff --git a/src/config.rs b/src/config.rs index 49eb079..350842c 100644 --- a/src/config.rs +++ b/src/config.rs @@ -290,11 +290,17 @@ impl Config { } } - pub fn color_scheme_kind(&self) -> ColorSchemeKind { - if self.app_theme.theme().theme_type.is_dark() { - ColorSchemeKind::Dark - } else { - ColorSchemeKind::Light + pub fn color_scheme_kind(&self, system_theme: &theme::Theme) -> ColorSchemeKind { + match self.app_theme { + AppTheme::Dark => ColorSchemeKind::Dark, + AppTheme::Light => ColorSchemeKind::Light, + AppTheme::System => { + if system_theme.theme_type.is_dark() { + ColorSchemeKind::Dark + } else { + ColorSchemeKind::Light + } + } } } @@ -358,8 +364,11 @@ impl Config { } // Get current syntax theme based on dark mode - pub fn syntax_theme(&self, profile_id_opt: Option) -> (String, ColorSchemeKind) { - let color_scheme_kind = self.color_scheme_kind(); + pub fn syntax_theme( + &self, + color_scheme_kind: ColorSchemeKind, + profile_id_opt: Option, + ) -> (String, ColorSchemeKind) { let theme_name = match profile_id_opt.and_then(|profile_id| self.profiles.get(&profile_id)) { Some(profile) => match color_scheme_kind { diff --git a/src/main.rs b/src/main.rs index b9682fe..3bf9e7f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -688,11 +688,12 @@ impl App { } // Set config of all tabs + let color_scheme_kind = self.config.color_scheme_kind(&theme); for (_pane, tab_model) in self.pane_model.panes.iter() { for entity in tab_model.iter() { if let Some(terminal) = tab_model.data::>(entity) { let mut terminal = terminal.lock().unwrap(); - terminal.set_config(&self.config, &self.themes); + terminal.set_config(&self.config, color_scheme_kind, &self.themes); } } } @@ -708,6 +709,7 @@ impl App { // skip writing config to fs when zoom in/ out // recalculate the pane due to the changes of zoom_adj value // but only for the active pane/tab + let color_scheme_kind = self.config.color_scheme_kind(self.core.system_theme()); if let Some(tab_model) = self.pane_model.active() { for entity in tab_model.iter() { if tab_model.is_active(entity) @@ -724,7 +726,7 @@ impl App { } _ => {} } - terminal.set_config(&self.config, &self.themes); + terminal.set_config(&self.config, color_scheme_kind, &self.themes); } } } @@ -1552,10 +1554,11 @@ impl App { self.pane_model.set_focus(pane); match &self.term_event_tx_opt { Some(term_event_tx) => { + let color_scheme_kind = self.config.color_scheme_kind(self.core.system_theme()); let colors = self .themes - .get(&self.config.syntax_theme(profile_id_opt)) - .or_else(|| match self.config.color_scheme_kind() { + .get(&self.config.syntax_theme(color_scheme_kind, profile_id_opt)) + .or_else(|| match color_scheme_kind { ColorSchemeKind::Dark => self .themes .get(&(config::COSMIC_THEME_DARK.to_string(), ColorSchemeKind::Dark)), @@ -1632,7 +1635,11 @@ impl App { tab_title_override, ) { Ok(mut terminal) => { - terminal.set_config(&self.config, &self.themes); + terminal.set_config( + &self.config, + color_scheme_kind, + &self.themes, + ); tab_model .data_set::>(entity, Mutex::new(terminal)); } @@ -1671,7 +1678,7 @@ impl App { None => { log::error!( "failed to find terminal theme {:?}", - self.config.syntax_theme(profile_id_opt) + self.config.syntax_theme(color_scheme_kind, profile_id_opt) ); //TODO: fall back to known good theme } diff --git a/src/menu.rs b/src/menu.rs index 6007c1d..b71cbb8 100644 --- a/src/menu.rs +++ b/src/menu.rs @@ -206,6 +206,8 @@ pub fn menu_bar<'a>( //TODO: what to do if there are no profiles? + let color_scheme_kind = config.color_scheme_kind(core.system_theme()); + responsive_menu_bar() .item_height(ItemHeight::Dynamic(40)) .item_width(ItemWidth::Uniform(320)) @@ -267,7 +269,7 @@ pub fn menu_bar<'a>( MenuItem::Button( fl!("menu-color-schemes"), None, - Action::ColorSchemes(config.color_scheme_kind()), + Action::ColorSchemes(color_scheme_kind), ), MenuItem::Button( fl!("menu-keyboard-shortcuts"), diff --git a/src/terminal.rs b/src/terminal.rs index 87f25ef..8c1b22f 100644 --- a/src/terminal.rs +++ b/src/terminal.rs @@ -613,6 +613,7 @@ impl Terminal { pub fn set_config( &mut self, config: &AppConfig, + color_scheme_kind: ColorSchemeKind, themes: &HashMap<(String, ColorSchemeKind), Colors>, ) { let mut update_cell_size = false; @@ -655,7 +656,9 @@ impl Terminal { update_cell_size = true; } - if let Some(colors) = themes.get(&config.syntax_theme(self.profile_id_opt)) { + if let Some(colors) = + themes.get(&config.syntax_theme(color_scheme_kind, self.profile_id_opt)) + { let mut changed = false; for i in 0..color::COUNT { if self.colors[i] != colors[i] {