use crossterm::event::KeyEvent as CrosstermKeyEvent;
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum Key {
Char(char),
Esc,
Enter,
Up,
Down,
Left,
Right,
Tab,
Backspace,
Other,
}
impl From<CrosstermKeyEvent> for Key {
fn from(key: CrosstermKeyEvent) -> Self {
from_code(key.code)
}
}
pub fn from_code(code: crossterm::event::KeyCode) -> Key {
use crossterm::event::KeyCode;
match code {
KeyCode::Char(c) => Key::Char(c),
KeyCode::Esc => Key::Esc,
KeyCode::Enter => Key::Enter,
KeyCode::Up => Key::Up,
KeyCode::Down => Key::Down,
KeyCode::Left => Key::Left,
KeyCode::Right => Key::Right,
KeyCode::Tab => Key::Tab,
KeyCode::Backspace => Key::Backspace,
_ => Key::Other,
}
}