Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'helix-term/src/application.rs')
| -rw-r--r-- | helix-term/src/application.rs | 40 |
1 files changed, 36 insertions, 4 deletions
diff --git a/helix-term/src/application.rs b/helix-term/src/application.rs index 9ee02a53..cf8ab233 100644 --- a/helix-term/src/application.rs +++ b/helix-term/src/application.rs @@ -77,6 +77,8 @@ pub struct Application { signals: Signals, jobs: Jobs, lsp_progress: LspProgressMap, + + theme_mode: Option<theme::Mode>, } #[cfg(feature = "integration")] @@ -121,6 +123,7 @@ impl Application { #[cfg(feature = "integration")] let backend = TestBackend::new(120, 150); + let theme_mode = backend.get_theme_mode(); let terminal = Terminal::new(backend)?; let area = terminal.size().expect("couldn't get terminal size"); let mut compositor = Compositor::new(area); @@ -139,6 +142,7 @@ impl Application { &mut editor, &config.load(), terminal.backend().supports_true_color(), + theme_mode, ); let keys = Box::new(Map::new(Arc::clone(&config), |config: &Config| { @@ -258,6 +262,7 @@ impl Application { signals, jobs: Jobs::new(), lsp_progress: LspProgressMap::new(), + theme_mode, }; Ok(app) @@ -416,6 +421,7 @@ impl Application { &mut self.editor, &default_config, self.terminal.backend().supports_true_color(), + self.theme_mode, ); // Re-parse any open documents with the new language config. @@ -449,12 +455,18 @@ impl Application { } /// Load the theme set in configuration - fn load_configured_theme(editor: &mut Editor, config: &Config, terminal_true_color: bool) { + fn load_configured_theme( + editor: &mut Editor, + config: &Config, + terminal_true_color: bool, + mode: Option<theme::Mode>, + ) { let true_color = terminal_true_color || config.editor.true_color || crate::true_color(); let theme = config .theme .as_ref() - .and_then(|theme| { + .and_then(|theme_config| { + let theme = theme_config.choose(mode); editor .theme_loader .load(theme) @@ -672,6 +684,9 @@ impl Application { } pub async fn handle_terminal_events(&mut self, event: std::io::Result<TerminalEvent>) { + #[cfg(not(windows))] + use termina::escape::csi; + let mut cx = crate::compositor::Context { editor: &mut self.editor, jobs: &mut self.jobs, @@ -698,6 +713,16 @@ impl Application { kind: termina::event::KeyEventKind::Release, .. }) => false, + #[cfg(not(windows))] + termina::Event::Csi(csi::Csi::Mode(csi::Mode::ReportTheme(mode))) => { + Self::load_configured_theme( + &mut self.editor, + &self.config.load(), + self.terminal.backend().supports_true_color(), + Some(mode.into()), + ); + true + } #[cfg(windows)] TerminalEvent::Resize(width, height) => { self.terminal @@ -1167,9 +1192,16 @@ impl Application { #[cfg(all(not(feature = "integration"), not(windows)))] pub fn event_stream(&self) -> impl Stream<Item = std::io::Result<TerminalEvent>> + Unpin { - use termina::Terminal as _; + use termina::{escape::csi, Terminal as _}; let reader = self.terminal.backend().terminal().event_reader(); - termina::EventStream::new(reader, |event| !event.is_escape()) + termina::EventStream::new(reader, |event| { + // Accept either non-escape sequences or theme mode updates. + !event.is_escape() + || matches!( + event, + termina::Event::Csi(csi::Csi::Mode(csi::Mode::ReportTheme(_))) + ) + }) } #[cfg(all(not(feature = "integration"), windows))] |