Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Complete Control key interpretation #24

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 16 additions & 8 deletions term/src/terminalstate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -765,23 +765,31 @@ impl TerminalState {
(Insert, _, _, SHIFT, _) => paste!(),
(Char('v'), ..) if mods == KeyModifiers::SUPER => paste!(),

(Char(c), CTRL, _, SHIFT, _) if c <= 0xff as char && c > 0x40 as char => {
// If shift is held we have C == 0x43 and want to translate
// that into 0x03
buf.push((c as u8 - 0x40) as char);
// Control key interpration
// https://www.x.org/releases/current/doc/kbproto/xkbproto.html#Interpreting_the_Control_Modifier
// & libX11:src/xkb/XKBBind.c
(Char(c), CTRL, _, _, _) if c >= '@' && c < 127u8 as char || c == ' ' => {
buf.push(((c as u8) & 0x1f) as char);
buf.as_str()
}
(Char(c), CTRL, ..) if c <= 0xff as char && c > 0x60 as char => {
// If shift is not held we have C == 0x63 and want to translate
// that into 0x03
buf.push((c as u8 - 0x60) as char);
(Char('2'), CTRL, _, _, _) => "\0",
(Char(c), CTRL, _, _, _) if c >= '3' && c <= '7' => {
buf.push(((c as u8) - 27) as char);
buf.as_str()
}
(Char('8'), CTRL, _, _, _) => "\x1f",
(Char('/'), CTRL, _, _, _) => {
buf.push((('_' as u8) & 0x1f) as char);
buf.as_str()
}

// Alt key interpretation
(Char(c), _, ALT, ..) => {
buf.push(0x1b as char);
buf.push(c);
buf.as_str()
}

(Char(c), ..) => {
buf.push(c);
buf.as_str()
Expand Down