1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
use crossterm::event::KeyCode as CrosstermKeyCode;
use termion::event::Key as TermionKey;
use termwiz::input::KeyCode as TermwizKeyCode;

// relevant imports:
// use crossterm::event::{KeyCode, KeyEvent, KeyModifiers};
// use termion::event::{Event, Key};
// use termwiz::input::{KeyCode, KeyEvent, Modifiers};

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

impl From<CrosstermKeyCode> for KeyCode {
    fn from(key_code: CrosstermKeyCode) -> Self {
        match key_code {
            CrosstermKeyCode::Backspace => Self::Backspace,
            CrosstermKeyCode::Enter => Self::Enter,
            CrosstermKeyCode::Left => Self::Left,
            CrosstermKeyCode::Right => Self::Right,
            CrosstermKeyCode::Up => Self::Up,
            CrosstermKeyCode::Down => Self::Down,
            CrosstermKeyCode::Home => Self::Home,
            CrosstermKeyCode::End => Self::End,
            CrosstermKeyCode::PageUp => Self::PageUp,
            CrosstermKeyCode::PageDown => Self::PageDown,
            CrosstermKeyCode::Tab => Self::Tab,
            CrosstermKeyCode::BackTab => Self::BackTab,
            CrosstermKeyCode::Delete => Self::Delete,
            CrosstermKeyCode::Insert => Self::Insert,
            CrosstermKeyCode::F(n) => Self::F(n),
            CrosstermKeyCode::Char(c) => Self::Char(c),
            CrosstermKeyCode::Null => Self::Null,
            CrosstermKeyCode::Esc => Self::Esc,
            CrosstermKeyCode::ScrollLock => Self::ScrollLock,
            CrosstermKeyCode::NumLock => Self::NumLock,
            CrosstermKeyCode::PrintScreen => Self::PrintScreen,
            CrosstermKeyCode::Pause => Self::PauseBreak,
            CrosstermKeyCode::Menu => Self::Menu,
            CrosstermKeyCode::CapsLock => todo!(),
            CrosstermKeyCode::KeypadBegin => todo!(),
            CrosstermKeyCode::Media(_) => todo!(),
            CrosstermKeyCode::Modifier(_) => todo!(),
        }
    }
}

impl From<TermionKey> for KeyCode {
    fn from(key_code: TermionKey) -> Self {
        match key_code {
            TermionKey::Backspace => Self::Backspace,
            TermionKey::Left => Self::Left,
            TermionKey::Right => Self::Right,
            TermionKey::Up => Self::Up,
            TermionKey::Down => Self::Down,
            TermionKey::Home => Self::Home,
            TermionKey::End => Self::End,
            TermionKey::PageUp => Self::PageUp,
            TermionKey::PageDown => Self::PageDown,
            TermionKey::BackTab => Self::BackTab,
            TermionKey::Delete => Self::Delete,
            TermionKey::Insert => Self::Insert,
            TermionKey::F(n) => Self::F(n),
            TermionKey::Char(c) => Self::Char(c),
            TermionKey::Null => Self::Null,
            TermionKey::Esc => Self::Esc,
            TermionKey::Ctrl('m') => Self::Enter,
            TermionKey::Ctrl('i') => Self::Tab, // maybe?
            TermionKey::Ctrl(c) => Self::Char(c),
            TermionKey::Alt(_) => todo!(),
            _ => todo!(),
        }
    }
}

impl From<TermwizKeyCode> for KeyCode {
    fn from(key_code: TermwizKeyCode) -> Self {
        match key_code {
            TermwizKeyCode::Backspace => Self::Backspace,
            TermwizKeyCode::Enter => Self::Enter,
            TermwizKeyCode::LeftArrow => Self::Left,
            TermwizKeyCode::RightArrow => Self::Right,
            TermwizKeyCode::UpArrow => Self::Up,
            TermwizKeyCode::DownArrow => Self::Down,
            TermwizKeyCode::Home => Self::Home,
            TermwizKeyCode::End => Self::End,
            TermwizKeyCode::PageUp => Self::PageUp,
            TermwizKeyCode::PageDown => Self::PageDown,
            TermwizKeyCode::Tab => Self::Tab,
            TermwizKeyCode::Delete => Self::Delete,
            TermwizKeyCode::Insert => Self::Insert,
            TermwizKeyCode::Function(n) => Self::F(n),
            TermwizKeyCode::Char(c) => Self::Char(c),
            TermwizKeyCode::Escape => Self::Esc,
            TermwizKeyCode::ScrollLock => Self::ScrollLock,
            TermwizKeyCode::NumLock => Self::NumLock,
            TermwizKeyCode::PrintScreen => Self::PrintScreen,
            TermwizKeyCode::Pause => Self::PauseBreak,
            TermwizKeyCode::Menu => Self::Menu,
            TermwizKeyCode::Hyper => todo!(),
            TermwizKeyCode::Super => todo!(),
            TermwizKeyCode::Meta => todo!(),
            TermwizKeyCode::Cancel => todo!(),
            TermwizKeyCode::Clear => todo!(),
            TermwizKeyCode::Shift => todo!(),
            TermwizKeyCode::LeftShift => todo!(),
            TermwizKeyCode::RightShift => todo!(),
            TermwizKeyCode::Control => todo!(),
            TermwizKeyCode::LeftControl => todo!(),
            TermwizKeyCode::RightControl => todo!(),
            TermwizKeyCode::Alt => todo!(),
            TermwizKeyCode::LeftAlt => todo!(),
            TermwizKeyCode::RightAlt => todo!(),
            TermwizKeyCode::LeftMenu => todo!(),
            TermwizKeyCode::RightMenu => todo!(),
            TermwizKeyCode::CapsLock => todo!(),
            TermwizKeyCode::Select => todo!(),
            TermwizKeyCode::Print => todo!(),
            TermwizKeyCode::Execute => todo!(),
            TermwizKeyCode::Help => todo!(),
            TermwizKeyCode::LeftWindows => todo!(),
            TermwizKeyCode::RightWindows => todo!(),
            TermwizKeyCode::Applications => todo!(),
            TermwizKeyCode::Sleep => todo!(),
            TermwizKeyCode::Numpad0 => todo!(),
            TermwizKeyCode::Numpad1 => todo!(),
            TermwizKeyCode::Numpad2 => todo!(),
            TermwizKeyCode::Numpad3 => todo!(),
            TermwizKeyCode::Numpad4 => todo!(),
            TermwizKeyCode::Numpad5 => todo!(),
            TermwizKeyCode::Numpad6 => todo!(),
            TermwizKeyCode::Numpad7 => todo!(),
            TermwizKeyCode::Numpad8 => todo!(),
            TermwizKeyCode::Numpad9 => todo!(),
            TermwizKeyCode::Multiply => todo!(),
            TermwizKeyCode::Add => todo!(),
            TermwizKeyCode::Separator => todo!(),
            TermwizKeyCode::Subtract => todo!(),
            TermwizKeyCode::Decimal => todo!(),
            TermwizKeyCode::Divide => todo!(),
            TermwizKeyCode::Copy => todo!(),
            TermwizKeyCode::Cut => todo!(),
            TermwizKeyCode::Paste => todo!(),
            TermwizKeyCode::BrowserBack => todo!(),
            TermwizKeyCode::BrowserForward => todo!(),
            TermwizKeyCode::BrowserRefresh => todo!(),
            TermwizKeyCode::BrowserStop => todo!(),
            TermwizKeyCode::BrowserSearch => todo!(),
            TermwizKeyCode::BrowserFavorites => todo!(),
            TermwizKeyCode::BrowserHome => todo!(),
            TermwizKeyCode::VolumeMute => todo!(),
            TermwizKeyCode::VolumeDown => todo!(),
            TermwizKeyCode::VolumeUp => todo!(),
            TermwizKeyCode::MediaNextTrack => todo!(),
            TermwizKeyCode::MediaPrevTrack => todo!(),
            TermwizKeyCode::MediaStop => todo!(),
            TermwizKeyCode::MediaPlayPause => todo!(),
            TermwizKeyCode::ApplicationLeftArrow => todo!(),
            TermwizKeyCode::ApplicationRightArrow => todo!(),
            TermwizKeyCode::ApplicationUpArrow => todo!(),
            TermwizKeyCode::ApplicationDownArrow => todo!(),
            _ => todo!(),
        }
    }
}