Skip to content

Commit a5c2d18

Browse files
committed
Enable the enhanced keyboard protocol if supported
1 parent f3c4bf3 commit a5c2d18

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

helix-term/src/application.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ use anyhow::{Context, Error};
4040
use crossterm::{
4141
event::{
4242
DisableBracketedPaste, DisableFocusChange, DisableMouseCapture, EnableBracketedPaste,
43-
EnableFocusChange, EnableMouseCapture, Event as CrosstermEvent,
43+
EnableFocusChange, EnableMouseCapture, Event as CrosstermEvent, KeyboardEnhancementFlags,
44+
PopKeyboardEnhancementFlags, PushKeyboardEnhancementFlags,
4445
},
4546
execute, terminal,
4647
tty::IsTty,
@@ -111,6 +112,9 @@ fn restore_term() -> Result<(), Error> {
111112
let mut stdout = stdout();
112113
// reset cursor shape
113114
write!(stdout, "\x1B[0 q")?;
115+
if matches!(terminal::supports_keyboard_enhancement(), Ok(true)) {
116+
execute!(stdout, PopKeyboardEnhancementFlags)?;
117+
}
114118
// Ignore errors on disabling, this might trigger on windows if we call
115119
// disable without calling enable previously
116120
let _ = execute!(stdout, DisableMouseCapture);
@@ -1056,6 +1060,19 @@ impl Application {
10561060
if self.config.load().editor.mouse {
10571061
execute!(stdout, EnableMouseCapture)?;
10581062
}
1063+
if matches!(terminal::supports_keyboard_enhancement(), Ok(true)) {
1064+
log::debug!("The enhanced keyboard protocol is supported on this terminal");
1065+
execute!(
1066+
stdout,
1067+
PushKeyboardEnhancementFlags(
1068+
KeyboardEnhancementFlags::DISAMBIGUATE_ESCAPE_CODES
1069+
| KeyboardEnhancementFlags::REPORT_ALTERNATE_KEYS
1070+
)
1071+
)?;
1072+
} else {
1073+
log::debug!("The enhanced keyboard protocol is not supported on this terminal");
1074+
}
1075+
10591076
Ok(())
10601077
}
10611078

0 commit comments

Comments
 (0)