61 lines
1.6 KiB
Rust
61 lines
1.6 KiB
Rust
#[derive(Clone, Debug)]
|
|
pub enum Event<T> {
|
|
Link(String),
|
|
Input(Key),
|
|
Message(T),
|
|
}
|
|
|
|
impl From<termion::event::Key> for Key {
|
|
fn from(value: termion::event::Key) -> Self {
|
|
match value {
|
|
termion::event::Key::Backspace => Self::Backspace,
|
|
termion::event::Key::Left => Self::Left,
|
|
termion::event::Key::Right => Self::Right,
|
|
termion::event::Key::Up => Self::Up,
|
|
termion::event::Key::Down => Self::Down,
|
|
termion::event::Key::Home => Self::Home,
|
|
termion::event::Key::End => Self::End,
|
|
termion::event::Key::PageUp => Self::PgUp,
|
|
termion::event::Key::PageDown => Self::PgDown,
|
|
termion::event::Key::BackTab => Self::Backtab,
|
|
termion::event::Key::Delete => Self::Delete,
|
|
termion::event::Key::Insert => Self::Insert,
|
|
termion::event::Key::F(f) => Self::F(f),
|
|
termion::event::Key::Char(c) => match c {
|
|
'\n' => Self::Return,
|
|
'\t' => Self::Tab,
|
|
_ => Self::Char(c),
|
|
},
|
|
termion::event::Key::Alt(c) => Self::Alt(c),
|
|
termion::event::Key::Ctrl(c) => Self::Ctrl(c),
|
|
termion::event::Key::Null => Self::Null,
|
|
termion::event::Key::Esc => Self::Esc,
|
|
_ => Self::Null,
|
|
}
|
|
}
|
|
}
|
|
|
|
#[derive(Clone, Copy, Debug)]
|
|
pub enum Key {
|
|
Backspace,
|
|
Left,
|
|
Right,
|
|
Up,
|
|
Down,
|
|
Home,
|
|
End,
|
|
PgUp,
|
|
PgDown,
|
|
Backtab,
|
|
Delete,
|
|
Insert,
|
|
F(u8),
|
|
Char(char),
|
|
Alt(char),
|
|
Ctrl(char),
|
|
Null,
|
|
Esc,
|
|
Return,
|
|
Tab,
|
|
}
|