Skip to content

Commit

Permalink
Enable the enhanced keyboard protocol if supported
Browse files Browse the repository at this point in the history
  • Loading branch information
the-mikedavis committed Feb 11, 2023
1 parent 37996eb commit 8f347ad
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion helix-term/src/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ use anyhow::{Context, Error};
use crossterm::{
event::{
DisableBracketedPaste, DisableFocusChange, DisableMouseCapture, EnableBracketedPaste,
EnableFocusChange, EnableMouseCapture, Event as CrosstermEvent,
EnableFocusChange, EnableMouseCapture, Event as CrosstermEvent, KeyboardEnhancementFlags,
PopKeyboardEnhancementFlags, PushKeyboardEnhancementFlags,
},
execute, terminal,
tty::IsTty,
Expand Down Expand Up @@ -111,6 +112,9 @@ fn restore_term() -> Result<(), Error> {
let mut stdout = stdout();
// reset cursor shape
write!(stdout, "\x1B[0 q")?;
if matches!(terminal::supports_keyboard_enhancement(), Ok(true)) {
execute!(stdout, PopKeyboardEnhancementFlags)?;
}
// Ignore errors on disabling, this might trigger on windows if we call
// disable without calling enable previously
let _ = execute!(stdout, DisableMouseCapture);
Expand Down Expand Up @@ -1056,6 +1060,19 @@ impl Application {
if self.config.load().editor.mouse {
execute!(stdout, EnableMouseCapture)?;
}
if matches!(terminal::supports_keyboard_enhancement(), Ok(true)) {
log::debug!("The enhanced keyboard protocol is supported on this terminal");
execute!(
stdout,
PushKeyboardEnhancementFlags(
KeyboardEnhancementFlags::DISAMBIGUATE_ESCAPE_CODES
| KeyboardEnhancementFlags::REPORT_ALTERNATE_KEYS
)
)?;
} else {
log::debug!("The enhanced keyboard protocol is not supported on this terminal");
}

Ok(())
}

Expand Down

0 comments on commit 8f347ad

Please sign in to comment.