diff --git a/input/src/input_dsl.rs b/input/src/input_dsl.rs index bb3c353..1f6ac42 100644 --- a/input/src/input_dsl.rs +++ b/input/src/input_dsl.rs @@ -1,10 +1,9 @@ use crate::*; - +use std::{sync::Arc, collections::BTreeMap, path::{Path, PathBuf}, fs::{exists, read_to_string}}; /// Map of each event (e.g. key combination) to /// all command expressions bound to it by /// all loaded input layers. type EventMapImpl = BTreeMap>>; - /// A collection of input bindings. /// /// Each contained layer defines a mapping from input event to command invocation @@ -16,7 +15,6 @@ type EventMapImpl = BTreeMap>>; /// that .event()binding's value is returned. #[derive(Debug)] pub struct EventMap(EventMapImpl); - /// An input binding. #[derive(Debug, Clone)] pub struct Binding { @@ -25,18 +23,14 @@ pub struct Binding { pub description: Option>, pub source: Option>, } - /// Input bindings are only returned if this evaluates to true #[derive(Clone)] pub struct Condition(Arcbool + Send + Sync>>); - impl_debug!(Condition |self, w| { write!(w, "*") }); - /// Default is always empty map regardless if `E` and `C` implement [Default]. impl Default for EventMap { fn default () -> Self { Self(Default::default()) } } - impl EventMap { /// Create a new event map pub fn new () -> Self { @@ -68,7 +62,7 @@ impl EventMap { /// Create event map from path to text file. pub fn from_path > (path: P) -> Usually where E: From> { if exists(path.as_ref())? { - Self::from_source(read_and_leak(path)?) + Self::from_source(read_to_string(path)?) } else { return Err(format!("(e5) not found: {:?}", path.as_ref()).into()) } @@ -117,7 +111,6 @@ impl EventMap { Ok(map) } } - impl Binding { fn from_dsl (dsl: impl Dsl) -> Usually { let mut command: Option = None; @@ -131,18 +124,9 @@ impl Binding { } } } - fn unquote (x: &str) -> &str { let mut chars = x.chars(); chars.next(); //chars.next_back(); chars.as_str() } - -fn read_and_leak (path: impl AsRef) -> Usually<&'static str> { - Ok(leak(String::from_utf8(std::fs::read(path.as_ref())?)?)) -} - -fn leak (x: impl AsRef) -> &'static str { - Box::leak(x.as_ref().into()) -} diff --git a/input/src/input_test.rs b/input/src/input_test.rs index 8373435..24576db 100644 --- a/input/src/input_test.rs +++ b/input/src/input_test.rs @@ -21,8 +21,8 @@ use crate::*; Ok(()) } -#[cfg(all(test, feature = "dsl"))] #[test] fn test_dsl_keymap () -> Usually<()> { - let _keymap = CstIter::new(""); - Ok(()) -} +//#[cfg(all(test, feature = "dsl"))] #[test] fn test_dsl_keymap () -> Usually<()> { + //let _keymap = CstIter::new(""); + //Ok(()) +//} diff --git a/tengri/src/test.rs b/tengri/src/test.rs index c782996..2df3c8a 100644 --- a/tengri/src/test.rs +++ b/tengri/src/test.rs @@ -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 { None } } - struct Test { keys: InputMap } +//#[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 { None } } + //struct Test { keys: InputMap } - 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 { - Ok(None) - } - fn do_thing_arg (_state: &mut Test, _arg: usize) -> Perhaps { - Ok(None) - } - fn do_sub (state: &mut Test, command: TestSubcommand) -> Perhaps { - Ok(command.execute(state)?.map(|command|Self::DoSub { command })) - } - } + //#[tengri_proc::command(Test)] + //impl TestCommand { + //fn do_thing (_state: &mut Test) -> Perhaps { + //Ok(None) + //} + //fn do_thing_arg (_state: &mut Test, _arg: usize) -> Perhaps { + //Ok(None) + //} + //fn do_sub (state: &mut Test, command: TestSubcommand) -> Perhaps { + //Ok(command.execute(state)?.map(|command|Self::DoSub { command })) + //} + //} - #[tengri_proc::command(Test)] - impl TestSubcommand { - fn do_other_thing (_state: &mut Test) -> Perhaps { - Ok(None) - } - fn do_other_thing_arg (_state: &mut Test, _arg: usize) -> Perhaps { - Ok(None) - } - } + //#[tengri_proc::command(Test)] + //impl TestSubcommand { + //fn do_other_thing (_state: &mut Test) -> Perhaps { + //Ok(None) + //} + //fn do_other_thing_arg (_state: &mut Test, _arg: usize) -> Perhaps { + //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 () {