Merged Fn keys into a single enum value

This commit is contained in:
Alexandre Bury 2015-05-28 14:57:21 -07:00
parent 3adb95c7ab
commit dd11d34206

View File

@ -42,21 +42,6 @@ pub enum Key {
/// Escape key. Often buffered by the terminal,
/// may appear with a delay or along with the next key.
Esc,
F1,
F2,
F3,
F4,
F5,
F6,
F7,
F8,
F9,
F10,
F11,
F12,
F13,
F14,
F15,
// Left arrow while shift is pressed
ShiftLeft,
ShiftRight,
@ -64,6 +49,7 @@ pub enum Key {
CtrlRight,
CtrlUp,
CtrlDown,
F(u8),
CtrlChar(char),
Unknown(i32),
}
@ -92,21 +78,7 @@ impl Key {
ncurses::KEY_NPAGE => Key::PageDown,
ncurses::KEY_HOME => Key::Home,
ncurses::KEY_END => Key::End,
ncurses::KEY_F1 => Key::F1,
ncurses::KEY_F2 => Key::F2,
ncurses::KEY_F3 => Key::F3,
ncurses::KEY_F4 => Key::F4,
ncurses::KEY_F5 => Key::F5,
ncurses::KEY_F6 => Key::F6,
ncurses::KEY_F7 => Key::F7,
ncurses::KEY_F8 => Key::F8,
ncurses::KEY_F9 => Key::F9,
ncurses::KEY_F10 => Key::F10,
ncurses::KEY_F11 => Key::F11,
ncurses::KEY_F12 => Key::F12,
ncurses::KEY_F13 => Key::F13,
ncurses::KEY_F14 => Key::F14,
ncurses::KEY_F15 => Key::F15,
f @ ncurses::KEY_F1 ... ncurses::KEY_F15 => Key::F((f - ncurses::KEY_F0) as u8),
c @ 1 ... 7 | c @ 11 ... 25 => Key::CtrlChar(('a' as u8 + (c-1) as u8) as char),
_ => Key::Unknown(ch),
}
@ -118,6 +90,7 @@ impl fmt::Display for Key {
match *self {
Key::Unknown(ch) => write!(f, "Unknown: {}", ch),
Key::CtrlChar(ch) => write!(f, "Ctrl-{}", ch),
Key::F(n) => write!(f, "F{}", n),
key => write!(f, "{}", match key {
Key::Left => "Left",
Key::Right => "Right",
@ -139,21 +112,6 @@ impl fmt::Display for Key {
Key::Tab => "Tab",
Key::Ins => "Ins",
Key::Esc => "Esc",
Key::F1 => "F1",
Key::F2 => "F2",
Key::F3 => "F3",
Key::F4 => "F4",
Key::F5 => "F5",
Key::F6 => "F6",
Key::F7 => "F7",
Key::F8 => "F8",
Key::F9 => "F9",
Key::F10 => "F10",
Key::F11 => "F11",
Key::F12 => "F12",
Key::F13 => "F13",
Key::F14 => "F14",
Key::F15 => "F15",
_ => "",
}),
}