tui: Log keyboard enhancement query time

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).
This commit is contained in:
Michael Davis 2023-03-07 10:33:46 -06:00 committed by Blaž Hrastnik
parent 611701c362
commit 563ac1a3cb

View File

@ -76,7 +76,18 @@ pub fn new(buffer: W) -> CrosstermBackend<W> {
#[inline] #[inline]
fn supports_keyboard_enhancement_protocol(&self) -> io::Result<bool> { fn supports_keyboard_enhancement_protocol(&self) -> io::Result<bool> {
self.supports_keyboard_enhancement_protocol 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() .copied()
} }
} }
@ -111,7 +122,6 @@ fn claim(&mut self, config: Config) -> io::Result<()> {
execute!(self.buffer, EnableMouseCapture)?; execute!(self.buffer, EnableMouseCapture)?;
} }
if self.supports_keyboard_enhancement_protocol()? { if self.supports_keyboard_enhancement_protocol()? {
log::debug!("The enhanced keyboard protocol is supported on this terminal");
execute!( execute!(
self.buffer, self.buffer,
PushKeyboardEnhancementFlags( PushKeyboardEnhancementFlags(
@ -119,8 +129,6 @@ fn claim(&mut self, config: Config) -> io::Result<()> {
| KeyboardEnhancementFlags::REPORT_ALTERNATE_KEYS | KeyboardEnhancementFlags::REPORT_ALTERNATE_KEYS
) )
)?; )?;
} else {
log::debug!("The enhanced keyboard protocol is not supported on this terminal");
} }
Ok(()) Ok(())
} }