From e86070da500ca3a45ef55a14a82b3c03f0cbe03c Mon Sep 17 00:00:00 2001 From: Michael Sippel Date: Sun, 21 Jul 2024 18:16:43 +0200 Subject: [PATCH] fixes to make dual-editor with big/little endian projection work --- examples/tty-04-posint/src/main.rs | 479 +++++++++++---------- lib-nested-core/src/editors/char/mod.rs | 22 +- lib-nested-core/src/editors/integer/ctx.rs | 114 +++-- lib-nested-core/src/editors/list/ctx.rs | 168 +++----- lib-nested-core/src/editors/list/editor.rs | 6 +- lib-nested-core/src/repr_tree/context.rs | 13 +- lib-nested-core/src/repr_tree/mod.rs | 124 ++++-- lib-nested-core/src/repr_tree/morphism.rs | 73 +++- lib-nested-tty/src/editors/list.rs | 28 +- lib-nested-tty/src/editors/mod.rs | 1 - 10 files changed, 578 insertions(+), 450 deletions(-) diff --git a/examples/tty-04-posint/src/main.rs b/examples/tty-04-posint/src/main.rs index d6887d4..b48d112 100644 --- a/examples/tty-04-posint/src/main.rs +++ b/examples/tty-04-posint/src/main.rs @@ -32,171 +32,57 @@ use { std::sync::{Arc, RwLock}, }; -#[async_std::main] -async fn main() { - /* setup context - */ - let ctx = Arc::new(RwLock::new(Context::new())); - nested::editors::char::init_ctx( ctx.clone() ); - nested::editors::digit::init_ctx( ctx.clone() ); - nested::editors::integer::init_ctx( ctx.clone() ); - nested::editors::list::init_ctx( ctx.clone() ); - nested_tty::setup_edittree_hook(&ctx); - - /* Create a Representation-Tree of type `ℕ` - */ - let mut rt_int = ReprTree::new_arc( Context::parse(&ctx, "ℕ") ); - - /* Add a specific Representation-Path (big-endian hexadecimal) - */ - rt_int.create_branch( - Context::parse(&ctx, " ~ > ~ ~Char>") - ); - rt_int.create_branch( - Context::parse(&ctx, " ~ > ~ ~Char>") - ); - rt_int.create_branch( - Context::parse(&ctx, " ~ > ~ ~Char>") - ); - - eprintln!("make big endian hex repr"); - let mut b = VecBuffer::with_data(vec![ 'c', 'f', 'f' ]); - rt_int.insert_leaf( - Context::parse(&ctx, "~>~>~"), - nested::repr_tree::ReprLeaf::from_view( b.get_port().to_list() ) - ); - - let mut b_le = VecBuffer::with_data(vec!['3', '2', '1']); - rt_int.insert_leaf( - Context::parse(&ctx, "~>~>~"), - nested::repr_tree::ReprLeaf::from_view( b_le.get_port().to_list() ) - ); - - ctx.read().unwrap().morphisms.apply_morphism( - rt_int.descend(Context::parse(&ctx, " - - ~ > - ~ > - ~ - ")).expect("descend"), - &Context::parse(&ctx, ""), - &Context::parse(&ctx, "") - ); - ctx.read().unwrap().morphisms.apply_morphism( - rt_int.descend(Context::parse(&ctx, " - - ~ > - ~ ~Char~EditTree > - ")).expect("descend"), - &Context::parse(&ctx, ""), - &Context::parse(&ctx, "~") - ); - ctx.read().unwrap().morphisms.apply_morphism( - rt_int.descend(Context::parse(&ctx, " - - ~ > - ~ ~Char> - ")).expect("descend"), - &Context::parse(&ctx, "~~"), - &Context::parse(&ctx, "~EditTree") - ); - ctx.read().unwrap().morphisms.apply_morphism( - rt_int.descend(Context::parse(&ctx, " - - ~ > - ~ ~Char > - ")).expect("descend"), - &Context::parse(&ctx, "~EditTree"), - &Context::parse(&ctx, "") - ); - ctx.read().unwrap().morphisms.apply_morphism( - rt_int.clone(), - &Context::parse(&ctx, " - ℕ - ~ - ~ > - ~ > - ~ - "), - &Context::parse(&ctx, " - ℕ - ~ - ~ > - ~ > - ~ - ") - ); - ctx.read().unwrap().morphisms.apply_morphism( - rt_int.clone(), - &Context::parse(&ctx, " - ℕ - ~ - ~ > - ~ > - ~ - "), - &Context::parse(&ctx, " - ℕ - ~ - ~ > - ~ > - ~ - ") - ); - - let edittree_hex_le_list = ctx.read().unwrap() - .setup_edittree( - rt_int.descend(Context::parse(&ctx," - - ~ > - ~ ~Char > - ")).expect("descend"), - SingletonBuffer::new(0).get_port() +fn rebuild_projections( + ctx: Arc>, + repr_tree: Arc>, + morph_types: Vec< (laddertypes::TypeTerm, laddertypes::TypeTerm) > +) { + repr_tree.write().unwrap().detach(&ctx); + for (src_type, dst_type) in morph_types.iter() { + ctx.read().unwrap().morphisms.apply_morphism( + repr_tree.clone(), + &src_type, + &dst_type ); + } +} - ctx.read().unwrap().morphisms.apply_morphism( - rt_int.descend(Context::parse(&ctx, " - ~>~~Char> - ")).expect("descend"), - &Context::parse(&ctx, ""), - &Context::parse(&ctx, "") - ); - ctx.read().unwrap().morphisms.apply_morphism( - rt_int.descend(Context::parse(&ctx, " - ~>~~Char~EditTree> - ")).expect("descend"), - &Context::parse(&ctx, ""), - &Context::parse(&ctx, "~") - ); - ctx.read().unwrap().morphisms.apply_morphism( - rt_int.descend(Context::parse(&ctx, " - ~>~~Char> - ")).expect("descend"), - &Context::parse(&ctx, "~~"), - &Context::parse(&ctx, "~EditTree") - ); - ctx.read().unwrap().morphisms.apply_morphism( - rt_int.descend(Context::parse(&ctx, " - ~>~~Char> - ")).expect("descend"), - &Context::parse(&ctx, "~EditTree"), - &Context::parse(&ctx, "") - ); +fn setup_le_master(ctx: &Arc>, rt_int: &Arc>) { + rebuild_projections( + ctx.clone(), + rt_int.clone(), + vec![ + // Little Endian Editor + ( + "ℕ ~ ~ > ~ ~ Char> ~ EditTree", + "ℕ ~ ~ > ~ ~ Char>" + ), - /* Setup an Editor for the big-endian hexadecimal representation - * (this will add the representation `>~EditTree` to the ReprTree) - */ - let edittree_hex_be_list = ctx.read().unwrap() - .setup_edittree( - rt_int.descend(Context::parse(&ctx, " - - ~ > - ~ > - ~ - ")).expect("cant descend reprtree"), - SingletonBuffer::new(0).get_port() - ); + // Convert Endianness + ( + "ℕ ~ ~ > ~ ~ Char>", + "ℕ ~ ~ > ~ ~ Char>" + ), + // Big Endian Editor + ( + "ℕ ~ ~ > ~ ~ Char>", + "ℕ ~ ~ > ~ ~ Char ~ EditTree>" + ), + ( + "ℕ ~ ~ > ~ ~ Char ~ EditTree>", + "ℕ ~ ~ > ~ ~ Char ~ EditTree> ~ " + ), + ( + "ℕ ~ ~ > ~ ~ Char ~ EditTree> ~ ", + "ℕ ~ ~ > ~ ~ Char> ~ EditTree" + ), + ].into_iter() + .map(|(s,d)| (Context::parse(&ctx, s), Context::parse(&ctx, d))) + .collect() + ); +/* + /* * map seq of chars to seq of u64 digits * and add this projection to the ReprTree @@ -225,87 +111,203 @@ async fn main() { } ); - rt_int.insert_leaf(Context::parse(&ctx, " + rt_int.attach_leaf_to(Context::parse(&ctx, " ~ ~ ℤ_2^64 ~ machine.UInt64 > "), - nested::repr_tree::ReprLeaf::from_view( digits_view.clone() ) + digits_view.clone() ); + //ΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛ // + */ +} - /* convert to little endian - */ - ctx.read().unwrap().morphisms.apply_morphism( +fn setup_be_master(ctx: &Arc>, rt_int: &Arc>) { + rebuild_projections( + ctx.clone(), rt_int.clone(), - &Context::parse(&ctx, " - ℕ - ~ - ~ - ~ ℤ_2^64 - ~ machine.UInt64 > - "), - &Context::parse(&ctx, " - ℕ - ~ - ~ - ~ ℤ_2^64 - ~ machine.UInt64 > - ") + vec![ + // Big Endian Editor + ( + "ℕ ~ ~ > ~ ~ Char> ~ EditTree", + "ℕ ~ ~ > ~ ~ Char>" + ), + + // Convert Endianness + ( + "ℕ ~ ~ > ~ ~ Char>", + "ℕ ~ ~ > ~ ~ Char>" + ), + + // Big Endian Editor + ( + "ℕ ~ ~ > ~ ~ Char>", + "ℕ ~ ~ > ~ ~ Char ~ EditTree>" + ), + ( + "ℕ ~ ~ > ~ ~ Char ~ EditTree>", + "ℕ ~ ~ > ~ ~ Char ~ EditTree> ~ " + ), + ( + "ℕ ~ ~ > ~ ~ Char ~ EditTree> ~ ", + "ℕ ~ ~ > ~ ~ Char> ~ EditTree" + ), + ].into_iter() + .map(|(s,d)| (Context::parse(&ctx, s), Context::parse(&ctx, d))) + .collect() ); - /* convert to decimal - */ - ctx.read().unwrap().morphisms.apply_morphism( - rt_int.clone(), - &Context::parse(&ctx, "ℕ ~ ~ ~ℤ_2^64~machine.UInt64>"), - &Context::parse(&ctx, "ℕ ~ ~ ~ℤ_2^64~machine.UInt64>") - ); - - /* convert back to big endian - */ - ctx.read().unwrap().morphisms.apply_morphism( - rt_int.clone(), - &Context::parse(&ctx, "ℕ ~ ~ ~ℤ_2^64~machine.UInt64>"), - &Context::parse(&ctx, "ℕ ~ ~ ~ℤ_2^64~machine.UInt64>") - ); - - - /* map seq of u64 digits to seq of chars + /* + /* + * map seq of chars to seq of u64 digits * and add this projection to the ReprTree */ - // //VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV - let dec_digits_view = - rt_int.descend(Context::parse(&ctx, " - < PosInt 10 BigEndian > - ~ < Seq - ~ ℤ_2^64 - ~ machine.UInt64 > - ")).expect("cant descend repr tree") - .read().unwrap() - .get_port::>().unwrap() - .map(|digit| TerminalAtom::from(char::from_digit(*digit as u32, 10))) - .to_grid_horizontal(); - //ΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛ - // - //VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV - let hex_digits_view = - rt_int.descend(Context::parse(&ctx, " - < PosInt 16 BigEndian > - ~ < Seq - ~ ℤ_2^64 - ~ machine.UInt64 > + let mut chars_view = rt_int.descend(Context::parse(&ctx, " + + ~ > + ~ ~Char> ")).expect("cant descend") .read().unwrap() - .view_seq::< u64 >() - .map(|digit| TerminalAtom::from(char::from_digit(*digit as u32, 16))) - .to_grid_horizontal(); + .get_port::>() + .unwrap(); + + let mut digits_view = chars_view + .to_sequence() + .filter_map( + |digit_char| + + /* TODO: call morphism for each item + */ + match digit_char.to_digit(16) { + Some(d) => Some(d as u64), + None => None + } + ); + + rt_int.attach_leaf_to(Context::parse(&ctx, " + + ~ + ~ ℤ_2^64 + ~ machine.UInt64 > + "), + digits_view.clone() + ); + //ΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛΛ // + */ +} + +#[async_std::main] +async fn main() { + /* setup context + */ + let ctx = Arc::new(RwLock::new(Context::new())); + nested::editors::char::init_ctx( ctx.clone() ); + nested::editors::digit::init_ctx( ctx.clone() ); + nested::editors::integer::init_ctx( ctx.clone() ); + nested::editors::list::init_ctx( ctx.clone() ); + nested_tty::setup_edittree_hook(&ctx); + + /* Create a Representation-Tree of type `ℕ` + */ + let mut rt_int = ReprTree::new_arc( Context::parse(&ctx, "ℕ") ); + + /* Add a specific Representation-Path (big-endian hexadecimal) + */ + let mut digits_be = VecBuffer::with_data(vec![ 'c', 'f', 'f' ]); + rt_int.insert_leaf( + Context::parse(&ctx, "~>~>~~"), + nested::repr_tree::ReprLeaf::from_vec_buffer( digits_be.clone() ) + ); + + let mut digits_le = VecBuffer::with_data(vec!['3', '2', '1']); + rt_int.insert_leaf( + Context::parse(&ctx, "~>~>~~"), + nested::repr_tree::ReprLeaf::from_vec_buffer( digits_le.clone() ) + ); + + let mut digits_le_editvec = VecBuffer::>>::new(); + rt_int.insert_leaf( + Context::parse(&ctx, " + + ~ > + ~ + ~ Char + ~ EditTree> + ~ + "), + nested::repr_tree::ReprLeaf::from_vec_buffer( digits_le_editvec.clone() ) + ); + + let mut digits_be_editvec = VecBuffer::>>::new(); + rt_int.insert_leaf( + Context::parse(&ctx, " + + ~ > + ~ + ~ Char + ~ EditTree> + ~ + "), + nested::repr_tree::ReprLeaf::from_vec_buffer( digits_be_editvec.clone() ) + ); + + /* initially copy values from Vec to EditTree... + */ + rebuild_projections( + ctx.clone(), + rt_int.clone(), + // master representation + vec![ + ( + "ℕ ~ ~ > ~ ~ Char> ~ ", + "ℕ ~ ~ > ~ ~ Char>" + ), + ( + "ℕ ~ ~ > ~ ~ Char>", + "ℕ ~ ~ > ~ ~ Char ~ EditTree>" + ), + ( + "ℕ ~ ~ > ~ ~ Char> ~ ", + "ℕ ~ ~ > ~ ~ Char> ~ ~ " + ), + ( + "ℕ ~ ~ > ~ ~ Char> ~ ~ ", + "ℕ ~ ~ > ~ ~ Char> ~ EditTree" + ), + ].into_iter() + .map(|(s,d)| (Context::parse(&ctx, s), Context::parse(&ctx, d))) + .collect() + ); + + setup_le_master(&ctx, &rt_int); + + let edittree_hex_le_list = ctx.read().unwrap() + .setup_edittree( + rt_int.descend(Context::parse(&ctx," + + ~ > + ~ > + ~ + ")).expect("descend"), + SingletonBuffer::new(0).get_port() + ).unwrap(); + let edittree_hex_be_list = ctx.read().unwrap() + .setup_edittree( + rt_int.descend(Context::parse(&ctx," + + ~ > + ~ > + ~ + ")).expect("descend"), + SingletonBuffer::new(0).get_port() + ).unwrap(); /* list of both editors */ @@ -321,7 +323,7 @@ async fn main() { edittree_hex_le_list.get().goto(TreeCursor::none()); edittree.goto(TreeCursor{ leaf_mode: nested::editors::list::ListCursorMode::Insert, - tree_addr: vec![0,0] + tree_addr: vec![1,0] }); let edittree = Arc::new(RwLock::new(edittree)); @@ -331,7 +333,31 @@ async fn main() { /* event handler */ let ctx = ctx.clone(); + let rt_int = rt_int.clone(); + let last_idx = RwLock::new(1); move |ev| { + + let cur = edittree.read().unwrap().get_cursor(); + if cur.tree_addr.len() > 0 { + match cur.tree_addr[0] { + 0 => { + let mut li = last_idx.write().unwrap(); + if *li != 0 { + setup_be_master(&ctx, &rt_int); + *li = 0; + } + } + 1 => { + let mut li = last_idx.write().unwrap(); + if *li != 1 { + setup_le_master(&ctx, &rt_int); + *li = 1; + } + } + _=>{} + } + } + edittree.write().unwrap().send_cmd_obj(ev.to_repr_tree(&ctx)); } }); @@ -341,7 +367,7 @@ async fn main() { * so it will be displayed on TTY-output. */ let compositor = TerminalCompositor::new(app.port.inner()); - + /* Now add some views to our compositor */ { @@ -366,15 +392,18 @@ async fn main() { /* project the seq of u64 representations to a view */ + /* comp.push(nested_tty::make_label("dec: ").offset(Vector2::new(3,7))); comp.push(dec_digits_view.offset(Vector2::new(8,7)).map_item(|_,a| { a.add_style_back(TerminalStyle::fg_color((30,90,200))) })); - + */ + /* comp.push(nested_tty::make_label("hex: ").offset(Vector2::new(3,8))); comp.push(hex_digits_view.offset(Vector2::new(8,8)).map_item(|_,a| { a.add_style_back(TerminalStyle::fg_color((200, 200, 30))) })); + */ } /* write the changes in the view of `term_port` to the terminal diff --git a/lib-nested-core/src/editors/char/mod.rs b/lib-nested-core/src/editors/char/mod.rs index b4d0e51..5d37008 100644 --- a/lib-nested-core/src/editors/char/mod.rs +++ b/lib-nested-core/src/editors/char/mod.rs @@ -32,16 +32,17 @@ pub fn init_ctx( ctx: Arc> ) { let ctx = ctx.clone(); move |rt, σ| { { - let mut rt = rt.write().unwrap(); - if let Some(buf) = rt.singleton_buffer::() { + let mut b = rt.write().unwrap().singleton_buffer::(); + if let Some(buf) = b { // buffer already exists } else { // create char buffer - rt.insert_leaf( + rt.write().unwrap().insert_leaf( vec![].into_iter(), ReprLeaf::from_singleton_buffer( - SingletonBuffer::new('\0') - )); + SingletonBuffer::new('\0') + ) + ); } } @@ -53,13 +54,10 @@ pub fn init_ctx( ctx: Arc> ) { SingletonBuffer::::new(0).get_port() ); - rt.write().unwrap() - .insert_branch( - ReprTree::from_singleton_buffer( - Context::parse(&ctx, "EditTree"), - SingletonBuffer::new(edittree) - ) - ); + rt.insert_leaf( + Context::parse(&ctx, "EditTree"), + ReprLeaf::from_singleton_buffer(SingletonBuffer::new(edittree)) + ); } } ); diff --git a/lib-nested-core/src/editors/integer/ctx.rs b/lib-nested-core/src/editors/integer/ctx.rs index 7ca2a22..683dc61 100644 --- a/lib-nested-core/src/editors/integer/ctx.rs +++ b/lib-nested-core/src/editors/integer/ctx.rs @@ -20,6 +20,10 @@ pub fn init_ctx(ctx: Arc>) { ctx.write().unwrap().add_varname("SrcRadix"); ctx.write().unwrap().add_varname("DstRadix"); + + /* + * MACHINE INT, SEQ + */ let morphism_type = MorphismType { src_type: Context::parse(&ctx, " @@ -49,21 +53,22 @@ pub fn init_ctx(ctx: Arc>) { .apply_substitution(&|k|σ.get(k).cloned()) .clone() ).expect("cant descend") - .read().unwrap() - .view_seq::< u64 >(); + .view_seq::< u64 >(); - src_rt.insert_leaf(Context::parse(&ctx, " + src_rt.attach_leaf_to(Context::parse(&ctx, " ~ ~ ℤ_2^64 ~ machine.UInt64 > ").apply_substitution(&|k|σ.get(k).cloned()).clone(), - ReprLeaf::from_view( src_digits.reverse() ) + src_digits.reverse() ); } } ); + /* MACHINE INT, LIST + */ let morphism_type = MorphismType { src_type: Context::parse(&ctx, " ℕ @@ -95,16 +100,15 @@ pub fn init_ctx(ctx: Arc>) { ") .apply_substitution(&|k|σ.get(k).cloned()).clone() ).expect("cant descend") - .read().unwrap() - .get_port::< dyn ListView >().unwrap(); + .get_port::< dyn ListView >().unwrap(); - src_rt.insert_leaf( + src_rt.attach_leaf_to( Context::parse(&ctx, " ~ > ~ ~ ℤ_2^64 ~ machine.UInt64> ").apply_substitution(&|k| σ.get(k).cloned()).clone(), - ReprLeaf::from_view( src_digits.reverse() ) + src_digits.reverse() ); } } @@ -113,14 +117,14 @@ pub fn init_ctx(ctx: Arc>) { let mt = MorphismType { src_type: Context::parse(&ctx, " - ℕ + ℕ ~ ~ > ~ > ~ "), dst_type: Context::parse(&ctx, " - ℕ + ℕ ~ ~ > ~ > @@ -132,22 +136,23 @@ pub fn init_ctx(ctx: Arc>) { { let ctx = ctx.clone(); move |src_rt, σ| { + let radix = σ.get( &laddertypes::TypeID::Var(ctx.read().unwrap().get_var_typeid("Radix").unwrap()) ); let src_digits = src_rt.descend(Context::parse(&ctx, " - + ~ > ~ ~Char > ").apply_substitution(&|k|σ.get(k).cloned()).clone() ).expect("cant descend") - .read().unwrap() .get_port::< dyn ListView >().unwrap(); - src_rt.insert_leaf( + let rev_port = src_digits.reverse(); + src_rt.attach_leaf_to( Context::parse(&ctx, " - < PosInt Radix LittleEndian > + < PosInt Radix LittleEndian > ~ < Seq > ~ < List ~Char > ").apply_substitution(&|k| σ.get(k).cloned()).clone(), - ReprLeaf::from_view( src_digits.reverse() ) + rev_port ); } } @@ -176,21 +181,14 @@ pub fn init_ctx(ctx: Arc>) { ") .apply_substitution(&|k|σ.get(k).cloned()).clone() ).expect("cant descend") - .read().unwrap() - .view_seq::< u64 >(); + .view_seq::< u64 >(); - src_rt.write().unwrap().insert_leaf( - vec![ - Context::parse(&ctx, "") - .apply_substitution(&|k|σ.get(k).cloned()).clone(), - Context::parse(&ctx, ">") - .apply_substitution(&|k|σ.get(k).cloned()).clone(), - Context::parse(&ctx, ""), - Context::parse(&ctx, "") - ].into_iter(), - - ReprLeaf::from_view( src_digits.reverse() ) - ); + src_rt.attach_leaf_to(Context::parse(&ctx, " + + ~ ~ ℤ_2^64 ~ machine.UInt64> + ").apply_substitution(&|k|σ.get(k).cloned()).clone(), + src_digits.reverse() + ); } } ); @@ -219,32 +217,29 @@ pub fn init_ctx(ctx: Arc>) { let ctx = ctx.clone(); move |src_rt, σ| { - let src_digits = ReprTree::descend( - &src_rt, - Context::parse(&ctx, " + let src_digits = src_rt.descend( + Context::parse(&ctx, " ~ > ~ ~ℤ_2^64~machine.UInt64 > - ") - .apply_substitution(&|k|σ.get(k).cloned()).clone() - ).expect("cant descend") - .read().unwrap() - .get_port::< dyn ListView >().unwrap(); + ").apply_substitution(&|k|σ.get(k).cloned()).clone() + ) + .expect("cant descend") + .view_list::(); - src_rt.insert_leaf( + src_rt.attach_leaf_to( Context::parse(&ctx, " ~ > ~ ~ℤ_2^64~machine.UInt64 > - "), - ReprLeaf::from_view( src_digits.reverse() ) - ); + ").apply_substitution(&|k|σ.get(k).cloned()).clone(), + src_digits.reverse() + ); } } ); - let mt = MorphismType { src_type: Context::parse(&ctx, " ℕ @@ -273,16 +268,15 @@ pub fn init_ctx(ctx: Arc>) { ~ ~Char > ").apply_substitution(&|k|σ.get(k).cloned()).clone() ).expect("cant descend") - .read().unwrap() - .get_port::< dyn ListView >().unwrap(); + .view_list::(); - src_rt.insert_leaf( + src_rt.attach_leaf_to( Context::parse(&ctx, " < PosInt Radix BigEndian > ~ < Seq > ~ < List ~Char > ").apply_substitution(&|k| σ.get(k).cloned()).clone(), - ReprLeaf::from_view( src_digits.reverse() ) + src_digits.reverse() ); } } @@ -327,30 +321,24 @@ pub fn init_ctx(ctx: Arc>) { _ => 0 }; - let src_digits_rt = ReprTree::descend( - src_rt, - Context::parse(&ctx, " + let src_digits_rt = src_rt.descend(Context::parse(&ctx, " - ~ ~ ℤ_2^64 ~ machine.UInt64 >" - ).apply_substitution(&|k|σ.get(k).cloned()).clone() + ~ ~ ℤ_2^64 ~ machine.UInt64 > + ").apply_substitution(&|k|σ.get(k).cloned()).clone() ).expect("cant descend repr tree"); let dst_digits_port = - src_digits_rt.read().unwrap() - .view_seq::() + src_digits_rt.view_seq::() .to_positional_uint( src_radix ) .transform_radix( dst_radix ); - src_rt.write().unwrap() - .insert_leaf( - vec![ - Context::parse(&ctx, "").apply_substitution(&|k|σ.get(k).cloned()).clone(), - Context::parse(&ctx, ">").apply_substitution(&|k|σ.get(k).cloned()).clone(), - Context::parse(&ctx, ""), - Context::parse(&ctx, ""), - ].into_iter(), - ReprLeaf::from_view(dst_digits_port) - ); + src_rt.attach_leaf_to( + Context::parse(&ctx, " + + ~ ~ ℤ_2^64 ~ machine.UInt64> + ").apply_substitution(&|k|σ.get(k).cloned()).clone(), + dst_digits_port + ); } } ); diff --git a/lib-nested-core/src/editors/list/ctx.rs b/lib-nested-core/src/editors/list/ctx.rs index 8bc584c..839110d 100644 --- a/lib-nested-core/src/editors/list/ctx.rs +++ b/lib-nested-core/src/editors/list/ctx.rs @@ -1,7 +1,7 @@ use { r3vi::{ view::{ - ViewPort, + ViewPort, port::UpdateTask, OuterViewPort, Observer, singleton::*, list::* @@ -32,33 +32,34 @@ pub fn init_ctx(ctx: Arc>) { ctx.write().unwrap().morphisms.add_morphism(mt, { let ctx = ctx.clone(); move |src_rt, σ| { - let list_port = src_rt.read().unwrap().get_port::>().clone(); + let list_port = src_rt.descend(Context::parse(&ctx, "")).expect("descend").get_port::>().clone(); if let Some(list_port) = list_port { + + // for each char, create EditTree let edit_tree_list = list_port - // for each char, create and EditTree .map({ let ctx = ctx.clone(); move |c| { let item_rt = ReprTree::from_char(&ctx, *c); + ctx.read().unwrap().setup_edittree( item_rt.clone(), SingletonBuffer::new(0).get_port() ); + let et = item_rt - .descend(Context::parse(&ctx, "EditTree")).unwrap() - .read().unwrap() - .get_port::< dyn SingletonView >() - .expect("cant get view port (EditTree)") + .descend(Context::parse(&ctx, "Char ~ EditTree")).expect("cant descend repr tree") + .get_port::< dyn SingletonView >().expect("cant get view port (EditTree)") .get_view().unwrap() .get(); Arc::new(RwLock::new(et)) } }); - src_rt.write().unwrap().insert_leaf( - Context::parse(&ctx, "").get_lnf_vec().into_iter(), - ReprLeaf::from_view( edit_tree_list ) + src_rt.attach_leaf_to( + Context::parse(&ctx, "~"), + edit_tree_list ); } else { eprintln!("morphism missing view port"); @@ -70,44 +71,29 @@ pub fn init_ctx(ctx: Arc>) { src_type: Context::parse(&ctx, "~~"), dst_type: Context::parse(&ctx, "~EditTree") }; + ctx.write().unwrap().morphisms.add_morphism(mt, { let ctx = ctx.clone(); move |src_rt, σ| { let item_id = laddertypes::TypeID::Var( ctx.read().unwrap().get_var_typeid("Item").unwrap() ); if let Some( item_type ) = σ.get( &item_id ) { - /* - let mut item_vec_buffer = VecBuffer::new(); - - eprintln!("try attach to data port"); - if let Some( list_port ) = - src_rt - .descend(Context::parse(&ctx, "")).expect("") - .read().unwrap() - .get_port::< dyn ListView< Arc> > >() - { - eprintln!("get list port"); - item_vec_buffer.attach_to( list_port ); - }*/ - let mut item_vec_rt = src_rt - .descend(Context::parse(&ctx, "~")) + .descend( + Context::parse(&ctx, "~") + .apply_substitution(&|id| σ.get(id).cloned()).clone() + ) .expect("cant descend src repr"); - let item_vec_buffer = item_vec_rt - .write().unwrap() - .vec_buffer::< Arc> >().expect("cant get vec buffer"); + let item_vec_buffer = item_vec_rt.vec_buffer::< Arc> >(); - // eprintln!("create ListEditor"); let mut list_editor = ListEditor::with_data(ctx.clone(), item_type.clone(), item_vec_buffer); - let edittree_list = list_editor.into_node( SingletonBuffer::::new(0).get_port() ); - - // eprintln!("make edittree"); - src_rt.write().unwrap().insert_branch( - ReprTree::from_singleton_buffer( - Context::parse(&ctx, "EditTree"), + src_rt.insert_leaf( + Context::parse(&ctx, " ~ EditTree") + .apply_substitution(&|id| σ.get(id).cloned()).clone(), + ReprLeaf::from_singleton_buffer( SingletonBuffer::new(edittree_list) ) ); @@ -128,64 +114,31 @@ pub fn init_ctx(ctx: Arc>) { move |src_rt, σ| { let edittree = src_rt - .descend(Context::parse(&ctx, "EditTree")).unwrap() + .descend(Context::parse(&ctx, "~EditTree")).unwrap() .singleton_buffer::(); let list_edit = edittree.get().get_edit::< ListEditor >().unwrap(); let edittree_items = list_edit.read().unwrap().data.get_port().to_list(); - src_rt.write().unwrap().insert_leaf( - vec![].into_iter(), - ReprLeaf::from_view( - edittree_items - .map( - |edittree_char| - edittree_char - .read().unwrap() - .get_edit::().unwrap() - .read().unwrap() - .get() - ) - ) - ); - } - } - ); - let mt = crate::repr_tree::MorphismType { - src_type: Context::parse(&ctx, ">~EditTree"), - dst_type: Context::parse(&ctx, "~Char>") - }; - ctx.write().unwrap().morphisms.add_morphism( - mt, - { - let ctx = ctx.clone(); - move |src_rt, σ| { - let edittree = - src_rt - .descend(Context::parse(&ctx, "EditTree")).unwrap() - .singleton_buffer::(); - - let list_edit = edittree.get().get_edit::< ListEditor >().unwrap(); - let edittree_items = list_edit.read().unwrap().data.get_port().to_list(); - src_rt.write().unwrap().insert_leaf( - vec![ Context::parse(&ctx, "") ].into_iter(), + src_rt.insert_leaf( + Context::parse(&ctx, ""), ReprLeaf::from_view( - edittree_items - .map( - |edittree_char| - edittree_char - .read().unwrap() - .get_edit::().unwrap() - .read().unwrap() - .get_char() - ) - ) + edittree_items + .map(|edittree_char| + edittree_char + .read().unwrap() + .get_edit::().unwrap() + .read().unwrap() + .get() + )) ); } } ); + /* todo : unify the following two morphims with generic item parameter ? + */ let mt = crate::repr_tree::MorphismType { src_type: Context::parse(&ctx, ""), dst_type: Context::parse(&ctx, "~") @@ -195,17 +148,30 @@ pub fn init_ctx(ctx: Arc>) { { let ctx = ctx.clone(); move |src_rt, σ| { - let buf = VecBuffer::::new(); - let mut leaf = ReprLeaf::from_vec_buffer(buf); - leaf.attach_to( - src_rt.read().unwrap() - .get_port::>() - .unwrap() - ); - src_rt.write().unwrap().insert_leaf( - vec![ Context::parse(&ctx, "") ].into_iter(), - leaf - ); + src_rt + .attach_leaf_to( + Context::parse(&ctx, "~"), + src_rt + .descend(Context::parse(&ctx, "")) + .expect("descend") + .view_list::() + ); + } + } + ); + + let mt = crate::repr_tree::MorphismType { + src_type: Context::parse(&ctx, "~"), + dst_type: Context::parse(&ctx, "") + }; + ctx.write().unwrap().morphisms.add_morphism( + mt, + { + let ctx = ctx.clone(); + move |src_rt, σ| { + let src_port = src_rt.descend(Context::parse(&ctx, "~")).expect("descend") + .get_port::>>().unwrap(); + src_rt.attach_leaf_to( Context::parse(&ctx, ""), src_port.to_list() ); } } ); @@ -219,16 +185,14 @@ pub fn init_ctx(ctx: Arc>) { { let ctx = ctx.clone(); move |src_rt, σ| { - let buf = VecBuffer::>>::new(); - let mut leaf = ReprLeaf::from_vec_buffer(buf); - leaf.attach_to( - src_rt.read().unwrap() - .get_port::> >>() - .unwrap() - ); - src_rt.write().unwrap().insert_leaf( - vec![ Context::parse(&ctx, "") ].into_iter(), - leaf + let p = + src_rt + .descend(Context::parse(&ctx, "")).expect("descend") + .get_port::> >>().unwrap(); + + src_rt.attach_leaf_to( + Context::parse(&ctx, " ~ "), + p ); } } diff --git a/lib-nested-core/src/editors/list/editor.rs b/lib-nested-core/src/editors/list/editor.rs index 1bb0351..b9fa64e 100644 --- a/lib-nested-core/src/editors/list/editor.rs +++ b/lib-nested-core/src/editors/list/editor.rs @@ -319,12 +319,14 @@ impl ListEditor { let mut b = item.ctrl.spillbuf.write().unwrap(); let rt = ReprTree::new_arc(self.typ.clone()); - let edittree = self.ctx.read().unwrap() + let mut et = self.ctx.read().unwrap() .setup_edittree( rt, self.depth.map(|d| d+1) ); + if let Some(edittree) = et.as_mut(){ + let mut tail_node = edittree.get_mut(); tail_node.goto(TreeCursor::home()); @@ -354,6 +356,8 @@ impl ListEditor { edittree.value.clone() ); + } + } else { self.up(); self.listlist_split(); diff --git a/lib-nested-core/src/repr_tree/context.rs b/lib-nested-core/src/repr_tree/context.rs index 4835736..78f2ed7 100644 --- a/lib-nested-core/src/repr_tree/context.rs +++ b/lib-nested-core/src/repr_tree/context.rs @@ -179,7 +179,7 @@ impl Context { &self, rt: Arc>, depth: OuterViewPort> - ) -> SingletonBuffer { + ) -> Option> { let ladder = TypeTerm::Ladder(vec![ rt.read().unwrap().get_type().clone(), self.type_term_from_str("EditTree").expect("") @@ -194,14 +194,19 @@ impl Context { if let Some(new_edittree) = rt.descend(self.type_term_from_str("EditTree").unwrap()) { + let typ = rt.read().unwrap().get_type().clone(); let buf = new_edittree.singleton_buffer::(); (*self.edittree_hook)( &mut *buf.get_mut(), - rt.read().unwrap().get_type().clone() + typ ); - buf + Some(buf) } else { - unreachable!(); + eprintln!("cant find edit tree repr {} ~Ψ~ {}", + self.type_term_to_str(rt.read().unwrap().get_halo_type()), + self.type_term_to_str(rt.read().unwrap().get_type()) + ); + None } } } diff --git a/lib-nested-core/src/repr_tree/mod.rs b/lib-nested-core/src/repr_tree/mod.rs index 28488e5..072424f 100644 --- a/lib-nested-core/src/repr_tree/mod.rs +++ b/lib-nested-core/src/repr_tree/mod.rs @@ -40,6 +40,7 @@ pub struct ReprLeaf { /// keepalive for the observer that updates the buffer from in_port keepalive: Option>, + in_keepalive: Option>, } #[derive(Clone)] @@ -72,15 +73,16 @@ impl ReprLeaf { V::Msg: Clone { let mut in_port = ViewPort::::new(); - in_port.attach_to(src_port); + let in_keepalive = in_port.attach_to(src_port); - let mut buf_port = ViewPort::::new(); - buf_port.attach_to(in_port.outer()); + let mut out_port = ViewPort::::new(); + let out_keepalive = out_port.attach_to(in_port.outer()); ReprLeaf { - keepalive: None, + keepalive: Some(out_keepalive), + in_keepalive: Some(in_keepalive), in_port: in_port.inner().into(), - out_port: buf_port.into(), + out_port: out_port.into(), data: None, } } @@ -89,23 +91,55 @@ impl ReprLeaf { where V: View + ?Sized + 'static, V::Msg: Clone { + self.keepalive = None; + self.in_keepalive = None; + let ip = self.in_port.clone() .downcast::().ok() .unwrap(); + ip.0.detach(); - ip.0.update_hooks.write().unwrap().clear(); - ip.set_view(None) - .write().unwrap() - .reset(None); + if self.data.is_none() { + let mut op = self.out_port.clone() + .downcast::().ok() + .unwrap(); + + op.detach(); + self.keepalive = Some(op.attach_to(ip.0.outer())); + } + } + + pub fn detach_vec(&mut self) + where Item: Clone + Send + Sync + 'static + { + self.keepalive = None; + self.in_keepalive = None; + + let ip = self.in_port.clone() + .downcast::>().ok() + .unwrap(); + + ip.0.detach(); + + if let Some(data) = self.data.as_mut() { + let mut op = self.out_port.clone() + .downcast::>>().ok() + .unwrap(); + op.detach(); + + let data = data.clone().downcast::< RwLock> >().ok().unwrap(); + let buffer = VecBuffer::with_data_arc_port(data, op.inner()); + self.keepalive = Some(buffer.attach_to(ip.0.outer())) + } } pub fn attach_to(&mut self, src_port: OuterViewPort) where V: View + ?Sized + 'static, V::Msg: Clone { - self.in_port.clone() + self.in_keepalive = Some(self.in_port.clone() .downcast::().ok().unwrap() - .0.attach_to( src_port ); + .0.attach_to( src_port )); } pub fn from_singleton_buffer( buffer: SingletonBuffer ) -> Self @@ -113,6 +147,7 @@ impl ReprLeaf { { let in_port = ViewPort::>::new(); ReprLeaf { + in_keepalive: None, keepalive: Some(buffer.attach_to(in_port.outer())), in_port: in_port.inner().into(), out_port: buffer.get_port().0.into(), @@ -125,6 +160,7 @@ impl ReprLeaf { { let in_port = ViewPort::< dyn ListView >::new(); ReprLeaf { + in_keepalive: None, keepalive: Some(buffer.attach_to(in_port.outer())), in_port: in_port.inner().into(), out_port: buffer.get_port().0.into(), @@ -172,7 +208,6 @@ impl ReprLeaf { let data_arc = if let Some(data) = self.data.as_ref() { - eprintln!("downcast existing vec-data"); data.clone().downcast::>>().ok() } else { vec_port.update(); @@ -188,9 +223,6 @@ impl ReprLeaf { }; if let Some(data_arc) = data_arc { - eprintln!("ReprLeaf: have Vec-like data-arc"); - eprintln!("LEN = {}", data_arc.read().unwrap().len()); - self.data = Some(data_arc.clone() as Arc); let buf = VecBuffer::with_data_arc_port(data_arc, vec_port.inner()); self.keepalive = Some(buf.attach_to( @@ -252,6 +284,22 @@ impl ReprTree { &self.halo } + pub fn get_leaf_types(&self) -> Vec< TypeTerm > { + let mut leaf_types = Vec::new(); + if self.leaf.is_some() { + leaf_types.push( self.get_type().clone() ); + } + for (branch_type, branch) in self.branches.iter() { + for t in branch.read().unwrap().get_leaf_types() { + leaf_types.push(TypeTerm::Ladder(vec![ + self.get_type().clone(), + t + ]).normalize()) + } + } + leaf_types + } + pub fn insert_branch(&mut self, repr: Arc>) { let branch_type = repr.read().unwrap().get_type().clone(); @@ -261,6 +309,7 @@ impl ReprTree { self.halo.clone(), self.type_tag.clone() ]).normalize() ); + self.branches.insert(branch_type, repr.clone()); } @@ -307,12 +356,20 @@ impl ReprTree { V::Msg: Clone { if let Some(rung_type) = type_ladder.next() { - if let Some(next_repr) = self.branches.get(&rung_type) { - next_repr.write().unwrap().attach_leaf_to(type_ladder, src_port); + if &rung_type == self.get_type() { + if let Some(leaf) = self.leaf.as_mut() { + leaf.attach_to(src_port); + } else { + self.leaf = Some(ReprLeaf::from_view(src_port)); + } } else { - let mut next_repr = ReprTree::new(rung_type.clone()); - next_repr.attach_leaf_to(type_ladder, src_port); - self.insert_branch(Arc::new(RwLock::new(next_repr))); + if let Some(next_repr) = self.branches.get(&rung_type) { + next_repr.write().unwrap().attach_leaf_to(type_ladder, src_port); + } else { + let mut next_repr = ReprTree::new(rung_type.clone()); + next_repr.attach_leaf_to(type_ladder, src_port); + self.insert_branch(Arc::new(RwLock::new(next_repr))); + } } } else { if let Some(leaf) = self.leaf.as_mut() { @@ -337,13 +394,13 @@ impl ReprTree { } } - pub fn detach(&mut self, ctx: &Arc>) { + pub fn detach(&mut self, ctx: &Arc>) { if let Some(leaf) = self.leaf.as_mut() { if self.type_tag == Context::parse(&ctx, "Char") { leaf.detach::>(); } if self.type_tag == Context::parse(&ctx, "") { - leaf.detach::>(); + leaf.detach_vec::(); } if self.type_tag == Context::parse(&ctx, "") { leaf.detach::>(); @@ -393,7 +450,15 @@ impl ReprTree { } pub fn descend(rt: &Arc>, dst_type: impl Into) -> Option>> { - ReprTree::descend_ladder(rt, dst_type.into().get_lnf_vec().into_iter()) + let mut lnf = dst_type.into().get_lnf_vec(); + if lnf.len() > 0 { + if lnf[0] == rt.get_type() { + lnf.remove(0); + } + ReprTree::descend_ladder(rt, lnf.into_iter()) + } else { + Some(rt.clone()) + } } pub fn ascend(rt: &Arc>, type_term: impl Into) -> Arc> { @@ -487,14 +552,17 @@ pub trait ReprTreeExt { fn create_branch(&mut self, rung: impl Into); fn descend(&self, target_type: impl Into) -> Option>>; - fn get_port(&self) -> Option> where V::Msg: Clone; fn attach_leaf_to(&self, t: impl Into, v: OuterViewPort) where V::Msg: Clone; + fn get_port(&self) -> Option> where V::Msg: Clone; fn view_char(&self) -> OuterViewPort>; fn view_u8(&self) -> OuterViewPort>; fn view_u64(&self) -> OuterViewPort>; fn view_usize(&self) -> OuterViewPort>; + fn view_seq(&self) -> OuterViewPort>; + fn view_list(&self) -> OuterViewPort>; + fn singleton_buffer(&self) -> SingletonBuffer; fn vec_buffer(&self) -> VecBuffer; } @@ -554,6 +622,14 @@ impl ReprTreeExt for Arc> { self.read().unwrap().view_usize() } + fn view_seq(&self) -> OuterViewPort> { + self.read().unwrap().view_seq::() + } + + fn view_list(&self) -> OuterViewPort> { + self.read().unwrap().view_list::() + } + fn singleton_buffer(&self) -> SingletonBuffer { self.write().unwrap().singleton_buffer::().expect("") } diff --git a/lib-nested-core/src/repr_tree/morphism.rs b/lib-nested-core/src/repr_tree/morphism.rs index 64ea186..65eb5bb 100644 --- a/lib-nested-core/src/repr_tree/morphism.rs +++ b/lib-nested-core/src/repr_tree/morphism.rs @@ -52,7 +52,10 @@ impl MorphismBase { ) { self.morphisms.push( GenericReprTreeMorphism { - morph_type, + morph_type: MorphismType { + src_type: morph_type.src_type.normalize(), + dst_type: morph_type.dst_type.normalize() + }, setup_projection: Arc::new(setup_projection) } ); @@ -67,12 +70,13 @@ impl MorphismBase { let unification_problem = laddertypes::UnificationProblem::new( vec![ - ( src_type.clone(), m.morph_type.src_type.clone() ), - ( dst_type.clone(), m.morph_type.dst_type.clone() ) + ( src_type.clone().normalize(), m.morph_type.src_type.clone() ), + ( dst_type.clone().normalize(), m.morph_type.dst_type.clone() ) ] ); - if let Ok(σ) = unification_problem.solve() { + let unification_result = unification_problem.solve(); + if let Ok(σ) = unification_result { return Some((m, σ)); } } @@ -80,19 +84,70 @@ impl MorphismBase { None } + + pub fn find_morphism_ladder( + &self, + src_type: &TypeTerm, + dst_type: &TypeTerm, + ) -> Option<( + &GenericReprTreeMorphism, + TypeTerm, + HashMap + )> { + let mut src_lnf = src_type.clone().get_lnf_vec(); + let mut dst_lnf = dst_type.clone().get_lnf_vec(); + let mut halo = vec![]; + + while src_lnf.len() > 0 && dst_lnf.len() > 0 { + if let Some((m, σ)) = self.find_morphism( &TypeTerm::Ladder(src_lnf.clone()), &TypeTerm::Ladder(dst_lnf.clone()) ) { + return Some((m, TypeTerm::Ladder(halo), σ)); + } else { + if src_lnf[0] == dst_lnf[0] { + src_lnf.remove(0); + halo.push(dst_lnf.remove(0)); + } else { + return None; + } + } + } + + None + } + pub fn apply_morphism( &self, - mut repr_tree: Arc>, + repr_tree: Arc>, src_type: &TypeTerm, dst_type: &TypeTerm ) { -// let t = repr_tree.read().unwrap().get_type().clone(); - if let Some((m, σ)) = self.find_morphism( &src_type, dst_type ) { - (m.setup_projection)( &mut repr_tree, &σ ); + if let Some((m, s, σ)) = self.find_morphism_ladder( &src_type, dst_type ) { + //eprintln!("apply morphism on subtree {:?}", s); + let mut rt = repr_tree.descend( s ).expect("descend"); + (m.setup_projection)( &mut rt, &σ ); } else { - eprintln!("could not find morphism"); + eprintln!("could not find morphism\n {:?}\n ====>\n {:?}", src_type, dst_type); } } +/* + pub fn apply_seq_map_morphism( + &self, + mut repr_tree: Arc>, + src_item_type: &TypeTerm, + dst_item_type: &TypeTerm + ) { + if let Some((item_morphism, σ)) = self.find_morphism( &src_item_type, dst_item_type ) { + + let src_port = repr_tree.read().unwrap().get_port::> >>().unwrap(); + src_port.map( + m.setup_projection + ) + + (m.setup_projection)( &mut repr_tree, &σ ); + } else { + eprintln!("could not find item morphism"); + } + } + */ } //<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>> diff --git a/lib-nested-tty/src/editors/list.rs b/lib-nested-tty/src/editors/list.rs index 4af92fc..4584e9c 100644 --- a/lib-nested-tty/src/editors/list.rs +++ b/lib-nested-tty/src/editors/list.rs @@ -7,6 +7,7 @@ use { repr_tree::{Context, ReprTree}, editors::list::*, edit_tree::{TreeCursor, TreeNav, TreeNavResult, EditTree}, + repr_tree::{ReprTreeExt, ReprLeaf} }, crate::{ DisplaySegment, @@ -80,10 +81,12 @@ impl PTYListStyle { editor.get_cursor_port(), editor.get_data_port() ); - let seg_seq = seg_seq.read().unwrap(); + + let seg_seq0 = seg_seq.read().unwrap(); + let seg_seq = seg_seq0.get_view(); + drop(seg_seq0); seg_seq - .get_view() .map(move |segment| segment.display_view()) .separate(make_label(&self.style.1)) .wrap(make_label(&self.style.0), make_label(&self.style.2)) @@ -92,15 +95,14 @@ impl PTYListStyle { } pub fn for_node(node: &mut EditTree, style: (&str, &str, &str)) { + let editor = node.get_edit::().unwrap(); + let editor = editor.read().unwrap(); + let pty_view = Self::new(style).pty_view(&editor); node.disp.view - .write().unwrap() - .insert_branch(ReprTree::from_view( + .attach_leaf_to( Context::parse(&node.ctx, "TerminalView"), - Self::new(style) - .pty_view( - &node.get_edit::().unwrap().read().unwrap() - ) - )); + pty_view + ); } } @@ -226,6 +228,8 @@ impl PTYListController { self.depth.map(|d| d+1) ); + if let Some(new_edittree) = new_edittree { + let mut ne = new_edittree.get(); match ne.send_cmd_obj(cmd_obj.clone()) { TreeNavResult::Continue => { @@ -237,6 +241,12 @@ impl PTYListController { TreeNavResult::Exit } } + + } else { + + panic!("cant get edit tree"); + TreeNavResult::Continue + } }, ListCursorMode::Select => { if let Some(item) = e.get_item_mut() { diff --git a/lib-nested-tty/src/editors/mod.rs b/lib-nested-tty/src/editors/mod.rs index 0cf01fb..669aab7 100644 --- a/lib-nested-tty/src/editors/mod.rs +++ b/lib-nested-tty/src/editors/mod.rs @@ -17,7 +17,6 @@ use { } }; - pub fn edittree_make_char_view( node: EditTree ) -> EditTree {