Skip to content

Commit 07fe597

Browse files
authored
fix: only check for kitty support when it's enabled (#988)
1 parent 32a3366 commit 07fe597

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

src/engine.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ impl Reedline {
240240
buffer_editor: None,
241241
cursor_shapes: None,
242242
bracketed_paste: BracketedPasteGuard::default(),
243-
kitty_protocol: KittyProtocolGuard::new(),
243+
kitty_protocol: KittyProtocolGuard::default(),
244244
immediately_accept: false,
245245
#[cfg(feature = "external_printer")]
246246
external_printer: None,

src/terminal_extensions/kitty.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,24 @@ use crossterm::{event, execute};
1212
/// * [dte text editor](https://gitlab.com/craigbarnes/dte/-/issues/138)
1313
///
1414
/// Refer to <https://sw.kovidgoyal.net/kitty/keyboard-protocol/> if you're curious.
15+
#[derive(Default)]
1516
pub(crate) struct KittyProtocolGuard {
1617
enabled: bool,
1718
active: bool,
18-
support_kitty_protocol: bool,
19+
/// Caches whether the terminal supports the kitty protocol; `None` means we haven't checked yet
20+
/// and `Some(bool)` stores a cached answer.
21+
support_kitty_protocol: Option<bool>,
1922
}
2023

2124
impl KittyProtocolGuard {
22-
pub fn new() -> Self {
23-
Self {
24-
support_kitty_protocol: super::kitty_protocol_available(),
25-
enabled: false,
26-
active: false,
25+
pub fn set(&mut self, enable: bool) {
26+
// If we are enabling and haven't yet checked for support, do so now. We cache
27+
// the result to avoid repeated checks.
28+
if enable && self.support_kitty_protocol.is_none() {
29+
self.support_kitty_protocol = Some(super::kitty_protocol_available());
2730
}
28-
}
2931

30-
pub fn set(&mut self, enable: bool) {
31-
self.enabled = enable && self.support_kitty_protocol;
32+
self.enabled = enable && self.support_kitty_protocol.unwrap_or(false);
3233
}
3334
pub fn enter(&mut self) {
3435
if self.enabled && !self.active {

0 commit comments

Comments
 (0)