From e46c143decf2969fbfe27cf46c7024dd3b2aec41 Mon Sep 17 00:00:00 2001 From: Michael Sippel Date: Thu, 18 Jan 2024 17:16:20 +0100 Subject: [PATCH] test different style for , add meta-chars to ctx globally to avoid deadlock --- examples/tty-02-node/src/main.rs | 28 ++++++++++++++++------ lib-nested-core/src/edit_tree/node.rs | 4 ++-- lib-nested-core/src/editors/list/editor.rs | 2 +- lib-nested-tty/src/editors/list.rs | 4 ++-- lib-nested-tty/src/editors/mod.rs | 25 +------------------ 5 files changed, 27 insertions(+), 36 deletions(-) diff --git a/examples/tty-02-node/src/main.rs b/examples/tty-02-node/src/main.rs index 8607683..1bafa37 100644 --- a/examples/tty-02-node/src/main.rs +++ b/examples/tty-02-node/src/main.rs @@ -32,15 +32,18 @@ async fn main() { nested::editors::integer::editor::init_ctx( ctx.clone() ); nested::editors::list::init_ctx( ctx.clone() ); - let char_type = Context::parse(&ctx, "Char"); let digit_type = Context::parse(&ctx, ""); let list_type = Context::parse(&ctx, ""); + let posint_type = Context::parse(&ctx, ""); + let item_tyid = ctx.read().unwrap().get_var_typeid("Item").unwrap(); + ctx.write().unwrap().meta_chars.push(','); + ctx.write().unwrap().meta_chars.push('\"'); ctx.write().unwrap().set_edittree_hook( Arc::new( move |et: Arc>, t: laddertypes::TypeTerm| { - if let Ok(σ) = laddertypes::unify(&t, &char_type) { + 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()); } @@ -48,14 +51,25 @@ async fn main() { 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(); - nested_tty::editors::list::PTYListStyle::for_node( &mut *et, ("(", ",", ")")); - nested_tty::editors::list::PTYListController::for_node( &mut *et, None, None ); - *et = nested_tty::editors::edittree_make_list_edit(et.clone()); + let item_type = σ.get( &laddertypes::TypeID::Var(item_tyid) ).unwrap(); + 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 { + nested_tty::editors::list::PTYListStyle::for_node( &mut *et, ("{", ", ", "}")); + nested_tty::editors::list::PTYListController::for_node( &mut *et, Some(','), Some('}') ); + } + //*et = nested_tty::editors::edittree_make_list_edit(et.clone()); } } - ) + ) ); /* structure of Repr-Tree @@ -91,7 +105,7 @@ async fn main() { let edittree_digit = ctx.read().unwrap().setup_edittree(rt_digit.clone(), r3vi::buffer::singleton::SingletonBuffer::new(0).get_port()); //--- - let rt_string = ReprTree::new_arc( Context::parse(&ctx, ">>") ); + 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 diff --git a/lib-nested-core/src/edit_tree/node.rs b/lib-nested-core/src/edit_tree/node.rs index 6a69dbf..0be85f7 100644 --- a/lib-nested-core/src/edit_tree/node.rs +++ b/lib-nested-core/src/edit_tree/node.rs @@ -74,13 +74,13 @@ impl EditTree { editor: SingletonBuffer::new(None), spillbuf: Arc::new(RwLock::new(Vec::new())), cmd: SingletonBuffer::new(None), - close_char: SingletonBuffer::new(None), + close_char: SingletonBuffer::new(None), tree_nav: SingletonBuffer::new(None), }, ctx } } - + pub fn set_editor(mut self, editor: Arc) -> Self { self.ctrl.editor.set(Some(editor)); self diff --git a/lib-nested-core/src/editors/list/editor.rs b/lib-nested-core/src/editors/list/editor.rs index 89c2642..2b0bfff 100644 --- a/lib-nested-core/src/editors/list/editor.rs +++ b/lib-nested-core/src/editors/list/editor.rs @@ -175,7 +175,7 @@ impl ListEditor { } else { None } - } + } pub fn get_item_mut(&mut self) -> Option>>> { if let Some(idx) = self.cursor.get().idx { diff --git a/lib-nested-tty/src/editors/list.rs b/lib-nested-tty/src/editors/list.rs index 64cf6a1..83ec4ec 100644 --- a/lib-nested-tty/src/editors/list.rs +++ b/lib-nested-tty/src/editors/list.rs @@ -139,7 +139,7 @@ impl PTYListController { split_char: Option, close_char: Option ) { - /* +/* { let ctx = node.ctx.as_ref(); let mut ctx = ctx.write().unwrap(); @@ -151,7 +151,7 @@ impl PTYListController { ctx.meta_chars.push(*c); } } - */ +*/ let editor = node.get_edit::().unwrap(); let controller = Arc::new(RwLock::new(PTYListController::from_editor( editor, split_char, close_char, node.disp.depth.clone() ))); diff --git a/lib-nested-tty/src/editors/mod.rs b/lib-nested-tty/src/editors/mod.rs index eee1b74..3133edd 100644 --- a/lib-nested-tty/src/editors/mod.rs +++ b/lib-nested-tty/src/editors/mod.rs @@ -61,6 +61,7 @@ pub fn edittree_make_digit_view( node } + /* pub fn edittree_make_seq_view( mut node: EditTree @@ -84,27 +85,3 @@ pub fn edittree_make_seq_view( node } */ - -pub fn edittree_make_list_edit( - mut node: EditTree -) -> EditTree { - list::PTYListStyle::for_node( &mut node, ("(", "", ")") ); - list::PTYListController::for_node( &mut node, None, None ); - node -} -/* -pub fn edittree_make_tty_view( - et: EditTree -) -> EditTree { - if et.data.read().unwrap().get_type() == &Context::parse(&node.ctx, "Char") { - node_make_char_view( node ) - } else if et.data.read().unwrap().get_type() == &Context::parse(&node.ctx, "") { - node_make_seq_view( node ) - } else if et.data.read().unwrap().get_type() == &Context::parse(&node.ctx, "") { - node_make_list_edit( node ) - } else { - eprintln!("couldnt add view"); - node - } -} -*/