diff --git a/Justfile b/Justfile index ef96bbd6..c33e8c1d 100644 --- a/Justfile +++ b/Justfile @@ -119,13 +119,9 @@ plugin: reset cargo run --bin tek_plugin -edn01: +edn: reset - cd edn && cargo run --example edn01 - -edn02: - reset - cd edn && cargo run --example edn02 + cargo run --example edn test: reset diff --git a/edn/examples/edn02.rs b/edn/examples/edn02.rs deleted file mode 100644 index 4c823884..00000000 --- a/edn/examples/edn02.rs +++ /dev/null @@ -1,31 +0,0 @@ -use tek_tui::{*, tek_layout::{*, tek_engine::*}}; -use tek_edn::*; -use std::sync::{Arc, RwLock}; - -const EDN: &'static str = include_str!("edn02.edn"); - -fn main () -> Usually<()> { - let state = Arc::new(RwLock::new(Example)); - Tui::new().unwrap().run(&state)?; - Ok(()) -} - -pub struct Example; - -impl EdnViewData for &Example { - fn get_content <'a> (&'a self, sym: &'a str) -> RenderBox<'a, Tui> { - Box::new(Thunk::new(move||match sym { - ":hello" => "Hello", - ":world" => "world", - _ => "" - })) - } -} - -impl Content for Example { - fn content (&self) -> impl Render { - EdnView::new(self, EDN).unwrap() - } -} - -impl Handle for Example {} diff --git a/edn/examples/edn03.rs b/edn/examples/edn03.rs deleted file mode 100644 index e69de29b..00000000 diff --git a/edn/src/edn_view.rs b/edn/src/edn_view.rs index 42ccdaeb..c7ee5802 100644 --- a/edn/src/edn_view.rs +++ b/edn/src/edn_view.rs @@ -9,6 +9,7 @@ pub type EdnCallback<'a, Output, State> = pub type EdnRenderCallback<'a, Output, State> = Box>; +/// Provides values to the template pub trait EdnViewData { fn get_bool (&self, _sym: EdnItem<&str>) -> bool { false } fn get_unit (&self, _sym: EdnItem<&str>) -> E::Unit { 0.into() } @@ -25,9 +26,11 @@ pub enum EdnView> { } impl> EdnView { - pub fn new (context: T, source: &str) -> Usually { - let layout = EdnItem::read_one(&source)?.0; - Ok(Self::Ok(context, layout)) + pub fn new (state: T, source: &str) -> Self { + match EdnItem::read_one(&source) { + Ok((layout, _)) => Self::Ok(state, layout), + Err(error) => Self::Err(format!("{error}")) + } } } diff --git a/edn/examples/edn.rs b/examples/edn.rs similarity index 87% rename from edn/examples/edn.rs rename to examples/edn.rs index d1c306c1..9334c357 100644 --- a/edn/examples/edn.rs +++ b/examples/edn.rs @@ -16,8 +16,8 @@ fn main () -> Usually<()> { pub struct Example(usize); -impl EdnViewData for &Example { - fn get_content <'a> (&'a self, sym: EdnItem<&'a str>) -> RenderBox<'a, Tui> { +impl EdnViewData for &Example { + fn get_content <'a> (&'a self, sym: EdnItem<&'a str>) -> RenderBox<'a, TuiOut> { Box::new(Thunk::new(move||match sym { EdnItem::Sym(":hello-world") => "Hello world!", EdnItem::Sym(":hello") => "Hello", @@ -30,9 +30,8 @@ impl EdnViewData for &Example { impl Content for Example { fn content (&self) -> impl Render { Bsp::a( - &format!("{}", self.0), + Push::xy(1, 1, Align::n(format!("Example {}/{}:", self.0 + 1, EDN.len()))), EdnView::new(self, EDN[self.0]) - .unwrap_or_else(|e|format!("Failed to render {}: {e}", self.0)) ) } } diff --git a/edn/examples/edn01.edn b/examples/edn01.edn similarity index 100% rename from edn/examples/edn01.edn rename to examples/edn01.edn diff --git a/edn/examples/edn02.edn b/examples/edn02.edn similarity index 100% rename from edn/examples/edn02.edn rename to examples/edn02.edn diff --git a/edn/examples/edn03.edn b/examples/edn03.edn similarity index 100% rename from edn/examples/edn03.edn rename to examples/edn03.edn diff --git a/src/groovebox/groovebox_tui.rs b/src/groovebox/groovebox_tui.rs index 8f760a25..966cdcf6 100644 --- a/src/groovebox/groovebox_tui.rs +++ b/src/groovebox/groovebox_tui.rs @@ -8,7 +8,7 @@ const EDN: &'static str = include_str!("groovebox.edn"); impl Content for Groovebox { fn content (&self) -> impl Render { - self.size.of(EdnView::new(self, EDN).expect("failed to build view")) + self.size.of(EdnView::new(self, EDN)) } }