Simplify InputEvent
Now that I've decided the F1 menu should always show all key bindings, there is no need for the InputEvent to be so complex.
This commit is contained in:
parent
64a7e7f518
commit
36c5831b9b
2 changed files with 40 additions and 103 deletions
|
|
@ -1,12 +1,49 @@
|
|||
mod event;
|
||||
mod keys;
|
||||
|
||||
pub use cove_macro::KeyGroup;
|
||||
use crossterm::event::KeyEvent;
|
||||
|
||||
pub use event::*;
|
||||
pub use keys::*;
|
||||
pub use crate::keys::*;
|
||||
|
||||
/// A group of related key bindings.
|
||||
pub trait KeyGroup {
|
||||
fn bindings(&self) -> Vec<(&KeyBinding, &'static str)>;
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum InputEvent {
|
||||
Key(KeyEvent),
|
||||
Paste(String),
|
||||
}
|
||||
|
||||
impl InputEvent {
|
||||
pub fn from_crossterm_event(event: crossterm::event::Event) -> Option<Self> {
|
||||
use crossterm::event::Event::*;
|
||||
match event {
|
||||
Key(event) => Some(Self::Key(event)),
|
||||
Paste(string) => Some(Self::Paste(string)),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn key_event(&self) -> Option<KeyEvent> {
|
||||
match self {
|
||||
Self::Key(event) => Some(*event),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn paste_event(&self) -> Option<&str> {
|
||||
match self {
|
||||
Self::Paste(string) => Some(string),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn matches<S: ToString>(&self, binding: &KeyBinding) -> bool {
|
||||
match self.key_event() {
|
||||
Some(event) => binding.matches(event),
|
||||
None => false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue