on master help sign in
Use terminfo to reset terminal cursor style (#8591)
553ffbcRyan Mehri
helix-tui/src/backend/crossterm.rs+18−2
@@ -32,10 +32,21 @@ fn vte_version() -> Option<usize> {
32}
32}
33
33
34/// Describes terminal capabilities like extended underline, truecolor, etc.
34/// Describes terminal capabilities like extended underline, truecolor, etc.
35−#[derive(Copy, Clone, Debug, Default)]
35+#[derive(Clone, Debug)]
36struct Capabilities {
36struct Capabilities {
37 /// Support for undercurled, underdashed, etc.
37 /// Support for undercurled, underdashed, etc.
38 has_extended_underlines: bool,
38 has_extended_underlines: bool,
39+ /// Support for resetting the cursor style back to normal.
40+ reset_cursor_command: String,
41+}
42+
43+impl Default for Capabilities {
44+ fn default() -> Self {
45+ Self {
46+ has_extended_underlines: false,
47+ reset_cursor_command: "\x1B[0 q".to_string(),
48+ }
49+ }
39}
50}
40
51
41impl Capabilities {
52impl Capabilities {
@@ -54,6 +65,10 @@ impl Capabilities {
54 || t.extended_cap("Su").is_some()
65 || t.extended_cap("Su").is_some()
55 || vte_version() >= Some(5102)
66 || vte_version() >= Some(5102)
56 || matches!(term_program().as_deref(), Some("WezTerm")),
67 || matches!(term_program().as_deref(), Some("WezTerm")),
68+ reset_cursor_command: t
69+ .utf8_string_cap(termini::StringCapability::CursorNormal)
70+ .unwrap_or("\x1B[0 q")
71+ .to_string(),
57 },
72 },
58 }
73 }
59 }
74 }
@@ -154,7 +169,8 @@ where
154
169
155 fn restore(&mut self, config: Config) -> io::Result<()> {
170 fn restore(&mut self, config: Config) -> io::Result<()> {
156 // reset cursor shape
171 // reset cursor shape
157− write!(self.buffer, "\x1B[0 q")?;
172+ self.buffer
173+ .write_all(self.capabilities.reset_cursor_command.as_bytes())?;
158 if config.enable_mouse_capture {
174 if config.enable_mouse_capture {
159 execute!(self.buffer, DisableMouseCapture)?;
175 execute!(self.buffer, DisableMouseCapture)?;
160 }
176 }