Skip to content

Commit

Permalink
tui: Handle keyboard enhancement check failure (helix-editor#6438)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
the-mikedavis authored and wes-adams committed Jul 3, 2023
1 parent aff3e2c commit 7635f1d
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions helix-tui/src/backend/crossterm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}

Expand Down Expand Up @@ -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(
Expand All @@ -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!(
Expand Down

0 comments on commit 7635f1d

Please sign in to comment.