fix: avoid re-reading system theme from disk on every menu bar render
This commit is contained in:
parent
8c042673e7
commit
18b4450c0f
4 changed files with 36 additions and 15 deletions
|
|
@ -290,13 +290,19 @@ impl Config {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn color_scheme_kind(&self) -> ColorSchemeKind {
|
||||
if self.app_theme.theme().theme_type.is_dark() {
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Get a sorted and adjusted for duplicates list of color scheme names and ids
|
||||
pub fn color_scheme_names(
|
||||
|
|
@ -358,8 +364,11 @@ impl Config {
|
|||
}
|
||||
|
||||
// Get current syntax theme based on dark mode
|
||||
pub fn syntax_theme(&self, profile_id_opt: Option<ProfileId>) -> (String, ColorSchemeKind) {
|
||||
let color_scheme_kind = self.color_scheme_kind();
|
||||
pub fn syntax_theme(
|
||||
&self,
|
||||
color_scheme_kind: ColorSchemeKind,
|
||||
profile_id_opt: Option<ProfileId>,
|
||||
) -> (String, ColorSchemeKind) {
|
||||
let theme_name = match profile_id_opt.and_then(|profile_id| self.profiles.get(&profile_id))
|
||||
{
|
||||
Some(profile) => match color_scheme_kind {
|
||||
|
|
|
|||
19
src/main.rs
19
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::<Mutex<Terminal>>(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::<Mutex<Terminal>>(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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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"),
|
||||
|
|
|
|||
|
|
@ -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] {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue