feat: enable enhanced keyboard mode (#1505)

This enabled the Kitty Keyboard Protocol

Read more here: https://sw.kovidgoyal.net/kitty/keyboard-protocol/

No change on unsupported terminals, but means in the future we can be
more creative with keybinding depending on terminal.

Tested on Alacritty and events come through with all modifiers
supported.

Will be useful for #193
This commit is contained in:
Ellie Huxtable 2024-01-05 13:15:28 +00:00 committed by GitHub
parent 951aafa414
commit e129f7a93e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -7,7 +7,8 @@ use atuin_common::utils;
use crossterm::{
event::{
self, DisableMouseCapture, EnableMouseCapture, Event, KeyCode, KeyEvent, KeyModifiers,
MouseEvent,
KeyboardEnhancementFlags, MouseEvent, PopKeyboardEnhancementFlags,
PushKeyboardEnhancementFlags,
},
execute, terminal,
};
@ -562,14 +563,21 @@ impl Stdout {
pub fn new(inline_mode: bool) -> std::io::Result<Self> {
terminal::enable_raw_mode()?;
let mut stdout = stdout();
if !inline_mode {
execute!(stdout, terminal::EnterAlternateScreen)?;
}
execute!(
stdout,
event::EnableMouseCapture,
event::EnableBracketedPaste,
PushKeyboardEnhancementFlags(
KeyboardEnhancementFlags::DISAMBIGUATE_ESCAPE_CODES
| KeyboardEnhancementFlags::REPORT_ALL_KEYS_AS_ESCAPE_CODES
),
)?;
Ok(Self {
stdout,
inline_mode,
@ -586,6 +594,7 @@ impl Drop for Stdout {
self.stdout,
event::DisableMouseCapture,
event::DisableBracketedPaste,
PopKeyboardEnhancementFlags
)
.unwrap();
terminal::disable_raw_mode().unwrap();