@@ -40,7 +40,8 @@ use anyhow::{Context, Error};
40use crossterm::{
40use crossterm::{
42 DisableBracketedPaste, DisableFocusChange, DisableMouseCapture, EnableBracketedPaste,
42 DisableBracketedPaste, DisableFocusChange, DisableMouseCapture, EnableBracketedPaste,
43− EnableFocusChange, EnableMouseCapture, Event as CrosstermEvent,
43+ EnableFocusChange, EnableMouseCapture, Event as CrosstermEvent, KeyboardEnhancementFlags,
44+ PopKeyboardEnhancementFlags, PushKeyboardEnhancementFlags,
45 execute, terminal,
46 execute, terminal,
46 tty::IsTty,
47 tty::IsTty,
@@ -111,6 +112,9 @@ fn restore_term() -> Result<(), Error> {
111 let mut stdout = stdout();
112 let mut stdout = stdout();
112 // reset cursor shape
113 // reset cursor shape
113 write!(stdout, "\x1B[0 q")?;
114 write!(stdout, "\x1B[0 q")?;
115+ if matches!(terminal::supports_keyboard_enhancement(), Ok(true)) {
116+ execute!(stdout, PopKeyboardEnhancementFlags)?;
114 // Ignore errors on disabling, this might trigger on windows if we call
118 // Ignore errors on disabling, this might trigger on windows if we call
115 // disable without calling enable previously
119 // disable without calling enable previously
116 let _ = execute!(stdout, DisableMouseCapture);
120 let _ = execute!(stdout, DisableMouseCapture);
@@ -1062,6 +1066,19 @@ impl Application {
1062 if self.config.load().editor.mouse {
1066 if self.config.load().editor.mouse {
1063 execute!(stdout, EnableMouseCapture)?;
1067 execute!(stdout, EnableMouseCapture)?;
1069+ if matches!(terminal::supports_keyboard_enhancement(), Ok(true)) {
1070+ log::debug!("The enhanced keyboard protocol is supported on this terminal");
1073+ PushKeyboardEnhancementFlags(
1074+ KeyboardEnhancementFlags::DISAMBIGUATE_ESCAPE_CODES
1075+ | KeyboardEnhancementFlags::REPORT_ALTERNATE_KEYS
1079+ log::debug!("The enhanced keyboard protocol is not supported on this terminal");