#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum KeyInput {
Char(char),
Up,
Down,
Left,
Right,
Home,
End,
PageUp,
PageDown,
Enter,
Backspace,
Delete,
Escape,
Tab,
F(u8),
Ctrl(char),
Alt(char),
Shift(char),
CtrlUp,
CtrlDown,
CtrlLeft,
CtrlRight,
CtrlHome,
CtrlEnd,
AltUp,
AltDown,
AltEnter,
ShiftUp,
ShiftDown,
}
impl KeyInput {
pub fn is_char(&self) -> bool {
matches!(
self,
KeyInput::Char(_) | KeyInput::Ctrl(_) | KeyInput::Alt(_) | KeyInput::Shift(_)
)
}
pub fn as_char(&self) -> Option<char> {
match self {
KeyInput::Char(c) | KeyInput::Shift(c) => Some(*c),
_ => None,
}
}
pub fn has_ctrl(&self) -> bool {
matches!(
self,
KeyInput::Ctrl(_)
| KeyInput::CtrlUp
| KeyInput::CtrlDown
| KeyInput::CtrlLeft
| KeyInput::CtrlRight
| KeyInput::CtrlHome
| KeyInput::CtrlEnd
)
}
pub fn has_alt(&self) -> bool {
matches!(
self,
KeyInput::Alt(_) | KeyInput::AltUp | KeyInput::AltDown | KeyInput::AltEnter
)
}
pub fn has_shift(&self) -> bool {
matches!(
self,
KeyInput::Shift(_) | KeyInput::ShiftUp | KeyInput::ShiftDown
)
}
}