mirror of
https://codeberg.org/unspeaker/tengri.git
synced 2025-12-06 19:56:44 +01:00
This commit is contained in:
parent
643658ab16
commit
a601d3d806
3 changed files with 84 additions and 99 deletions
|
|
@ -1,86 +1,87 @@
|
|||
use crate::*;
|
||||
use crate::{dsl::*, input::*, tui::TuiIn};
|
||||
use crossterm::event::{Event, KeyEvent, KeyCode, KeyModifiers, KeyEventKind, KeyEventState};
|
||||
use std::cmp::Ordering;
|
||||
// FIXME
|
||||
//use crate::*;
|
||||
//use crate::{dsl::*, input::*, tui::TuiIn};
|
||||
//use crossterm::event::{Event, KeyEvent, KeyCode, KeyModifiers, KeyEventKind, KeyEventState};
|
||||
//use std::cmp::Ordering;
|
||||
|
||||
#[test] fn test_subcommand () -> Usually<()> {
|
||||
#[derive(Debug)] struct Event(crossterm::event::Event);
|
||||
impl Eq for Event {}
|
||||
impl PartialEq for Event { fn eq (&self, other: &Self) -> bool { todo!() } }
|
||||
impl Ord for Event { fn cmp (&self, other: &Self) -> Ordering { todo!() } }
|
||||
impl PartialOrd for Event { fn partial_cmp (&self, other: &Self) -> Option<Ordering> { None } }
|
||||
struct Test { keys: InputMap<Event, Ast> }
|
||||
//#[test] fn test_subcommand () -> Usually<()> {
|
||||
//#[derive(Debug)] struct Event(crossterm::event::Event);
|
||||
//impl Eq for Event {}
|
||||
//impl PartialEq for Event { fn eq (&self, other: &Self) -> bool { todo!() } }
|
||||
//impl Ord for Event { fn cmp (&self, other: &Self) -> Ordering { todo!() } }
|
||||
//impl PartialOrd for Event { fn partial_cmp (&self, other: &Self) -> Option<Ordering> { None } }
|
||||
//struct Test { keys: InputMap<Event, Ast> }
|
||||
|
||||
handle!(TuiIn: |self: Test, input|Ok(None));/*if let Some(command) = self.keys.command(self, input) {
|
||||
Ok(Some(true))
|
||||
} else {
|
||||
Ok(None)
|
||||
});*/
|
||||
//handle!(TuiIn: |self: Test, input|Ok(None));[>if let Some(command) = self.keys.command(self, input) {
|
||||
//Ok(Some(true))
|
||||
//} else {
|
||||
//Ok(None)
|
||||
//});*/
|
||||
|
||||
#[tengri_proc::command(Test)]
|
||||
impl TestCommand {
|
||||
fn do_thing (_state: &mut Test) -> Perhaps<Self> {
|
||||
Ok(None)
|
||||
}
|
||||
fn do_thing_arg (_state: &mut Test, _arg: usize) -> Perhaps<Self> {
|
||||
Ok(None)
|
||||
}
|
||||
fn do_sub (state: &mut Test, command: TestSubcommand) -> Perhaps<Self> {
|
||||
Ok(command.execute(state)?.map(|command|Self::DoSub { command }))
|
||||
}
|
||||
}
|
||||
//#[tengri_proc::command(Test)]
|
||||
//impl TestCommand {
|
||||
//fn do_thing (_state: &mut Test) -> Perhaps<Self> {
|
||||
//Ok(None)
|
||||
//}
|
||||
//fn do_thing_arg (_state: &mut Test, _arg: usize) -> Perhaps<Self> {
|
||||
//Ok(None)
|
||||
//}
|
||||
//fn do_sub (state: &mut Test, command: TestSubcommand) -> Perhaps<Self> {
|
||||
//Ok(command.execute(state)?.map(|command|Self::DoSub { command }))
|
||||
//}
|
||||
//}
|
||||
|
||||
#[tengri_proc::command(Test)]
|
||||
impl TestSubcommand {
|
||||
fn do_other_thing (_state: &mut Test) -> Perhaps<Self> {
|
||||
Ok(None)
|
||||
}
|
||||
fn do_other_thing_arg (_state: &mut Test, _arg: usize) -> Perhaps<Self> {
|
||||
Ok(None)
|
||||
}
|
||||
}
|
||||
//#[tengri_proc::command(Test)]
|
||||
//impl TestSubcommand {
|
||||
//fn do_other_thing (_state: &mut Test) -> Perhaps<Self> {
|
||||
//Ok(None)
|
||||
//}
|
||||
//fn do_other_thing_arg (_state: &mut Test, _arg: usize) -> Perhaps<Self> {
|
||||
//Ok(None)
|
||||
//}
|
||||
//}
|
||||
|
||||
let mut test = Test {
|
||||
keys: InputMap::from_source("
|
||||
(@a do-thing)
|
||||
(@b do-thing-arg 0)
|
||||
(@c do-sub do-other-thing)
|
||||
(@d do-sub do-other-thing-arg 0)
|
||||
")?
|
||||
};
|
||||
//let mut test = Test {
|
||||
//keys: InputMap::from_source("
|
||||
//(@a do-thing)
|
||||
//(@b do-thing-arg 0)
|
||||
//(@c do-sub do-other-thing)
|
||||
//(@d do-sub do-other-thing-arg 0)
|
||||
//")?
|
||||
//};
|
||||
|
||||
//assert_eq!(Some(true), test.handle(&TuiIn(Default::default(), Event::Key(KeyEvent {
|
||||
//kind: KeyEventKind::Press,
|
||||
//code: KeyCode::Char('a'),
|
||||
//modifiers: KeyModifiers::NONE,
|
||||
//state: KeyEventState::NONE,
|
||||
//})))?);
|
||||
//assert_eq!(Some(true), test.handle(&TuiIn(Default::default(), Event::Key(KeyEvent {
|
||||
//kind: KeyEventKind::Press,
|
||||
//code: KeyCode::Char('b'),
|
||||
//modifiers: KeyModifiers::NONE,
|
||||
//state: KeyEventState::NONE,
|
||||
//})))?);
|
||||
//assert_eq!(Some(true), test.handle(&TuiIn(Default::default(), Event::Key(KeyEvent {
|
||||
//kind: KeyEventKind::Press,
|
||||
//code: KeyCode::Char('c'),
|
||||
//modifiers: KeyModifiers::NONE,
|
||||
//state: KeyEventState::NONE,
|
||||
//})))?);
|
||||
//assert_eq!(Some(true), test.handle(&TuiIn(Default::default(), Event::Key(KeyEvent {
|
||||
//kind: KeyEventKind::Press,
|
||||
//code: KeyCode::Char('d'),
|
||||
//modifiers: KeyModifiers::NONE,
|
||||
//state: KeyEventState::NONE,
|
||||
//})))?);
|
||||
//assert_eq!(None, test.handle(&TuiIn(Default::default(), Event::Key(KeyEvent {
|
||||
//kind: KeyEventKind::Press,
|
||||
//code: KeyCode::Char('z'),
|
||||
//modifiers: KeyModifiers::NONE,
|
||||
//state: KeyEventState::NONE,
|
||||
//})))?);
|
||||
Ok(())
|
||||
}
|
||||
////assert_eq!(Some(true), test.handle(&TuiIn(Default::default(), Event::Key(KeyEvent {
|
||||
////kind: KeyEventKind::Press,
|
||||
////code: KeyCode::Char('a'),
|
||||
////modifiers: KeyModifiers::NONE,
|
||||
////state: KeyEventState::NONE,
|
||||
////})))?);
|
||||
////assert_eq!(Some(true), test.handle(&TuiIn(Default::default(), Event::Key(KeyEvent {
|
||||
////kind: KeyEventKind::Press,
|
||||
////code: KeyCode::Char('b'),
|
||||
////modifiers: KeyModifiers::NONE,
|
||||
////state: KeyEventState::NONE,
|
||||
////})))?);
|
||||
////assert_eq!(Some(true), test.handle(&TuiIn(Default::default(), Event::Key(KeyEvent {
|
||||
////kind: KeyEventKind::Press,
|
||||
////code: KeyCode::Char('c'),
|
||||
////modifiers: KeyModifiers::NONE,
|
||||
////state: KeyEventState::NONE,
|
||||
////})))?);
|
||||
////assert_eq!(Some(true), test.handle(&TuiIn(Default::default(), Event::Key(KeyEvent {
|
||||
////kind: KeyEventKind::Press,
|
||||
////code: KeyCode::Char('d'),
|
||||
////modifiers: KeyModifiers::NONE,
|
||||
////state: KeyEventState::NONE,
|
||||
////})))?);
|
||||
////assert_eq!(None, test.handle(&TuiIn(Default::default(), Event::Key(KeyEvent {
|
||||
////kind: KeyEventKind::Press,
|
||||
////code: KeyCode::Char('z'),
|
||||
////modifiers: KeyModifiers::NONE,
|
||||
////state: KeyEventState::NONE,
|
||||
////})))?);
|
||||
//Ok(())
|
||||
//}
|
||||
|
||||
//FIXME:
|
||||
//#[cfg(test)] #[test] fn test_dsl_context () {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue