@@ -15,6 +15,7 @@ use crossterm::{
17use helix_view::graphics::{Color, CursorKind, Modifier, Rect, UnderlineStyle};
17use helix_view::graphics::{Color, CursorKind, Modifier, Rect, UnderlineStyle};
18+use once_cell::sync::OnceCell;
20 io::{self, Write},
21 io::{self, Write},
@@ -57,6 +58,7 @@ impl Capabilities {
57pub struct CrosstermBackend<W: Write> {
58pub struct CrosstermBackend<W: Write> {
58 buffer: W,
59 buffer: W,
59 capabilities: Capabilities,
60 capabilities: Capabilities,
61+ supports_keyboard_enhancement_protocol: OnceCell<bool>,
62impl<W> CrosstermBackend<W>
64impl<W> CrosstermBackend<W>
@@ -67,8 +69,16 @@ where
67 CrosstermBackend {
69 CrosstermBackend {
69 capabilities: Capabilities::from_env_or_default(),
71 capabilities: Capabilities::from_env_or_default(),
72+ supports_keyboard_enhancement_protocol: OnceCell::new(),
77+ fn supports_keyboard_enhancement_protocol(&self) -> io::Result<bool> {
78+ self.supports_keyboard_enhancement_protocol
79+ .get_or_try_init(terminal::supports_keyboard_enhancement)
74impl<W> Write for CrosstermBackend<W>
84impl<W> Write for CrosstermBackend<W>
@@ -100,7 +110,7 @@ where
100 if config.enable_mouse_capture {
110 if config.enable_mouse_capture {
101 execute!(self.buffer, EnableMouseCapture)?;
111 execute!(self.buffer, EnableMouseCapture)?;
103− if matches!(terminal::supports_keyboard_enhancement(), Ok(true)) {
113+ if self.supports_keyboard_enhancement_protocol()? {
104 log::debug!("The enhanced keyboard protocol is supported on this terminal");
114 log::debug!("The enhanced keyboard protocol is supported on this terminal");
105 execute!(
115 execute!(
106 self.buffer,
116 self.buffer,
@@ -121,7 +131,7 @@ where
121 if config.enable_mouse_capture {
131 if config.enable_mouse_capture {
122 execute!(self.buffer, DisableMouseCapture)?;
132 execute!(self.buffer, DisableMouseCapture)?;
124− if matches!(terminal::supports_keyboard_enhancement(), Ok(true)) {
134+ if self.supports_keyboard_enhancement_protocol()? {
125 execute!(self.buffer, PopKeyboardEnhancementFlags)?;
135 execute!(self.buffer, PopKeyboardEnhancementFlags)?;
127 execute!(
137 execute!(