File tree Expand file tree Collapse file tree 2 files changed +11
-10
lines changed
Expand file tree Collapse file tree 2 files changed +11
-10
lines changed Original file line number Diff line number Diff 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 ,
Original file line number Diff line number Diff 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 ) ]
1516pub ( 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
2124impl 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 {
You can’t perform that action at this time.
0 commit comments