From 0a6405b08e40b83dec2e17c9f118b56b4b5f31fc Mon Sep 17 00:00:00 2001 From: Michael Sippel Date: Sun, 1 Sep 2024 23:56:04 +0200 Subject: [PATCH] minor stuff & style --- examples/tty-02-digit/src/main.rs | 6 ++-- lib-nested-core/src/editors/list/editor.rs | 23 ++++++------- lib-nested-core/src/editors/list/segment.rs | 5 +-- lib-nested-core/src/repr_tree/context.rs | 1 - lib-nested-tty/src/editors/list.rs | 36 ++++++++++----------- 5 files changed, 33 insertions(+), 38 deletions(-) diff --git a/examples/tty-02-digit/src/main.rs b/examples/tty-02-digit/src/main.rs index ad50898..9279cc5 100644 --- a/examples/tty-02-digit/src/main.rs +++ b/examples/tty-02-digit/src/main.rs @@ -47,7 +47,7 @@ async fn main() { * / | \ * / | \ * / | \ - * u32 EditTree Char + * u64 EditTree Char * - Editor \ * - Display EditTree * / | \ - Editor @@ -109,13 +109,13 @@ async fn main() { .map_item(|p, a| { a.add_style_back(TerminalStyle::fg_color(((25 * p.x % 255) as u8, 200, 0))) }) - .offset(Vector2::new(5, 0))); + .offset(Vector2::new(5,0))); let label_str = ctx.read().unwrap().type_term_to_str(&rt_digit.read().unwrap().get_type()); comp.push( nested_tty::make_label(&label_str) .map_item(|_pt,atom| atom.add_style_front(TerminalStyle::fg_color((90,90,90)))) - .offset(Vector2::new(1, 1))); + .offset(Vector2::new(1,1))); comp.push(rt_digit .edittree( &ctx ).get().read().unwrap() diff --git a/lib-nested-core/src/editors/list/editor.rs b/lib-nested-core/src/editors/list/editor.rs index 92fa436..6773891 100644 --- a/lib-nested-core/src/editors/list/editor.rs +++ b/lib-nested-core/src/editors/list/editor.rs @@ -124,23 +124,18 @@ impl ListEditor { .set_editor(editor.clone()) .set_nav(editor.clone()) .set_cmd(editor.clone()) - .set_diag(e - .get_data_port() + .set_diag(e.get_data_port() .enumerate() .map(|(idx, item_editor)| { - let idx = *idx; - item_editor - .get_msg_port() - .map( - move |msg| { - let mut msg = msg.clone(); - msg.addr.insert(0, idx); - msg - } - ) + let idx = *idx; + item_editor.get_msg_port() + .map(move |msg| { + let mut msg = msg.clone(); + msg.addr.insert(0, idx); + msg + }) }) - .flatten() - ); + .flatten()); node.ctrl.spillbuf = e.spillbuf.clone(); node diff --git a/lib-nested-core/src/editors/list/segment.rs b/lib-nested-core/src/editors/list/segment.rs index f8dbdc7..4cd495b 100644 --- a/lib-nested-core/src/editors/list/segment.rs +++ b/lib-nested-core/src/editors/list/segment.rs @@ -42,11 +42,12 @@ impl SequenceView for ListSegmentSequence { type Item = ListSegment; fn len(&self) -> Option { + let l = self.data.len()?; match self.cur_cursor.mode { ListCursorMode::Insert => { - Some(self.data.len()? + if self.cur_cursor.idx.is_some() { 1 } else { 0 }) + Some(l + if self.cur_cursor.idx.is_some() { 1 } else { 0 }) } - _ => self.data.len(), + _ => Some(l), } } diff --git a/lib-nested-core/src/repr_tree/context.rs b/lib-nested-core/src/repr_tree/context.rs index a9ed8ec..c39da1e 100644 --- a/lib-nested-core/src/repr_tree/context.rs +++ b/lib-nested-core/src/repr_tree/context.rs @@ -223,7 +223,6 @@ impl Context { pub fn setup_edittree( &self, rt: &Arc> -// depth: OuterViewPort> ) -> Option>>> { if let Some(new_edittree) = rt.descend(self.type_term_from_str("EditTree").unwrap()) diff --git a/lib-nested-tty/src/editors/list.rs b/lib-nested-tty/src/editors/list.rs index 189125c..e55172c 100644 --- a/lib-nested-tty/src/editors/list.rs +++ b/lib-nested-tty/src/editors/list.rs @@ -224,37 +224,37 @@ impl PTYListController { ListCursorMode::Insert => { let rt = ReprTree::new_arc(e.typ.clone()); - let ladder = laddertypes::TypeTerm::Ladder(vec![ + let src_ladder = laddertypes::TypeTerm::Ladder(vec![ + rt.read().unwrap().get_type().clone() + ]); + let dst_ladder = laddertypes::TypeTerm::Ladder(vec![ rt.read().unwrap().get_type().clone(), ctx.type_term_from_str("EditTree").expect("") ]); ctx.apply_morphism( &rt, &laddertypes::MorphismType { - src_type: rt.get_type(), - dst_type: ladder + src_type: src_ladder, + dst_type: dst_ladder } ); let new_edittree = ctx.setup_edittree( &rt ); if let Some(new_edittree) = new_edittree { - - let mut ne = new_edittree.get(); - let mut ne = ne.write().unwrap(); - match ne.send_cmd_obj(cmd_obj.clone()) { - TreeNavResult::Continue => { - drop(ne); - e.insert(new_edittree.value.read().unwrap().clone()); - TreeNavResult::Continue + let mut ne = new_edittree.get(); + let mut ne = ne.write().unwrap(); + match ne.send_cmd_obj(cmd_obj.clone()) { + TreeNavResult::Continue => { + drop(ne); + e.insert(new_edittree.value.read().unwrap().clone()); + TreeNavResult::Continue + } + TreeNavResult::Exit => { + TreeNavResult::Exit + } } - TreeNavResult::Exit => { - TreeNavResult::Exit - } - } - } else { - panic!("cant get edit tree"); TreeNavResult::Continue } @@ -301,7 +301,7 @@ impl ObjCommander for PTYListController { let cmd_type = cmd_obj.read().unwrap().get_type().clone(); if cmd_type == Context::parse(&e.ctx, "ListCmd").into() - || cmd_type == Context::parse(&e.ctx, "NestedNode").into() + || cmd_type == Context::parse(&e.ctx, "EditTree").into() { e.send_cmd_obj( cmd_obj ) }