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

commit563ac1a3cb7e909b345cf5c892c3bcf39b2e32a4 authorMichael Davis <mcarsondavis@gmail.com> dateTue 7 Mar 2023, 10:33 (4 years ago) parent611701c
1 file changed+12−4
helix-tui/src/backend/crossterm.rs+12−4
helix-tui/src/backend/crossterm.rs+12−4
@@ -76,7 +76,18 @@ where
7676 #[inline]
7777 fn supports_keyboard_enhancement_protocol(&self) -> io::Result<bool> {
7878 self.supports_keyboard_enhancement_protocol
79− .get_or_try_init(terminal::supports_keyboard_enhancement)
79+ .get_or_try_init(|| {
80+ use std::time::Instant;
81+
82+ let now = Instant::now();
83+ let support = terminal::supports_keyboard_enhancement();
84+ log::debug!(
85+ "The keyboard enhancement protocol is {}supported in this terminal (checked in {:?})",
86+ if matches!(support, Ok(true)) { "" } else { "not " },
87+ Instant::now().duration_since(now)
88+ );
89+ support
90+ })
8091 .copied()
8192 }
8293}
@@ -111,7 +122,6 @@ where
111122 execute!(self.buffer, EnableMouseCapture)?;
112123 }
113124 if self.supports_keyboard_enhancement_protocol()? {
114− log::debug!("The enhanced keyboard protocol is supported on this terminal");
115125 execute!(
116126 self.buffer,
117127 PushKeyboardEnhancementFlags(
@@ -119,8 +129,6 @@ where
119129 | KeyboardEnhancementFlags::REPORT_ALTERNATE_KEYS
120130 )
121131 )?;
122− } else {
123− log::debug!("The enhanced keyboard protocol is not supported on this terminal");
124132 }
125133 Ok(())
126134 }