aboutsummaryrefslogtreecommitdiff
path: root/helix-tui
diff options
context:
space:
mode:
authorRyan Mehri2023-10-26 23:36:34 +0000
committerGitHub2023-10-26 23:36:34 +0000
commit553ffbcaa09847ec606539bddab8af1456450d73 (patch)
treeb7bc1e0837ceac444648386f9985f0b4ec345421 /helix-tui
parent9eec9adb8fb299ea57dc6fa13f0c5d789dcdff73 (diff)
Use terminfo to reset terminal cursor style (#8591)
Diffstat (limited to 'helix-tui')
-rw-r--r--helix-tui/src/backend/crossterm.rs20
1 files changed, 18 insertions, 2 deletions
diff --git a/helix-tui/src/backend/crossterm.rs b/helix-tui/src/backend/crossterm.rs
index 52841f6e..c55ab6bb 100644
--- a/helix-tui/src/backend/crossterm.rs
+++ b/helix-tui/src/backend/crossterm.rs
@@ -32,10 +32,21 @@ fn vte_version() -> Option<usize> {
}
/// Describes terminal capabilities like extended underline, truecolor, etc.
-#[derive(Copy, Clone, Debug, Default)]
+#[derive(Clone, Debug)]
struct Capabilities {
/// Support for undercurled, underdashed, etc.
has_extended_underlines: bool,
+ /// Support for resetting the cursor style back to normal.
+ reset_cursor_command: String,
+}
+
+impl Default for Capabilities {
+ fn default() -> Self {
+ Self {
+ has_extended_underlines: false,
+ reset_cursor_command: "\x1B[0 q".to_string(),
+ }
+ }
}
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)
+ .unwrap_or("\x1B[0 q")
+ .to_string(),
},
}
}
@@ -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.as_bytes())?;
if config.enable_mouse_capture {
execute!(self.buffer, DisableMouseCapture)?;
}