Support more modifiers on some terminal emulators

If a terminal emulator supports the kitty protocol, this change will
allow cove to take advantage of this. This means that more modifiers
will work on special keys like enter or escape.

See also this section of the kitty protocol docs:
https://sw.kovidgoyal.net/kitty/keyboard-protocol/#disambiguate-escape-codes
This commit is contained in:
Joscha 2022-08-11 23:15:09 +02:00
parent 7e42913245
commit 45ece466c2

View file

@ -4,7 +4,10 @@ use std::io::Write;
use std::{io, mem}; use std::{io, mem};
use crossterm::cursor::{Hide, MoveTo, Show}; use crossterm::cursor::{Hide, MoveTo, Show};
use crossterm::event::{DisableBracketedPaste, EnableBracketedPaste}; use crossterm::event::{
DisableBracketedPaste, EnableBracketedPaste, KeyboardEnhancementFlags,
PopKeyboardEnhancementFlags, PushKeyboardEnhancementFlags,
};
use crossterm::style::{PrintStyledContent, StyledContent}; use crossterm::style::{PrintStyledContent, StyledContent};
use crossterm::terminal::{Clear, ClearType, EnterAlternateScreen, LeaveAlternateScreen}; use crossterm::terminal::{Clear, ClearType, EnterAlternateScreen, LeaveAlternateScreen};
use crossterm::{ExecutableCommand, QueueableCommand}; use crossterm::{ExecutableCommand, QueueableCommand};
@ -50,7 +53,10 @@ impl Terminal {
crossterm::terminal::disable_raw_mode()?; crossterm::terminal::disable_raw_mode()?;
self.out.execute(LeaveAlternateScreen)?; self.out.execute(LeaveAlternateScreen)?;
#[cfg(not(windows))] #[cfg(not(windows))]
{
self.out.execute(DisableBracketedPaste)?; self.out.execute(DisableBracketedPaste)?;
self.out.execute(PopKeyboardEnhancementFlags)?;
}
self.out.execute(Show)?; self.out.execute(Show)?;
Ok(()) Ok(())
} }
@ -59,7 +65,12 @@ impl Terminal {
crossterm::terminal::enable_raw_mode()?; crossterm::terminal::enable_raw_mode()?;
self.out.execute(EnterAlternateScreen)?; self.out.execute(EnterAlternateScreen)?;
#[cfg(not(windows))] #[cfg(not(windows))]
{
self.out.execute(EnableBracketedPaste)?; self.out.execute(EnableBracketedPaste)?;
self.out.execute(PushKeyboardEnhancementFlags(
KeyboardEnhancementFlags::DISAMBIGUATE_ESCAPE_CODES,
))?;
}
self.full_redraw = true; self.full_redraw = true;
Ok(()) Ok(())
} }