Unnamed repository; edit this file 'description' to name the repository.
Emit OSC11 when previewing a theme, too (#15443)
As an addendum to c10406510aacb0b83efdbe6ec806c80fc0f4611f, also change the terminal background color when previewing a theme.
Jonas Köhnen 4 months ago
parent 0d7e1dc · commit 75e6472
-rw-r--r--helix-term/src/application.rs8
-rw-r--r--helix-term/src/commands/typed.rs9
-rw-r--r--helix-view/src/editor.rs21
3 files changed, 17 insertions, 21 deletions
diff --git a/helix-term/src/application.rs b/helix-term/src/application.rs
index f3b8f49f..ae3b9392 100644
--- a/helix-term/src/application.rs
+++ b/helix-term/src/application.rs
@@ -496,13 +496,7 @@ impl Application {
})
})
.unwrap_or_else(|| editor.theme_loader.default_theme(true_color));
- let background_color = theme
- .try_get_exact("ui.background")
- .and_then(|style| style.bg);
- editor.set_theme(theme);
- let _ = terminal
- .backend_mut()
- .set_background_color(background_color);
+ let _ = editor.set_theme(theme);
}
#[cfg(windows)]
diff --git a/helix-term/src/commands/typed.rs b/helix-term/src/commands/typed.rs
index 8b542eb1..6685691f 100644
--- a/helix-term/src/commands/typed.rs
+++ b/helix-term/src/commands/typed.rs
@@ -1025,18 +1025,18 @@ fn theme(cx: &mut compositor::Context, args: Args, event: PromptEvent) -> anyhow
let true_color = cx.editor.config.load().true_color || crate::true_color();
match event {
PromptEvent::Abort => {
- cx.editor.unset_theme_preview();
+ cx.editor.unset_theme_preview()?;
}
PromptEvent::Update => {
if args.is_empty() {
// Ensures that a preview theme gets cleaned up if the user backspaces until the prompt is empty.
- cx.editor.unset_theme_preview();
+ cx.editor.unset_theme_preview()?;
} else if let Some(theme_name) = args.first() {
if let Ok(theme) = cx.editor.theme_loader.load(theme_name) {
if !(true_color || theme.is_16_color()) {
bail!("Unsupported theme: theme requires true color support");
}
- cx.editor.set_theme_preview(theme);
+ cx.editor.set_theme_preview(theme)?;
};
};
}
@@ -1050,8 +1050,7 @@ fn theme(cx: &mut compositor::Context, args: Args, event: PromptEvent) -> anyhow
if !(true_color || theme.is_16_color()) {
bail!("Unsupported theme: theme requires true color support");
}
- cx.editor.set_theme(theme);
- cx.editor.config_events.0.send(ConfigEvent::ThemeChanged)?;
+ cx.editor.set_theme(theme)?;
} else {
let name = cx.editor.theme.name().to_string();
diff --git a/helix-view/src/editor.rs b/helix-view/src/editor.rs
index 51e7094d..e5ae45c5 100644
--- a/helix-view/src/editor.rs
+++ b/helix-view/src/editor.rs
@@ -1480,26 +1480,26 @@ impl Editor {
.unwrap_or(false)
}
- pub fn unset_theme_preview(&mut self) {
+ pub fn unset_theme_preview(&mut self) -> anyhow::Result<()> {
if let Some(last_theme) = self.last_theme.take() {
- self.set_theme(last_theme);
+ self.set_theme(last_theme)?;
}
// None likely occurs when the user types ":theme" and then exits before previewing
+ Ok(())
}
- pub fn set_theme_preview(&mut self, theme: Theme) {
- self.set_theme_impl(theme, ThemeAction::Preview);
+ pub fn set_theme_preview(&mut self, theme: Theme) -> anyhow::Result<()> {
+ self.set_theme_impl(theme, ThemeAction::Preview)
}
- pub fn set_theme(&mut self, theme: Theme) {
- self.set_theme_impl(theme, ThemeAction::Set);
+ pub fn set_theme(&mut self, theme: Theme) -> anyhow::Result<()> {
+ self.set_theme_impl(theme, ThemeAction::Set)
}
- fn set_theme_impl(&mut self, theme: Theme, preview: ThemeAction) {
+ fn set_theme_impl(&mut self, theme: Theme, preview: ThemeAction) -> anyhow::Result<()> {
// `ui.selection` is the only scope required to be able to render a theme.
if theme.find_highlight_exact("ui.selection").is_none() {
- self.set_error("Invalid theme: `ui.selection` required");
- return;
+ bail!("Invalid theme: `ui.selection` required");
}
let scopes = theme.scopes();
@@ -1518,6 +1518,9 @@ impl Editor {
}
self._refresh();
+ self.config_events.0.send(ConfigEvent::ThemeChanged)?;
+
+ Ok(())
}
#[inline]