From 3e68e460b0b6c5963a534fc2cc6b9f14153266b5 Mon Sep 17 00:00:00 2001 From: Ryan Mehri Date: Thu, 26 Oct 2023 17:48:06 -0700 Subject: [PATCH] use terminfo to reset terminal cursor style --- helix-tui/src/backend/crossterm.rs | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/helix-tui/src/backend/crossterm.rs b/helix-tui/src/backend/crossterm.rs index 52841f6ef9cc1..4e11d63267df5 100644 --- a/helix-tui/src/backend/crossterm.rs +++ b/helix-tui/src/backend/crossterm.rs @@ -31,11 +31,22 @@ fn vte_version() -> Option { std::env::var("VTE_VERSION").ok()?.parse().ok() } +#[derive(Clone, Debug)] +struct ResetCursorCommand(String); + +impl Default for ResetCursorCommand { + fn default() -> Self { + Self("\x1B[0 q".to_string()) + } +} + /// Describes terminal capabilities like extended underline, truecolor, etc. -#[derive(Copy, Clone, Debug, Default)] +#[derive(Clone, Debug, Default)] struct Capabilities { /// Support for undercurled, underdashed, etc. has_extended_underlines: bool, + /// Support for resetting the cursor style back to normal. + reset_cursor_command: ResetCursorCommand, } impl Capabilities { @@ -54,6 +65,10 @@ impl Capabilities { || t.extended_cap("Su").is_some() || vte_version() >= Some(5102) || matches!(term_program().as_deref(), Some("WezTerm")), + reset_cursor_command: t + .utf8_string_cap(termini::StringCapability::CursorNormal) + .map(|s| ResetCursorCommand(s.to_string())) + .unwrap_or_default(), }, } } @@ -154,7 +169,8 @@ where fn restore(&mut self, config: Config) -> io::Result<()> { // reset cursor shape - write!(self.buffer, "\x1B[0 q")?; + self.buffer + .write_all(self.capabilities.reset_cursor_command.0.as_bytes())?; if config.enable_mouse_capture { execute!(self.buffer, DisableMouseCapture)?; }