Skip to content

Commit

Permalink
tui: Log keyboard enhancement query time
Browse files Browse the repository at this point in the history
In my testing this takes around 3-4ms in terminals that support the
enhanced keyboard protocol (Kitty, WezTerm) and a few hundred
microseconds in terminals that don't (st, Alacritty).
  • Loading branch information
the-mikedavis authored and archseer committed Mar 8, 2023
1 parent 611701c commit 563ac1a
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions helix-tui/src/backend/crossterm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,18 @@ where
#[inline]
fn supports_keyboard_enhancement_protocol(&self) -> io::Result<bool> {
self.supports_keyboard_enhancement_protocol
.get_or_try_init(terminal::supports_keyboard_enhancement)
.get_or_try_init(|| {
use std::time::Instant;

let now = Instant::now();
let support = terminal::supports_keyboard_enhancement();
log::debug!(
"The keyboard enhancement protocol is {}supported in this terminal (checked in {:?})",
if matches!(support, Ok(true)) { "" } else { "not " },
Instant::now().duration_since(now)
);
support
})
.copied()
}
}
Expand Down Expand Up @@ -111,16 +122,13 @@ where
execute!(self.buffer, EnableMouseCapture)?;
}
if self.supports_keyboard_enhancement_protocol()? {
log::debug!("The enhanced keyboard protocol is supported on this terminal");
execute!(
self.buffer,
PushKeyboardEnhancementFlags(
KeyboardEnhancementFlags::DISAMBIGUATE_ESCAPE_CODES
| KeyboardEnhancementFlags::REPORT_ALTERNATE_KEYS
)
)?;
} else {
log::debug!("The enhanced keyboard protocol is not supported on this terminal");
}
Ok(())
}
Expand Down

0 comments on commit 563ac1a

Please sign in to comment.