diff options
| author | Ogulcan Celik <ogulcancelik@gmail.com> | 2026-06-18 02:52:35 +0300 |
|---|---|---|
| committer | Ogulcan Celik <ogulcancelik@gmail.com> | 2026-06-18 02:53:31 +0300 |
| commit | 36b4001f4526b60f1c9b67a4a34596e5ad2bcca1 (patch) | |
| tree | 520ab28a0a3f3f798e6e655fc83529e8617720e9 /src/app/theme_sync.rs | |
| parent | aca35ea76f3df15ec68fd07959d939f5e7a78a6c (diff) | |
feat: sync theme with host appearance
refs #675
Diffstat (limited to 'src/app/theme_sync.rs')
| -rw-r--r-- | src/app/theme_sync.rs | 60 |
1 files changed, 55 insertions, 5 deletions
diff --git a/src/app/theme_sync.rs b/src/app/theme_sync.rs index a45818df..392d6f59 100644 --- a/src/app/theme_sync.rs +++ b/src/app/theme_sync.rs @@ -16,15 +16,54 @@ impl App { kind: crate::terminal_theme::DefaultColorKind, color: crate::terminal_theme::RgbColor, ) -> bool { + let mut changed = false; + if matches!(kind, crate::terminal_theme::DefaultColorKind::Background) + && !self.state.host_terminal_appearance_explicit + { + changed |= self.set_host_terminal_appearance(color.inferred_appearance(), false); + } let next_theme = self.state.host_terminal_theme.with_color(kind, color); - self.set_host_terminal_theme(next_theme) + changed | self.set_host_terminal_theme(next_theme) + } + + pub(super) fn set_host_terminal_appearance( + &mut self, + appearance: crate::terminal_theme::HostAppearance, + explicit: bool, + ) -> bool { + if self.state.host_terminal_appearance == Some(appearance) + && self.state.host_terminal_appearance_explicit == explicit + { + return false; + } + if self.state.host_terminal_appearance_explicit && !explicit { + return false; + } + self.state.host_terminal_appearance = Some(appearance); + self.state.host_terminal_appearance_explicit = explicit; + self.refresh_effective_app_theme() + } + + pub(crate) fn set_host_terminal_appearance_state( + &mut self, + appearance: Option<crate::terminal_theme::HostAppearance>, + explicit: bool, + ) -> bool { + if self.state.host_terminal_appearance == appearance + && self.state.host_terminal_appearance_explicit == explicit + { + return false; + } + self.state.host_terminal_appearance = appearance; + self.state.host_terminal_appearance_explicit = explicit; + self.refresh_effective_app_theme() } pub(crate) fn set_host_terminal_theme( &mut self, theme: crate::terminal_theme::TerminalTheme, ) -> bool { - if theme.is_empty() || theme == self.state.host_terminal_theme { + if theme == self.state.host_terminal_theme { return false; } self.state.host_terminal_theme = theme; @@ -32,11 +71,22 @@ impl App { true } - fn apply_host_terminal_theme_to_panes(&self) { - if self.state.host_terminal_theme.is_empty() { - return; + pub(super) fn refresh_effective_app_theme(&mut self) -> bool { + let (palette, theme_name) = super::resolve_effective_theme( + &self.state.theme_runtime, + self.state.host_terminal_appearance, + ); + if self.state.theme_name == theme_name && self.state.palette == palette { + return false; } + self.state.theme_name = theme_name; + self.state.palette = palette; + self.render_dirty.store(true, Ordering::Release); + self.render_notify.notify_one(); + true + } + fn apply_host_terminal_theme_to_panes(&self) { for runtime in self.terminal_runtimes.values() { runtime.apply_host_terminal_theme(self.state.host_terminal_theme); } |
