diff --git a/examples/tty-02-node/src/main.rs b/examples/tty-02-node/src/main.rs index 1bafa37..8bfdaca 100644 --- a/examples/tty-02-node/src/main.rs +++ b/examples/tty-02-node/src/main.rs @@ -40,26 +40,31 @@ async fn main() { ctx.write().unwrap().meta_chars.push(','); ctx.write().unwrap().meta_chars.push('\"'); + ctx.write().unwrap().meta_chars.push('}'); + + // Define a hook which is executed when a new editTree of type `t` is created. + // this will setup the display and navigation elements of the editor. + // It provides the necessary bridge to the rendering- & input-backend. ctx.write().unwrap().set_edittree_hook( Arc::new( move |et: Arc>, t: laddertypes::TypeTerm| { + let mut et = et.write().unwrap(); + if let Ok(σ) = laddertypes::unify(&t, &char_type.clone()) { - let mut et = et.write().unwrap(); *et = nested_tty::editors::edittree_make_char_view(et.clone()); } else if let Ok(σ) = laddertypes::unify(&t, &digit_type) { - let mut et = et.write().unwrap(); *et = nested_tty::editors::edittree_make_digit_view(et.clone()); } else if let Ok(σ) = laddertypes::unify(&t, &posint_type) { - let mut et = et.write().unwrap(); nested_tty::editors::list::PTYListStyle::for_node( &mut *et, ("0d", "", "")); nested_tty::editors::list::PTYListController::for_node( &mut *et, None, None ); } else if let Ok(σ) = laddertypes::unify(&t, &list_type) { - let mut et = et.write().unwrap(); let item_type = σ.get( &laddertypes::TypeID::Var(item_tyid) ).unwrap(); - if item_type == &char_type { + + // choose style based on element type + if *item_type == char_type { nested_tty::editors::list::PTYListStyle::for_node( &mut *et, ("\"", "", "\"")); nested_tty::editors::list::PTYListController::for_node( &mut *et, None, Some('\"') ); } else { @@ -97,16 +102,23 @@ async fn main() { rt_digit.write().unwrap() .insert_leaf( vec![ Context::parse(&ctx, "Char") ].into_iter(), - SingletonBuffer::new('x').get_port().into() + SingletonBuffer::new('4').get_port().into() ); /* setup TTY-Display for DigitEditor */ - let edittree_digit = ctx.read().unwrap().setup_edittree(rt_digit.clone(), r3vi::buffer::singleton::SingletonBuffer::new(0).get_port()); + let edittree_digit = ctx.read().unwrap() + .setup_edittree( + rt_digit + .read().unwrap() + .descend( Context::parse(&ctx, "Char") ).unwrap() + .clone(), + r3vi::buffer::singleton::SingletonBuffer::new(0).get_port()); //--- - let rt_string = ReprTree::new_arc( Context::parse(&ctx, ">") ); - let edittree = ctx.read().unwrap().setup_edittree(rt_string.clone(), r3vi::buffer::singleton::SingletonBuffer::new(0).get_port()); + let rt_string = ReprTree::new_arc( Context::parse(&ctx, ">") ); + let edittree = ctx.read().unwrap() + .setup_edittree(rt_string.clone(), r3vi::buffer::singleton::SingletonBuffer::new(0).get_port()); /* setup terminal */ @@ -125,28 +137,39 @@ async fn main() { let compositor = TerminalCompositor::new(app.port.inner()); // add some views to the display compositor - compositor.write().unwrap().push( - nested_tty::make_label("Hello World") - .map_item(|p, a| { - a.add_style_back(TerminalStyle::fg_color(((25 * p.x % 255) as u8, 200, 0))) - }) - .offset(Vector2::new(5, 0)), - ); - compositor.write().unwrap().push( edittree_digit.read().unwrap().display_view().offset(Vector2::new(0,2)) ); + { + let mut comp = compositor.write().unwrap(); - let label = ctx.read().unwrap().type_term_to_str(&rt_digit.read().unwrap().get_type()); - compositor - .write() - .unwrap() - .push(nested_tty::make_label(&label).offset(Vector2::new(0, 1))); + comp.push( + nested_tty::make_label("Hello World") + .map_item(|p, a| { + a.add_style_back(TerminalStyle::fg_color(((25 * p.x % 255) as u8, 200, 0))) + }) + .offset(Vector2::new(5, 0)), + ); - compositor.write().unwrap().push( edittree.read().unwrap().display_view().offset(Vector2::new(0,4)) ); + comp.push( + edittree_digit.read().unwrap().display_view() + .offset(Vector2::new(0,2)) + ); - let label = ctx.read().unwrap().type_term_to_str(&rt_string.read().unwrap().get_type()); - compositor - .write() - .unwrap() - .push(nested_tty::make_label(&label).offset(Vector2::new(0, 3))); + let label_str = ctx.read().unwrap().type_term_to_str(&rt_digit.read().unwrap().get_type()); + comp.push( + nested_tty::make_label(&label_str) + .offset(Vector2::new(0, 1)) + ); + + comp.push( + edittree.read().unwrap().display_view() + .offset(Vector2::new(0,4)) + ); + + let label_str = ctx.read().unwrap().type_term_to_str(&rt_string.read().unwrap().get_type()); + comp.push( + nested_tty::make_label(&label_str) + .offset(Vector2::new(0, 3)) + ); + } /* write the changes in the view of `term_port` to the terminal */ diff --git a/lib-nested-core/src/edit_tree/nav.rs b/lib-nested-core/src/edit_tree/nav.rs index a47204d..a8dc371 100644 --- a/lib-nested-core/src/edit_tree/nav.rs +++ b/lib-nested-core/src/edit_tree/nav.rs @@ -38,7 +38,7 @@ pub enum TreeNavCmd { pub trait TreeNav { /* CORE - */ + */ fn get_cursor(&self) -> TreeCursor { TreeCursor::default() } diff --git a/lib-nested-core/src/edit_tree/node.rs b/lib-nested-core/src/edit_tree/node.rs index 0be85f7..8b5a8a6 100644 --- a/lib-nested-core/src/edit_tree/node.rs +++ b/lib-nested-core/src/edit_tree/node.rs @@ -32,7 +32,9 @@ pub struct EdittreeControl { Option< Arc > >, - pub spillbuf: Arc> > >>, + pub spillbuf: Arc> > + >>, /// commander & navigation pub cmd: SingletonBuffer< @@ -47,9 +49,6 @@ pub struct EdittreeControl { >, } -/* - * TODO: rename to EditNode - */ #[derive(Clone)] pub struct EditTree { /// context diff --git a/lib-nested-core/src/editors/char/mod.rs b/lib-nested-core/src/editors/char/mod.rs index 3b3c1ff..d6a4d07 100644 --- a/lib-nested-core/src/editors/char/mod.rs +++ b/lib-nested-core/src/editors/char/mod.rs @@ -31,10 +31,15 @@ pub fn init_ctx( ctx: Arc> ) { { let ctx = ctx.clone(); move |rt, σ| { + if let Some(v) = rt.read().unwrap().get_view::>() { + eprintln!("prev value: {}", v.get()); + } + /* Create EditTree object */ let mut edittree_char = CharEditor::new_edit_tree( ctx.clone(), + SingletonBuffer::new('>'), r3vi::buffer::singleton::SingletonBuffer::::new(0).get_port() ); @@ -97,6 +102,7 @@ impl CharEditor { pub fn new_edit_tree( ctx0: Arc>, + data: SingletonBuffer, depth: OuterViewPort> ) -> EditTree { let data = SingletonBuffer::new('\0'); diff --git a/lib-nested-core/src/editors/integer/editor.rs b/lib-nested-core/src/editors/integer/editor.rs index 0a911c9..934888a 100644 --- a/lib-nested-core/src/editors/integer/editor.rs +++ b/lib-nested-core/src/editors/integer/editor.rs @@ -185,39 +185,6 @@ pub struct PosIntEditor { impl PosIntEditor { pub fn new(ctx: Arc>, radix: u32) -> Self { - /* - let mut node = Context::make_node( - &ctx, - Context::parse(&ctx, format!(">", radix).as_str()), - r3vi::buffer::singleton::SingletonBuffer::new(0).get_port() - ).unwrap(); - - // Set Type - node.data = ReprTree::ascend( - &node.data.clone(), - TypeTerm::App(vec![ - TypeTerm::TypeID(ctx.read().unwrap().get_typeid("PosInt").unwrap()), - TypeTerm::Num(radix as i64).into(), - TypeTerm::TypeID(ctx.read().unwrap().get_typeid("BigEndian").unwrap()) - ] - )); - */ -/* - PTYListController::for_node( &mut node, Some(' '), None ); - PTYListStyle::for_node( &mut node, - ( - match radix { - 2 => "0b".into(), - 8 => "0o".into(), - 10 => "0d".into(), - 16 => "0x".into(), - _ => "".into() - }, - "".into(), - "".into() - ) - ); -*/ PosIntEditor { radix, digits: EditTree::new( diff --git a/lib-nested-core/src/editors/list/cmd.rs b/lib-nested-core/src/editors/list/cmd.rs index 82b5023..4c37ae0 100644 --- a/lib-nested-core/src/editors/list/cmd.rs +++ b/lib-nested-core/src/editors/list/cmd.rs @@ -22,6 +22,7 @@ pub enum ListCmd { } impl ListCmd { + // note: cant use Into becaue of ctx (maybe global typedict?) pub fn into_repr_tree(self, ctx: &Arc>) -> Arc> { let buf = r3vi::buffer::singleton::SingletonBuffer::new(self); ReprTree::new_leaf( diff --git a/lib-nested-core/src/repr_tree/mod.rs b/lib-nested-core/src/repr_tree/mod.rs index 1f5ce63..3ea0c0c 100644 --- a/lib-nested-core/src/repr_tree/mod.rs +++ b/lib-nested-core/src/repr_tree/mod.rs @@ -24,6 +24,8 @@ pub struct ReprTree { branches: HashMap>>, } +//<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>> + impl std::fmt::Debug for ReprTree { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { writeln!(f, "| type: {:?}", self.type_tag)?; @@ -36,6 +38,8 @@ impl std::fmt::Debug for ReprTree { } } +//<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>> + impl ReprTree { pub fn new(type_tag: impl Into) -> Self { ReprTree { diff --git a/lib-nested-tty/src/editors/list.rs b/lib-nested-tty/src/editors/list.rs index 83ec4ec..3affc68 100644 --- a/lib-nested-tty/src/editors/list.rs +++ b/lib-nested-tty/src/editors/list.rs @@ -190,15 +190,15 @@ impl PTYListController { } pub fn handle_meta_char(&mut self, c: char, child_close_char: Option) -> TreeNavResult { - eprintln!("handle meta char: got '{}', child_close={:?}, self.close={:?}, split={:?}", c, child_close_char, self.close_char, self.split_char); +// eprintln!("handle meta char: got '{}', child_close={:?}, self.close={:?}, split={:?}", c, child_close_char, self.close_char, self.split_char); let mut e = self.editor.write().unwrap(); let cur = e.cursor.get(); - + if Some(c) == self.split_char // || Some(c) == child_close_char { e.listlist_split(); - eprintln!("done listlist split"); + // eprintln!("done listlist split"); TreeNavResult::Continue } else if Some(c) == child_close_char { e.goto(TreeCursor::none());