diff options
author | Michael Davis | 2023-03-29 03:51:11 +0000 |
---|---|---|
committer | GitHub | 2023-03-29 03:51:11 +0000 |
commit | bbcdcd04a5f6c02c14d73d6bd0f53099b1fcb765 (patch) | |
tree | e245ec3da26d152de18f4528d150df41157181db | |
parent | 6a323c0b1b8fd2491dcbca38b5a1f62bf9581da4 (diff) |
tui: Handle keyboard enhancement check failure (#6438)
If the terminal doesn't send the primary device attributes response to
the query, the `terminal::supports_keyboard_enhancement` function from
crossterm may timeout and return an Err.
We should interpret this error to mean that the terminal doesn't support
the keyboard enhancement protocol rather than an error in claiming the
terminal.
-rw-r--r-- | helix-tui/src/backend/crossterm.rs | 17 |
1 files changed, 8 insertions, 9 deletions
diff --git a/helix-tui/src/backend/crossterm.rs b/helix-tui/src/backend/crossterm.rs index 4b230f53..4d44f187 100644 --- a/helix-tui/src/backend/crossterm.rs +++ b/helix-tui/src/backend/crossterm.rs @@ -78,21 +78,20 @@ where } #[inline] - fn supports_keyboard_enhancement_protocol(&self) -> io::Result<bool> { - self.supports_keyboard_enhancement_protocol - .get_or_try_init(|| { + fn supports_keyboard_enhancement_protocol(&self) -> bool { + *self.supports_keyboard_enhancement_protocol + .get_or_init(|| { use std::time::Instant; let now = Instant::now(); - let support = terminal::supports_keyboard_enhancement(); + let supported = matches!(terminal::supports_keyboard_enhancement(), Ok(true)); log::debug!( "The keyboard enhancement protocol is {}supported in this terminal (checked in {:?})", - if matches!(support, Ok(true)) { "" } else { "not " }, + if supported { "" } else { "not " }, Instant::now().duration_since(now) ); - support + supported }) - .copied() } } @@ -125,7 +124,7 @@ where if config.enable_mouse_capture { execute!(self.buffer, EnableMouseCapture)?; } - if self.supports_keyboard_enhancement_protocol()? { + if self.supports_keyboard_enhancement_protocol() { execute!( self.buffer, PushKeyboardEnhancementFlags( @@ -143,7 +142,7 @@ where if config.enable_mouse_capture { execute!(self.buffer, DisableMouseCapture)?; } - if self.supports_keyboard_enhancement_protocol()? { + if self.supports_keyboard_enhancement_protocol() { execute!(self.buffer, PopKeyboardEnhancementFlags)?; } execute!( |