1
1
mirror of https://github.com/wez/wezterm.git synced 2024-11-22 04:56:12 +03:00

termwiz: request xterm modifyOtherKeys

When in raw mode, go to level 2, but use level 1 for cooked
so that we don't obfuscate ctrl-c.

A consequnce of this is that CTRL-C is now reported to the app
as CTRL-lowercase-c where we previously reported as CTRL-uppercase-C.
Made a note of the breaking nature of this change in a new changelog
file.

Fixed recognizing SHIFT-TAB

refs: https://github.com/wez/wezterm/issues/2511
This commit is contained in:
Wez Furlong 2022-09-21 20:25:17 -07:00
parent 9a7aad0200
commit 42f855d912
4 changed files with 32 additions and 4 deletions

7
termwiz/CHANGELOG.md Normal file
View File

@ -0,0 +1,7 @@
main:
* BREAKING: We now request modifyOtherKeys when setting up the unix terminal.
As a consequence, CTRL keys like `CTRL-C` are now reported as
`CTRL-lower-case-c` rather than `CTRL-upper-case-C`. We do this even when
modifyOtherKeys isn't active for the sake of overall consistency.

View File

@ -4,7 +4,7 @@ use termwiz::terminal::{new_terminal, Terminal};
use termwiz::Error;
const CTRL_C: KeyEvent = KeyEvent {
key: KeyCode::Char('C'),
key: KeyCode::Char('c'),
modifiers: Modifiers::CTRL,
};

View File

@ -1167,7 +1167,7 @@ impl InputParser {
map.insert(
&ctrl,
InputEvent::Key(KeyEvent {
key: KeyCode::Char(alpha as char),
key: KeyCode::Char((alpha as char).to_ascii_lowercase()),
modifiers: Modifiers::CTRL,
}),
);
@ -1416,6 +1416,13 @@ impl InputParser {
modifiers: Modifiers::NONE,
}),
);
map.insert(
b"\x1b[Z",
InputEvent::Key(KeyEvent {
key: KeyCode::Tab,
modifiers: Modifiers::SHIFT,
}),
);
map.insert(
&[b'\r'],
@ -1724,7 +1731,7 @@ mod test {
vec![
InputEvent::Key(KeyEvent {
modifiers: Modifiers::CTRL,
key: KeyCode::Char('C'),
key: KeyCode::Char('c'),
}),
InputEvent::Key(KeyEvent {
modifiers: Modifiers::ALT,

View File

@ -18,7 +18,7 @@ use termios::{
};
use crate::caps::Capabilities;
use crate::escape::csi::{DecPrivateMode, DecPrivateModeCode, Mode, CSI};
use crate::escape::csi::{DecPrivateMode, DecPrivateModeCode, Mode, XtermKeyModifierResource, CSI};
use crate::input::{InputEvent, InputParser};
use crate::render::terminfo::TerminfoRenderer;
use crate::surface::Change;
@ -99,6 +99,17 @@ impl TtyWriteHandle {
}
Ok(())
}
fn modify_other_keys(&mut self, level: i64) -> std::io::Result<()> {
write!(
self,
"{}",
CSI::Mode(Mode::XtermKeyMode {
resource: XtermKeyModifierResource::OtherKeys,
value: Some(level),
})
)
}
}
impl Write for TtyWriteHandle {
@ -323,12 +334,14 @@ impl Terminal for UnixTerminal {
decset!(AnyEventMouse);
decset!(SGRMouse);
}
self.write.modify_other_keys(2)?;
self.write.flush()?;
Ok(())
}
fn set_cooked_mode(&mut self) -> Result<()> {
self.write.modify_other_keys(1)?;
self.write
.set_termios(&self.saved_termios, SetAttributeWhen::Now)
}
@ -515,6 +528,7 @@ impl Drop for UnixTerminal {
decreset!(SGRMouse);
decreset!(AnyEventMouse);
}
self.write.modify_other_keys(0).unwrap();
self.exit_alternate_screen().unwrap();
self.write.flush().unwrap();