mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-06 03:36:41 +01:00
wip: more edn rendering setup
This commit is contained in:
parent
174a7ee614
commit
f1b3fc0040
10 changed files with 85 additions and 47 deletions
|
|
@ -1 +1 @@
|
|||
:test
|
||||
:hello
|
||||
|
|
|
|||
|
|
@ -1,8 +1,20 @@
|
|||
use tek_edn::*;
|
||||
use tek_edn::{*, tek_layout::{*, tek_engine::{*, tui::{*, TuiRun}}}};
|
||||
use std::sync::{Arc, RwLock};
|
||||
|
||||
const SOURCE: &'static str = include_str!("edn01.edn");
|
||||
const EDN: &'static str = include_str!("edn01.edn");
|
||||
|
||||
fn main () {
|
||||
Tui::run(Arc::new(RwLock::new(Demo::new())))?;
|
||||
fn main () -> Usually<()> {
|
||||
let state = Arc::new(RwLock::new(Example));
|
||||
Tui::new().unwrap().run(&state)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub struct Example;
|
||||
|
||||
impl EdnLayout<Tui> for Example {
|
||||
fn get_content <'a> (&'a self, sym: &'a str) -> Box<EdnRender<'a, Tui>> {
|
||||
Box::new(Thunk::new(move||if sym == ":hello" { "Hello world!" } else { "" }))
|
||||
}
|
||||
}
|
||||
|
||||
impl Handle<Tui> for Example {}
|
||||
|
|
|
|||
|
|
@ -1,12 +1 @@
|
|||
(sized
|
||||
(bsp/s (fill/x (fixed/y 2 (lay
|
||||
(align/w :input-meter-l)
|
||||
(align/e :input-meter-r)
|
||||
(align/x :transport))))
|
||||
(bsp/n (row :clip-play :clip-next :clip-edit :edit-stat)
|
||||
(bsp/n (max/y :sample-h (fill/xy :sample-view))
|
||||
(bsp/n (align/w (fixed/y 1 :sample-stat))
|
||||
(bsp/n (fixed/x :pool-w :pool-view)
|
||||
(fill/xy (bsp/e
|
||||
(fixed/x :samples-w (push/y :samples-y :samples-view))
|
||||
:midi-view))))))))
|
||||
(bsp/s :hello :world)
|
||||
|
|
|
|||
|
|
@ -1,8 +1,20 @@
|
|||
use tek_edn::*;
|
||||
use tek_edn::{*, tek_layout::{*, tek_engine::{*, tui::{*, TuiRun}}}};
|
||||
use std::sync::{Arc, RwLock};
|
||||
|
||||
const SOURCE: &'static str = include_str!("edn02.edn");
|
||||
const EDN: &'static str = include_str!("edn02.edn");
|
||||
|
||||
fn main () {
|
||||
Tui::run(Arc::new(RwLock::new(Demo::new())))?;
|
||||
fn main () -> Usually<()> {
|
||||
let state = Arc::new(RwLock::new(Example));
|
||||
Tui::new().unwrap().run(&state)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub struct Example;
|
||||
|
||||
impl EdnLayout<Tui> for Example {
|
||||
fn get_content <'a> (&'a self, sym: &'a str) -> Box<EdnRender<'a, Tui>> {
|
||||
Box::new(Thunk::new(move||if sym == ":hello" { "Hello world!" } else { "" }))
|
||||
}
|
||||
}
|
||||
|
||||
impl Handle<Tui> for Example {}
|
||||
|
|
|
|||
|
|
@ -14,14 +14,27 @@ impl<T> Default for EdnItem<T> {
|
|||
}
|
||||
impl<T: Debug> Debug for EdnItem<T> {
|
||||
fn fmt (&self, f: &mut Formatter<'_>) -> Result<(), FormatError> {
|
||||
use EdnItem::*;
|
||||
match self {
|
||||
Self::Nil => write!(f, "Nil"),
|
||||
Self::Num(u) => write!(f, "Num({u})"),
|
||||
Self::Sym(u) => write!(f, "Sym({u:?})"),
|
||||
Self::Key(u) => write!(f, "Key({u:?})"),
|
||||
Self::Exp(e) => write!(f, "Exp({})", itertools::join(
|
||||
e.iter().map(|i|format!("{:?}", i)), ","
|
||||
))
|
||||
Nil => write!(f, "Nil"),
|
||||
Num(u) => write!(f, "Num({u})"),
|
||||
Sym(u) => write!(f, "Sym({u:?})"),
|
||||
Key(u) => write!(f, "Key({u:?})"),
|
||||
Exp(e) => write!(f, "Exp({})",
|
||||
itertools::join(e.iter().map(|i|format!("{:?}", i)), ","))
|
||||
}
|
||||
}
|
||||
}
|
||||
impl<T: PartialEq> PartialEq for EdnItem<T> {
|
||||
fn eq (&self, other: &Self) -> bool {
|
||||
use EdnItem::*;
|
||||
match (self, other) {
|
||||
(Nil, Nil) => true,
|
||||
(Num(a), Num(b)) => a == b,
|
||||
(Sym(a), Sym(b)) => a == b,
|
||||
(Key(a), Key(b)) => a == b,
|
||||
(Exp(a), Exp(b)) => a == b,
|
||||
_ => false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
8
edn/src/edn_main.rs
Normal file
8
edn/src/edn_main.rs
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
use crate::*;
|
||||
|
||||
#[macro_export] macro_rules! run_tek_edn {
|
||||
($source:expr) => {
|
||||
struct EdnRunner;
|
||||
impl<E: Engine> EdnLayout<E> for EdnRunner;
|
||||
}
|
||||
}
|
||||
|
|
@ -16,7 +16,7 @@ pub trait EdnLayout<E: Engine> {
|
|||
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<EdnRender<'a, E>> { Box::new(()) }
|
||||
fn get_content <'a> (&'a self, _sym: &'a str) -> Box<EdnRender<'a, E>> { Box::new(()) }
|
||||
}
|
||||
|
||||
/// Renders from EDN source and context.
|
||||
|
|
|
|||
|
|
@ -4,40 +4,42 @@
|
|||
pub(crate) use std::{
|
||||
fmt::{Debug, Formatter, Error as FormatError}
|
||||
};
|
||||
pub use ::tek_layout;
|
||||
pub(crate) use ::tek_layout::{
|
||||
*,
|
||||
tek_engine::{Usually, Content, Render, Engine, Thunk}
|
||||
};
|
||||
|
||||
mod edn_error; pub use self::edn_error::*;
|
||||
mod edn_item; pub use self::edn_item::*;
|
||||
mod edn_token; pub use self::edn_token::*;
|
||||
mod edn_view; pub use self::edn_view::*;
|
||||
mod edn_error; pub use self::edn_error::*;
|
||||
mod edn_item; pub use self::edn_item::*;
|
||||
mod edn_token; pub use self::edn_token::*;
|
||||
mod edn_view; pub use self::edn_view::*;
|
||||
mod edn_main; pub use self::edn_main::*;
|
||||
|
||||
#[cfg(test)] #[test] fn test_edn () -> Result<(), ParseError> {
|
||||
use EdnItem::*;
|
||||
assert_eq!(EdnItem::read_all("")?,
|
||||
assert_eq!(EdnItem::<String>::read_all("")?,
|
||||
vec![]);
|
||||
assert_eq!(EdnItem::read_all(" ")?,
|
||||
assert_eq!(EdnItem::<String>::read_all(" ")?,
|
||||
vec![]);
|
||||
assert_eq!(EdnItem::read_all("1234")?,
|
||||
assert_eq!(EdnItem::<String>::read_all("1234")?,
|
||||
vec![Num(1234)]);
|
||||
assert_eq!(EdnItem::read_all("1234 5 67")?,
|
||||
assert_eq!(EdnItem::<String>::read_all("1234 5 67")?,
|
||||
vec![Num(1234), Num(5), Num(67)]);
|
||||
assert_eq!(EdnItem::read_all("foo/bar")?,
|
||||
assert_eq!(EdnItem::<String>::read_all("foo/bar")?,
|
||||
vec![Key("foo/bar".into())]);
|
||||
assert_eq!(EdnItem::read_all(":symbol")?,
|
||||
assert_eq!(EdnItem::<String>::read_all(":symbol")?,
|
||||
vec![Sym(":symbol".into())]);
|
||||
assert_eq!(EdnItem::read_all(" foo/bar :baz 456")?,
|
||||
assert_eq!(EdnItem::<String>::read_all(" foo/bar :baz 456")?,
|
||||
vec![Key("foo/bar".into()), Sym(":baz".into()), Num(456)]);
|
||||
assert_eq!(EdnItem::read_all(" (foo/bar :baz 456) ")?,
|
||||
assert_eq!(EdnItem::<String>::read_all(" (foo/bar :baz 456) ")?,
|
||||
vec![Exp(vec![Key("foo/bar".into()), Sym(":baz".into()), Num(456)])]);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg(test)] #[test] fn test_edn_layout () -> Result<(), ParseError> {
|
||||
let source = include_str!("example.edn");
|
||||
let layout = EdnItem::read_all(source)?;
|
||||
EdnItem::<String>::read_all(include_str!("../examples/edn01.edn"))?;
|
||||
EdnItem::<String>::read_all(include_str!("../examples/edn02.edn"))?;
|
||||
//panic!("{layout:?}");
|
||||
//let content = <dyn EdnLayout<::tek_engine::tui::Tui>>::from(&layout);
|
||||
Ok(())
|
||||
|
|
|
|||
|
|
@ -3,7 +3,9 @@ use std::sync::{Arc, Mutex, RwLock};
|
|||
|
||||
/// Handle input
|
||||
pub trait Handle<E: Engine>: Send + Sync {
|
||||
fn handle (&mut self, context: &E::Input) -> Perhaps<E::Handled>;
|
||||
fn handle (&mut self, _input: &E::Input) -> Perhaps<E::Handled> {
|
||||
Ok(None)
|
||||
}
|
||||
}
|
||||
|
||||
/// Current input state
|
||||
|
|
|
|||
|
|
@ -36,11 +36,11 @@ impl<'a, E: Engine> Content<E> for Box<dyn Render<E> + Send + Sync + 'a> {
|
|||
impl<E: Engine> Content<E> for &(dyn Render<E> + '_) {
|
||||
fn content (&self) -> impl Render<E> { self }
|
||||
}
|
||||
pub struct Thunk<E: Engine, T: Content<E>, F: Fn()->T + Send + Sync>(F, PhantomData<E>);
|
||||
impl<E: Engine, T: Content<E>, F: Fn()->T + Send + Sync> Thunk<E, T, F> {
|
||||
pub struct Thunk<E: Engine, T: Render<E>, F: Fn()->T + Send + Sync>(F, PhantomData<E>);
|
||||
impl<E: Engine, T: Render<E>, F: Fn()->T + Send + Sync> Thunk<E, T, F> {
|
||||
pub fn new (thunk: F) -> Self { Self(thunk, Default::default()) }
|
||||
}
|
||||
impl<E: Engine, T: Content<E>, F: Fn()->T + Send + Sync> Content<E> for Thunk<E, T, F> {
|
||||
impl<E: Engine, T: Render<E>, F: Fn()->T + Send + Sync> Content<E> for Thunk<E, T, F> {
|
||||
fn content (&self) -> impl Render<E> { (self.0)() }
|
||||
}
|
||||
impl<E: Engine, T: Content<E>> Content<E> for &T {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue