@ -15,6 +15,7 @@ use crossterm::{
Command ,
Command ,
} ;
} ;
use helix_view ::graphics ::{ Color , CursorKind , Modifier , Rect , UnderlineStyle } ;
use helix_view ::graphics ::{ Color , CursorKind , Modifier , Rect , UnderlineStyle } ;
use once_cell ::sync ::OnceCell ;
use std ::{
use std ::{
fmt ,
fmt ,
io ::{ self , Write } ,
io ::{ self , Write } ,
@ -57,6 +58,7 @@ impl Capabilities {
pub struct CrosstermBackend < W : Write > {
pub struct CrosstermBackend < W : Write > {
buffer : W ,
buffer : W ,
capabilities : Capabilities ,
capabilities : Capabilities ,
supports_keyboard_enhancement_protocol : OnceCell < bool > ,
}
}
impl < W > CrosstermBackend < W >
impl < W > CrosstermBackend < W >
@ -67,8 +69,16 @@ where
CrosstermBackend {
CrosstermBackend {
buffer ,
buffer ,
capabilities : Capabilities ::from_env_or_default ( ) ,
capabilities : Capabilities ::from_env_or_default ( ) ,
supports_keyboard_enhancement_protocol : OnceCell ::new ( ) ,
}
}
}
}
#[ inline ]
fn supports_keyboard_enhancement_protocol ( & self ) -> io ::Result < bool > {
self . supports_keyboard_enhancement_protocol
. get_or_try_init ( terminal ::supports_keyboard_enhancement )
. copied ( )
}
}
}
impl < W > Write for CrosstermBackend < W >
impl < W > Write for CrosstermBackend < W >
@ -100,7 +110,7 @@ where
if config . enable_mouse_capture {
if config . enable_mouse_capture {
execute ! ( self . buffer , EnableMouseCapture ) ? ;
execute ! ( self . buffer , EnableMouseCapture ) ? ;
}
}
if matches! ( terminal ::supports_keyboard_enhancement ( ) , Ok ( true ) ) {
if self . supports_keyboard_enhancement_protocol ( ) ? {
log ::debug ! ( "The enhanced keyboard protocol is supported on this terminal" ) ;
log ::debug ! ( "The enhanced keyboard protocol is supported on this terminal" ) ;
execute ! (
execute ! (
self . buffer ,
self . buffer ,
@ -121,7 +131,7 @@ where
if config . enable_mouse_capture {
if config . enable_mouse_capture {
execute ! ( self . buffer , DisableMouseCapture ) ? ;
execute ! ( self . buffer , DisableMouseCapture ) ? ;
}
}
if matches! ( terminal ::supports_keyboard_enhancement ( ) , Ok ( true ) ) {
if self . supports_keyboard_enhancement_protocol ( ) ? {
execute ! ( self . buffer , PopKeyboardEnhancementFlags ) ? ;
execute ! ( self . buffer , PopKeyboardEnhancementFlags ) ? ;
}
}
execute ! (
execute ! (