From 5f2fd1bf4f7c7e8ca95cd51242701bab69a3174c Mon Sep 17 00:00:00 2001 From: Michael Davis Date: Sat, 26 Nov 2022 13:04:27 -0600 Subject: [PATCH] Enable DISAMBIGUATE_ESCAPE_CODES if terminal supports it --- helix-term/src/application.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/helix-term/src/application.rs b/helix-term/src/application.rs index c0cbc2451483..67b5e4aa15ce 100644 --- a/helix-term/src/application.rs +++ b/helix-term/src/application.rs @@ -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, @@ -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); @@ -1051,6 +1055,14 @@ impl Application { if self.config.load().editor.mouse { execute!(stdout, EnableMouseCapture)?; } + if matches!(terminal::supports_keyboard_enhancement(), Ok(true)) { + log::debug!("Enabling DISAMBIGUATE_ESCAPE_CODES within crossterm"); + execute!( + stdout, + PushKeyboardEnhancementFlags(KeyboardEnhancementFlags::DISAMBIGUATE_ESCAPE_CODES) + )?; + } + Ok(()) }