on master help sign in
tui: Cache the keyboard enhancement check
611701cMichael Davis
Cargo.lock+1
@@ -1202,6 +1202,7 @@ dependencies = [
1202 "helix-core",
1202 "helix-core",
1203 "helix-view",
1203 "helix-view",
1204 "log",
1204 "log",
1205+ "once_cell",
1205 "serde",
1206 "serde",
1206 "termini",
1207 "termini",
1207 "unicode-segmentation",
1208 "unicode-segmentation",
helix-tui/Cargo.toml+1
@@ -22,6 +22,7 @@ unicode-segmentation = "1.10"
22crossterm = { version = "0.26", optional = true }
22crossterm = { version = "0.26", optional = true }
23termini = "0.1"
23termini = "0.1"
24serde = { version = "1", "optional" = true, features = ["derive"]}
24serde = { version = "1", "optional" = true, features = ["derive"]}
25+once_cell = "1.17"
25log = "~0.4"
26log = "~0.4"
26helix-view = { version = "0.6", path = "../helix-view", features = ["term"] }
27helix-view = { version = "0.6", path = "../helix-view", features = ["term"] }
27helix-core = { version = "0.6", path = "../helix-core" }
28helix-core = { version = "0.6", path = "../helix-core" }
helix-tui/src/backend/crossterm.rs+12−2
@@ -15,6 +15,7 @@ use crossterm::{
15 Command,
15 Command,
16};
16};
17use helix_view::graphics::{Color, CursorKind, Modifier, Rect, UnderlineStyle};
17use helix_view::graphics::{Color, CursorKind, Modifier, Rect, UnderlineStyle};
18+use once_cell::sync::OnceCell;
18use std::{
19use std::{
19 fmt,
20 fmt,
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>,
60}
62}
61
63
62impl<W> CrosstermBackend<W>
64impl<W> CrosstermBackend<W>
@@ -67,8 +69,16 @@ where
67 CrosstermBackend {
69 CrosstermBackend {
68 buffer,
70 buffer,
69 capabilities: Capabilities::from_env_or_default(),
71 capabilities: Capabilities::from_env_or_default(),
72+ supports_keyboard_enhancement_protocol: OnceCell::new(),
70 }
73 }
71 }
74 }
75+
76+ #[inline]
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)
80+ .copied()
81+ }
72}
82}
73
83
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)?;
102 }
112 }
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)?;
123 }
133 }
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)?;
126 }
136 }
127 execute!(
137 execute!(