Recognizes more modified keys

Shift-tab and a few others
This commit is contained in:
Alexandre Bury 2015-05-28 16:19:16 -07:00
parent dd11d34206
commit ae93b68c05

View File

@ -26,6 +26,7 @@ pub enum Key {
Enter, Enter,
/// Tabulation key /// Tabulation key
Tab, Tab,
ShiftTab,
Left, Left,
Right, Right,
Up, Up,
@ -43,12 +44,17 @@ pub enum Key {
/// may appear with a delay or along with the next key. /// may appear with a delay or along with the next key.
Esc, Esc,
// Left arrow while shift is pressed // Left arrow while shift is pressed
CtrlPageUp,
CtrlPageDown,
ShiftLeft, ShiftLeft,
ShiftRight, ShiftRight,
ShiftCtrlLeft,
ShiftCtrlRight,
CtrlLeft, CtrlLeft,
CtrlRight, CtrlRight,
CtrlUp, CtrlUp,
CtrlDown, CtrlDown,
CtrlDel,
F(u8), F(u8),
CtrlChar(char), CtrlChar(char),
Unknown(i32), Unknown(i32),
@ -64,10 +70,17 @@ impl Key {
127 | ncurses::KEY_BACKSPACE => Key::Backspace, 127 | ncurses::KEY_BACKSPACE => Key::Backspace,
330 => Key::Del, 330 => Key::Del,
331 => Key::Ins, 331 => Key::Ins,
// Those keys don't seem to be documented...
515 => Key::CtrlDel,
521 => Key::CtrlDown, 521 => Key::CtrlDown,
541 => Key::CtrlLeft, 541 => Key::CtrlLeft,
542 => Key::ShiftCtrlLeft,
546 => Key::CtrlPageDown,
551 => Key::CtrlPageUp,
556 => Key::CtrlRight, 556 => Key::CtrlRight,
557 => Key::ShiftCtrlRight,
562 => Key::CtrlUp, 562 => Key::CtrlUp,
ncurses::KEY_BTAB => Key::ShiftTab,
ncurses::KEY_SLEFT => Key::ShiftLeft, ncurses::KEY_SLEFT => Key::ShiftLeft,
ncurses::KEY_SRIGHT => Key::ShiftRight, ncurses::KEY_SRIGHT => Key::ShiftRight,
ncurses::KEY_LEFT => Key::Left, ncurses::KEY_LEFT => Key::Left,
@ -79,6 +92,7 @@ impl Key {
ncurses::KEY_HOME => Key::Home, ncurses::KEY_HOME => Key::Home,
ncurses::KEY_END => Key::End, ncurses::KEY_END => Key::End,
f @ ncurses::KEY_F1 ... ncurses::KEY_F15 => Key::F((f - ncurses::KEY_F0) as u8), f @ ncurses::KEY_F1 ... ncurses::KEY_F15 => Key::F((f - ncurses::KEY_F0) as u8),
// Avoids 8-10 (H,I,J), they are used by other commands.
c @ 1 ... 7 | c @ 11 ... 25 => Key::CtrlChar(('a' as u8 + (c-1) as u8) as char), c @ 1 ... 7 | c @ 11 ... 25 => Key::CtrlChar(('a' as u8 + (c-1) as u8) as char),
_ => Key::Unknown(ch), _ => Key::Unknown(ch),
} }
@ -96,12 +110,17 @@ impl fmt::Display for Key {
Key::Right => "Right", Key::Right => "Right",
Key::Down => "Down", Key::Down => "Down",
Key::Up => "Up", Key::Up => "Up",
Key::ShiftCtrlLeft => "Shift-Ctrl-Left",
Key::ShiftCtrlRight => "Shift-Ctrl-Right",
Key::ShiftLeft => "Shift-Left", Key::ShiftLeft => "Shift-Left",
Key::ShiftRight => "Shift-Right", Key::ShiftRight => "Shift-Right",
Key::CtrlDel => "Ctrl-Del",
Key::CtrlLeft => "Ctrl-Left", Key::CtrlLeft => "Ctrl-Left",
Key::CtrlRight => "Ctrl-Right", Key::CtrlRight => "Ctrl-Right",
Key::CtrlUp => "Ctrl-Up", Key::CtrlUp => "Ctrl-Up",
Key::CtrlDown => "Ctrl-Down", Key::CtrlDown => "Ctrl-Down",
Key::CtrlPageUp => "Ctrl-PageUp",
Key::CtrlPageDown => "Ctrl-PageDown",
Key::PageUp => "PageUp", Key::PageUp => "PageUp",
Key::PageDown => "PageDown", Key::PageDown => "PageDown",
Key::Home => "Home", Key::Home => "Home",
@ -109,6 +128,7 @@ impl fmt::Display for Key {
Key::Backspace => "Backspace", Key::Backspace => "Backspace",
Key::Del => "Del", Key::Del => "Del",
Key::Enter => "Enter", Key::Enter => "Enter",
Key::ShiftTab => "Shift-Tab",
Key::Tab => "Tab", Key::Tab => "Tab",
Key::Ins => "Ins", Key::Ins => "Ins",
Key::Esc => "Esc", Key::Esc => "Esc",