wip: command system: then for sequencer

This commit is contained in:
🪞👃🪞 2024-11-07 01:00:20 +01:00
parent 524e283075
commit abbe0dc8f7
3 changed files with 378 additions and 111 deletions

View file

@ -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)