#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum KeyCode {
    Char(char),
    F(u8),
    Up,
    Down,
    Left,
    Right,
    Enter,
    Escape,
    Backspace,
    Tab,
    BackTab,
    Home,
    End,
    PageUp,
    PageDown,
    Insert,
    Delete,
}

#[cfg(feature = "terminal")]
impl From<crossterm::event::KeyCode> for KeyCode {
    fn from(key: crossterm::event::KeyCode) -> Self {
        match key {
            crossterm::event::KeyCode::Char(character) => KeyCode::Char(character),
            crossterm::event::KeyCode::F(number) => KeyCode::F(number),
            crossterm::event::KeyCode::Up => KeyCode::Up,
            crossterm::event::KeyCode::Down => KeyCode::Down,
            crossterm::event::KeyCode::Left => KeyCode::Left,
            crossterm::event::KeyCode::Right => KeyCode::Right,
            crossterm::event::KeyCode::Enter => KeyCode::Enter,
            crossterm::event::KeyCode::Esc => KeyCode::Escape,
            crossterm::event::KeyCode::Backspace => KeyCode::Backspace,
            crossterm::event::KeyCode::Tab => KeyCode::Tab,
            crossterm::event::KeyCode::BackTab => KeyCode::BackTab,
            crossterm::event::KeyCode::Home => KeyCode::Home,
            crossterm::event::KeyCode::End => KeyCode::End,
            crossterm::event::KeyCode::PageUp => KeyCode::PageUp,
            crossterm::event::KeyCode::PageDown => KeyCode::PageDown,
            crossterm::event::KeyCode::Insert => KeyCode::Insert,
            crossterm::event::KeyCode::Delete => KeyCode::Delete,
            _ => KeyCode::Char('\0'),
        }
    }
}
