use bitflags::bitflags;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct KeyEvent {
pub code: KeyCode,
pub modifiers: KeyModifiers,
}
impl KeyEvent {
pub fn new(code: KeyCode, modifiers: KeyModifiers) -> Self {
Self { code, modifiers }
}
pub fn char(c: char) -> Self {
Self::new(KeyCode::Char(c), KeyModifiers::NONE)
}
pub fn ctrl(c: char) -> Self {
Self::new(KeyCode::Char(c), KeyModifiers::CTRL)
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum KeyCode {
Char(char),
Enter,
Esc,
Tab,
Backspace,
Delete,
Insert,
Up,
Down,
Left,
Right,
Home,
End,
PageUp,
PageDown,
F(u8),
}
bitflags! {
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct KeyModifiers: u8 {
const NONE = 0;
const SHIFT = 1 << 0;
const CTRL = 1 << 1;
const ALT = 1 << 2;
}
}