use def_command

This commit is contained in:
🪞👃🪞 2025-08-23 23:20:15 +03:00
parent 5ccbb9719f
commit cfd19062fd
37 changed files with 1578 additions and 1594 deletions

View file

@ -1,30 +1,62 @@
use crate::*;
handle!(TuiIn:|self: App, input|{
let mut commands = vec![];
for id in self.mode.keys.iter() {
if let Some(event_map) = self.config.binds.clone().read().unwrap().get(id.as_ref()) {
if let Some(bindings) = event_map.query(input.event()) {
for binding in bindings {
for command in binding.commands.iter() {
if let Some(command) = self.from(command)? as Option<AppCommand> {
commands.push(command)
}
}
}
}
}
}
for command in commands.into_iter() {
let result = command.execute(self);
match result {
Ok(undo) => {
self.history.push((command, undo));
},
Err(e) => {
self.history.push((command, None));
return Err(e)
}
}
}
Ok(None)
});
impl<'t> DslNs<'t, AppCommand> for App {
dsl_exprs!(|app| -> AppCommand { /* TODO */ });
dsl_words!(|app| -> AppCommand {
"x/inc" => todo!(),
"x/dec" => todo!(),
"y/inc" => todo!(),
"y/dec" => todo!(),
"y/inc" => match app.dialog {
Dialog::Menu(index, count) => AppCommand::SetDialog {
dialog: Dialog::Menu(if count > 0 {
(index + 1) % count
} else { 0 }, count)
},
_ => todo!(),
},
"y/dec" => match app.dialog {
Dialog::Menu(index, count) => AppCommand::SetDialog {
dialog: Dialog::Menu(if count > 0 {
index.overflowing_sub(1).0.min(count.saturating_sub(1))
} else { 0 }, count)
},
_ => todo!(),
},
"confirm" => todo!(),
});
}
#[derive(Debug)]
pub enum AppCommand { /* TODO */ }
#[tengri_proc::command(Option<Dialog>)]
impl DialogCommand {
fn open (dialog: &mut Option<Dialog>, new: Dialog) -> Perhaps<Self> {
*dialog = Some(new);
Ok(None)
}
fn close (dialog: &mut Option<Dialog>) -> Perhaps<Self> {
*dialog = None;
Ok(None)
}
}
def_command!(AppCommand: |app: App| {
SetDialog { dialog: Dialog } =>
swap_value(&mut app.dialog, dialog, |dialog|Self::SetDialog { dialog }),
});
//AppCommand => {
//("x/inc" /