on master help sign in
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.

commitbbcdcd04a5f6c02c14d73d6bd0f53099b1fcb765 authorMichael Davis <mcarsondavis@gmail.com> dateTue 28 Mar 2023, 22:51 (4 years ago) parent6a323c0
1 file changed+8−9
helix-tui/src/backend/crossterm.rs+8−9
helix-tui/src/backend/crossterm.rs+8−9
@@ -78,21 +78,20 @@ where
7878 }
7979
8080 #[inline]
81− fn supports_keyboard_enhancement_protocol(&self) -> io::Result<bool> {
82− self.supports_keyboard_enhancement_protocol
83− .get_or_try_init(|| {
81+ fn supports_keyboard_enhancement_protocol(&self) -> bool {
82+ *self.supports_keyboard_enhancement_protocol
83+ .get_or_init(|| {
8484 use std::time::Instant;
8585
8686 let now = Instant::now();
87− let support = terminal::supports_keyboard_enhancement();
87+ let supported = matches!(terminal::supports_keyboard_enhancement(), Ok(true));
8888 log::debug!(
8989 "The keyboard enhancement protocol is {}supported in this terminal (checked in {:?})",
90− if matches!(support, Ok(true)) { "" } else { "not " },
90+ if supported { "" } else { "not " },
9191 Instant::now().duration_since(now)
9292 );
93− support
93+ supported
9494 })
95− .copied()
9695 }
9796}
9897
@@ -125,7 +124,7 @@ where
125124 if config.enable_mouse_capture {
126125 execute!(self.buffer, EnableMouseCapture)?;
127126 }
128− if self.supports_keyboard_enhancement_protocol()? {
127+ if self.supports_keyboard_enhancement_protocol() {
129128 execute!(
130129 self.buffer,
131130 PushKeyboardEnhancementFlags(
@@ -143,7 +142,7 @@ where
143142 if config.enable_mouse_capture {
144143 execute!(self.buffer, DisableMouseCapture)?;
145144 }
146− if self.supports_keyboard_enhancement_protocol()? {
145+ if self.supports_keyboard_enhancement_protocol() {
147146 execute!(self.buffer, PopKeyboardEnhancementFlags)?;
148147 }
149148 execute!(