key pattern matching macro

This commit is contained in:
🪞👃🪞 2024-09-05 23:01:16 +03:00
parent e0c8a427f1
commit 92d747ba2a
7 changed files with 168 additions and 93 deletions

View file

@ -3,38 +3,37 @@ use crate::*;
impl Handle<Tui> for Track<Tui> {
fn handle (&mut self, from: &Tui) -> Perhaps<bool> {
match from.event() {
TuiEvent::Input(crossterm::event::Event::Key(event)) => {
for (code, modifiers, _, _, command) in [
key!(Up, NONE, "chain_cursor_up", "move cursor up", || {
Ok(true)
}),
key!(Down, NONE, "chain_cursor_down", "move cursor down", || {
Ok(true)
}),
key!(Left, NONE, "chain_cursor_left", "move cursor left", || {
//if let Some(track) = app.arranger.track_mut() {
//track.device = track.device.saturating_sub(1);
//return Ok(true)
//}
Ok(false)
}),
key!(Right, NONE, "chain_cursor_right", "move cursor right", || {
//if let Some(track) = app.arranger.track_mut() {
//track.device = (track.device + 1).min(track.devices.len().saturating_sub(1));
//return Ok(true)
//}
Ok(false)
}),
key!(Char('`'), NONE, "chain_mode_switch", "switch the display mode", || {
//app.chain_mode = !app.chain_mode;
Ok(true)
}),
].iter() {
if *code == event.code && modifiers.bits() == event.modifiers.bits() {
return command()
}
}
return Ok(None)
TuiEvent::Input(key) => match key {
//, NONE, "chain_cursor_up", "move cursor up", || {
key!(KeyCode::Up) => {
Ok(Some(true))
},
// , NONE, "chain_cursor_down", "move cursor down", || {
key!(KeyCode::Down) => {
Ok(Some(true))
},
// Left, NONE, "chain_cursor_left", "move cursor left", || {
key!(KeyCode::Left) => {
//if let Some(track) = app.arranger.track_mut() {
//track.device = track.device.saturating_sub(1);
//return Ok(true)
//}
Ok(Some(true))
},
// , NONE, "chain_cursor_right", "move cursor right", || {
key!(KeyCode::Right) => {
//if let Some(track) = app.arranger.track_mut() {
//track.device = (track.device + 1).min(track.devices.len().saturating_sub(1));
//return Ok(true)
//}
Ok(Some(true))
},
// , NONE, "chain_mode_switch", "switch the display mode", || {
key!(KeyCode::Char('`')) => {
//app.chain_mode = !app.chain_mode;
Ok(Some(true))
},
_ => Ok(None)
},
_ => Ok(None)
}