@@ -40,7 +40,8 @@ use anyhow::{Context, Error};
4040use 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);
@@ -1062,6 +1066,19 @@ impl Application {
10621066 if self.config.load().editor.mouse {
10631067 execute!(stdout, EnableMouseCapture)?;
10641068 }
1069+ if matches!(terminal::supports_keyboard_enhancement(), Ok(true)) {
1070+ log::debug!("The enhanced keyboard protocol is supported on this terminal");
1071+ execute!(
1072+ stdout,
1073+ PushKeyboardEnhancementFlags(
1074+ KeyboardEnhancementFlags::DISAMBIGUATE_ESCAPE_CODES
1075+ | KeyboardEnhancementFlags::REPORT_ALTERNATE_KEYS
1076+ )
1077+ )?;
1078+ } else {
1079+ log::debug!("The enhanced keyboard protocol is not supported on this terminal");
1080+ }
1081+
10651082 Ok(())
10661083 }
10671084