mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-08 04:36:45 +01:00
wip: command system: then for sequencer
This commit is contained in:
parent
524e283075
commit
abbe0dc8f7
3 changed files with 378 additions and 111 deletions
|
|
@ -27,15 +27,16 @@ pub trait Command<T>: Sized {
|
|||
|
||||
pub trait HandleKey<C: Command<Self> + 'static>: Sized {
|
||||
const HANDLE_KEY_MAP: &'static [(KeyEvent, C)];
|
||||
fn handle_key (&mut self, key: &KeyEvent) -> Perhaps<C> {
|
||||
let mut run_command: Option<&'static C> = None;
|
||||
fn match_key (key: &KeyEvent) -> Option<&'static C> {
|
||||
for (binding, command) in Self::HANDLE_KEY_MAP.iter() {
|
||||
if key == binding {
|
||||
run_command = Some(command);
|
||||
break
|
||||
return Some(command);
|
||||
}
|
||||
}
|
||||
if let Some(command) = run_command {
|
||||
None
|
||||
}
|
||||
fn handle_key (&mut self, key: &KeyEvent) -> Perhaps<C> {
|
||||
if let Some(command) = Self::match_key(key) {
|
||||
command.run(self)
|
||||
} else {
|
||||
Ok(None)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue