diff --git a/edn/README.md b/edn/README.md new file mode 100644 index 00000000..5c05a67d --- /dev/null +++ b/edn/README.md @@ -0,0 +1,4 @@ +# `tek_edn` + +parser and bindings for tek's configuration language, +which is based on edn. diff --git a/edn/examples/edn01.rs b/edn/examples/edn01.rs new file mode 100644 index 00000000..26fe7431 --- /dev/null +++ b/edn/examples/edn01.rs @@ -0,0 +1,8 @@ +use tek_edn::*; + +const SOURCE: &'static str = include_str!("edn01.edn"); + +fn main () { + Tui::run(Arc::new(RwLock::new(Demo::new())))?; + Ok(()) +} diff --git a/edn/examples/edn02.rs b/edn/examples/edn02.rs new file mode 100644 index 00000000..d5e23ee8 --- /dev/null +++ b/edn/examples/edn02.rs @@ -0,0 +1,8 @@ +use tek_edn::*; + +const SOURCE: &'static str = include_str!("edn02.edn"); + +fn main () { + Tui::run(Arc::new(RwLock::new(Demo::new())))?; + Ok(()) +} diff --git a/edn/src/edn_layout.rs b/edn/src/edn_layout.rs deleted file mode 100644 index 6c893626..00000000 --- a/edn/src/edn_layout.rs +++ /dev/null @@ -1,20 +0,0 @@ -use crate::*; -use std::marker::PhantomData; -use ::tek_layout::{*, tek_engine::{Usually, Content, Render, Engine, Thunk}}; -use EdnItem::*; - -pub type EdnRender<'a, Engine> = - dyn Render + Send + Sync + 'a; - -pub type EdnCallback<'a, Engine, State> = - dyn Fn(&'a State)->Box> + Send + Sync + 'a; - -pub type EdnRenderCallback<'a, Engine, State> = - Box>; - -pub trait EdnLayout<'a, E: Engine + 'a> where Self: 'a { - fn get_bool (&self, _sym: &str) -> bool { false } - fn get_unit (&self, _sym: &str) -> E::Unit { 0.into() } - fn get_usize (&self, _sym: &str) -> usize { 0 } - fn get_content (&'a self, _sym: &str) -> Box> { Box::new(()) } -} diff --git a/edn/src/edn_view.rs b/edn/src/edn_view.rs index dbac002b..aad174e4 100644 --- a/edn/src/edn_view.rs +++ b/edn/src/edn_view.rs @@ -1,22 +1,40 @@ use crate::*; use std::marker::PhantomData; +use ::tek_layout::{*, tek_engine::{Usually, Content, Render, Engine, Thunk}}; +use EdnItem::*; + +pub type EdnRender<'a, Engine> = + dyn Render + Send + Sync + 'a; + +pub type EdnCallback<'a, Engine, State> = + dyn Fn(&'a State)->Box> + Send + Sync + 'a; + +pub type EdnRenderCallback<'a, Engine, State> = + Box>; + +pub trait EdnLayout { + fn get_bool (&self, _sym: &str) -> bool { false } + fn get_unit (&self, _sym: &str) -> E::Unit { 0.into() } + fn get_usize (&self, _sym: &str) -> usize { 0 } + fn get_content <'a> (&'a self, _sym: &str) -> Box> { Box::new(()) } +} /// Renders from EDN source and context. -pub struct EdnView<'a, E: Engine + 'a, T: EdnLayout<'a, E> + 'a> { - _engine: PhantomData<&'a E>, +pub struct EdnView> { + _engine: PhantomData, context: T, layout: EdnItem //render: BoxBox + Send + Sync + 'a> + Send + Sync + 'a> } -impl<'a, E: Engine + 'a, T: EdnLayout<'a, E> + 'a> EdnView<'a, E, T> { - pub fn new (context: T, source: &'a str) -> Usually { +impl> EdnView { + pub fn new (context: T, source: &str) -> Usually { let layout = EdnItem::read_one(&source)?.0; Ok(Self { _engine: Default::default(), context, layout, }) } } -impl<'a, E: Engine + 'a, T: EdnLayout<'a, E> + Send + Sync + 'a> Content for EdnView<'a, E, T> { +impl + Send + Sync> Content for EdnView { fn content (&self) -> impl Render { use EdnItem::*; match &self.layout { diff --git a/edn/src/lib.rs b/edn/src/lib.rs index 70f8ced2..e0e93502 100644 --- a/edn/src/lib.rs +++ b/edn/src/lib.rs @@ -11,7 +11,6 @@ pub(crate) use ::tek_layout::{ mod edn_error; pub use self::edn_error::*; mod edn_item; pub use self::edn_item::*; -mod edn_layout; pub use self::edn_layout::*; mod edn_token; pub use self::edn_token::*; mod edn_view; pub use self::edn_view::*; diff --git a/engine/src/output.rs b/engine/src/output.rs index 7fa9a823..e37d3a47 100644 --- a/engine/src/output.rs +++ b/engine/src/output.rs @@ -27,6 +27,9 @@ impl> Render for C { fn layout (&self, area: E::Area) -> E::Area { Content::layout(self, area) } fn render (&self, output: &mut E::Output) { Content::render(self, output) } } +impl<'a, E: Engine> Content for Box + 'a> { + fn content (&self) -> impl Render { self } +} impl<'a, E: Engine> Content for Box + Send + Sync + 'a> { fn content (&self) -> impl Render { self } } @@ -74,6 +77,7 @@ impl> Content for Option { } } + #[macro_export] macro_rules! render { (($self:ident:$Struct:ty) => $content:expr) => { impl Content for $Struct { diff --git a/engine/src/tui.rs b/engine/src/tui.rs index 02b5948f..68116829 100644 --- a/engine/src/tui.rs +++ b/engine/src/tui.rs @@ -92,7 +92,7 @@ impl Tui { } } -pub trait TuiRun + Handle + Sized + 'static> { +pub trait TuiRun + Handle + Sized + 'static> { /// Run an app in the main loop. fn run (&self, state: &Arc>) -> Usually<()>; /// Spawn the input thread. @@ -101,7 +101,7 @@ pub trait TuiRun + Handle + Sized + 'static> { fn run_output (&self, state: &Arc>, sleep: Duration) -> JoinHandle<()>; } -impl + Handle + Sized + 'static> TuiRun for Arc> { +impl + Handle + Sized + 'static> TuiRun for Arc> { fn run (&self, state: &Arc>) -> Usually<()> { let _input_thread = self.run_input(state, Duration::from_millis(100)); self.write().unwrap().setup()?; diff --git a/engine/src/tui/tui_output.rs b/engine/src/tui/tui_output.rs index 43382fb7..f0a80aa5 100644 --- a/engine/src/tui/tui_output.rs +++ b/engine/src/tui/tui_output.rs @@ -65,7 +65,7 @@ impl TuiOut { } } -impl Content for &str { +impl Render for &str { fn layout (&self, to: [u16;4]) -> [u16;4] { to.center_xy([self.chars().count() as u16, 1]) } @@ -74,7 +74,7 @@ impl Content for &str { } } -impl Content for String { +impl Render for String { fn layout (&self, to: [u16;4]) -> [u16;4] { to.center_xy([self.chars().count() as u16, 1]) }