From bed4bc329bfa05c3e27cdb9759f8fef172726a05 Mon Sep 17 00:00:00 2001 From: Michael Sippel Date: Fri, 18 Nov 2022 00:21:29 +0100 Subject: [PATCH] cleanup editor constructors --- nested/src/core/context.rs | 86 ++++---- nested/src/core/mod.rs | 2 +- nested/src/lib.rs | 1 + nested/src/list/pty_editor.rs | 24 +-- nested/src/make_editor.rs | 396 ++++++++++++++++------------------ nested/src/product/editor.rs | 6 +- nested/src/product/nav.rs | 11 +- nested/src/sum/editor.rs | 2 - shell/src/command.rs | 5 +- shell/src/main.rs | 18 +- 10 files changed, 248 insertions(+), 303 deletions(-) diff --git a/nested/src/core/context.rs b/nested/src/core/context.rs index ec82346..afafeee 100644 --- a/nested/src/core/context.rs +++ b/nested/src/core/context.rs @@ -16,20 +16,22 @@ use { #[derive(Clone)] pub struct ReprTree { + type_tag: TypeTerm, port: Option, branches: HashMap>>, } impl ReprTree { - pub fn new() -> Self { + pub fn new(type_tag: TypeTerm) -> Self { ReprTree { + type_tag, port: None, branches: HashMap::new(), } } - pub fn new_leaf(port: AnyOuterViewPort) -> Arc> { - let mut tree = ReprTree::new(); + pub fn new_leaf(type_tag: TypeTerm, port: AnyOuterViewPort) -> Arc> { + let mut tree = ReprTree::new(type_tag); tree.insert_leaf(vec![].into_iter(), port); Arc::new(RwLock::new(tree)) } @@ -47,7 +49,7 @@ impl ReprTree { if let Some(next_repr) = self.branches.get(&type_term) { next_repr.write().unwrap().insert_leaf(type_ladder, port); } else { - let mut next_repr = ReprTree::new(); + let mut next_repr = ReprTree::new(type_term.clone()); next_repr.insert_leaf(type_ladder, port); self.insert_branch(type_term, Arc::new(RwLock::new(next_repr))); } @@ -55,48 +57,34 @@ impl ReprTree { self.port = Some(port); } } -} -//<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>> + //<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>> -#[derive(Clone)] -pub struct Object { - pub type_tag: TypeTerm, - pub repr: Arc>, -} - -impl Object { pub fn get_port(&self) -> Option> where V::Msg: Clone, { Some( - self.repr - .read() - .unwrap() - .port + self.port .clone()? .downcast::() .ok() - .unwrap(), + .unwrap() ) } - pub fn downcast(&self, dst_type: TypeTerm) -> Option { - if let Some(repr) = self.repr.read().unwrap().branches.get(&dst_type) { - Some(Object { - type_tag: dst_type, - repr: repr.clone(), - }) - } else { - None - } + pub fn downcast(&self, dst_type: &TypeTerm) -> Option>> { + self.branches.get(dst_type).cloned() } - fn downcast_ladder(&self, repr_ladder: impl Iterator) -> Option { - repr_ladder.fold(Some(self.clone()), |s, t| s?.downcast(t.clone())) + pub fn downcast_ladder(&self, mut repr_ladder: impl Iterator) -> Option>> { + let first = repr_ladder.next()?; + repr_ladder.fold( + self.downcast(&first), + |s, t| s?.read().unwrap().downcast(&t)) } +/* pub fn add_iso_repr( &self, type_ladder: impl Iterator, @@ -154,7 +142,7 @@ impl Object { morphism_constructors: &HashMap Object>>, ) { let mut cur_type = self.type_tag.clone(); - let mut cur_repr = self.repr.clone(); + let mut cur_repr = self.repr.clone(); for dst_type in type_ladder { if let Some(next_repr) = self.repr.read().unwrap().branches.get(&dst_type) { @@ -198,7 +186,9 @@ impl Object { _morphism_constructors: &HashMap Object>>, ) { // todo - } + +} + */ } //<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>> @@ -237,16 +227,16 @@ pub struct MorphismType { pub struct Context { /// assigns a name to every type type_dict: TypeDict, - + /// objects - objects: HashMap, + objects: HashMap>>, /// editors - editor_ctors: HashMap Option>> + Send + Sync>>, + editor_ctors: HashMap Option>> + Send + Sync>>, /// morphisms - default_constructors: HashMap Object + Send + Sync>>, - morphism_constructors: HashMap Object + Send + Sync>>, + default_constructors: HashMap Arc> + Send + Sync>>, + morphism_constructors: HashMap>) -> Arc> + Send + Sync>>, /// recursion parent: Option>>, @@ -279,7 +269,7 @@ impl Context { self.type_dict.type_term_to_str(&t) } - pub fn add_editor_ctor(&mut self, tn: &str, mk_editor: Box Option>> + Send + Sync>) { + pub fn add_editor_ctor(&mut self, tn: &str, mk_editor: Box Option>> + Send + Sync>) { if let Some(tid) = self.type_dict.get_typeid(&tn.into()) { self.editor_ctors.insert(tid, mk_editor); } else { @@ -287,10 +277,10 @@ impl Context { } } - pub fn make_editor(&self, type_term: TypeTerm) -> Option>> { + pub fn make_editor(&self, type_term: TypeTerm, depth: usize) -> Option>> { if let TypeTerm::Type{ id, args } = type_term.clone() { let mk_editor = self.editor_ctors.get(&id)?; - mk_editor(self, type_term) + mk_editor(self, type_term, depth) } else { None } @@ -299,7 +289,7 @@ impl Context { pub fn add_morphism( &mut self, morph_type: MorphismType, - morph_fn: Box Object + Send + Sync>, + morph_fn: Box>) -> Arc> + Send + Sync>, ) { self.morphism_constructors.insert(morph_type, morph_fn); } @@ -313,15 +303,12 @@ impl Context { if let Some(ctor) = self.default_constructors.get(&type_tag) { ctor() } else { - Object { - type_tag, - repr: Arc::new(RwLock::new(ReprTree::new())), - } + Arc::new(RwLock::new(ReprTree::new(type_tag))) }, ); } - pub fn get_obj(&self, name: &String) -> Option { + pub fn get_obj(&self, name: &String) -> Option>> { if let Some(obj) = self.objects.get(name) { Some(obj.clone()) } else if let Some(parent) = self.parent.as_ref() { @@ -331,6 +318,7 @@ impl Context { } } +/* pub fn get_obj_port<'a, V: View + ?Sized + 'static>( &self, name: &str, @@ -371,10 +359,7 @@ impl Context { }) { ctor(old_obj.clone()) } else { - Object { - type_tag: dst_type, - repr: Arc::new(RwLock::new(ReprTree::new())), - } + Arc::new(RwLock::new(ReprTree::new(dst_type))) }; new_obj @@ -409,7 +394,8 @@ impl Context { */ None } - } +} + */ } //<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>> diff --git a/nested/src/core/mod.rs b/nested/src/core/mod.rs index 4c0ba30..18c63a9 100644 --- a/nested/src/core/mod.rs +++ b/nested/src/core/mod.rs @@ -7,7 +7,7 @@ pub mod view; pub use { channel::{queue_channel, set_channel, singleton_channel, ChannelReceiver, ChannelSender}, - context::{Context, MorphismMode, MorphismType, Object, ReprTree}, + context::{Context, MorphismMode, MorphismType, ReprTree}, observer::{NotifyFnObserver, Observer, ObserverBroadcast, ObserverExt, ResetFnObserver}, port::{ AnyInnerViewPort, AnyOuterViewPort, AnyViewPort, InnerViewPort, OuterViewPort, ViewPort, diff --git a/nested/src/lib.rs b/nested/src/lib.rs index 842e9d6..0629432 100644 --- a/nested/src/lib.rs +++ b/nested/src/lib.rs @@ -46,5 +46,6 @@ pub trait Nested // + TreeType + Diagnostics + Send + + Sync {} diff --git a/nested/src/list/pty_editor.rs b/nested/src/list/pty_editor.rs index 8235b36..2b4e51d 100644 --- a/nested/src/list/pty_editor.rs +++ b/nested/src/list/pty_editor.rs @@ -1,6 +1,6 @@ use { crate::{ - core::{OuterViewPort, ViewPort}, + core::{OuterViewPort, ViewPort, TypeTerm}, list::{ ListCursor, ListCursorMode, ListSegment, ListSegmentSequence, @@ -33,7 +33,7 @@ where ItemEditor: Nested + ?Sized + Send + Sync + 'static style: SeqDecorStyle, depth: usize, - port: ViewPort + port: OuterViewPort } impl PTYListEditor @@ -45,14 +45,7 @@ where ItemEditor: Nested + ?Sized + Send + Sync + 'static split_char: char, depth: usize ) -> Self { - let port = ViewPort::new(); - PTYListEditor { - editor: ListEditor::new(make_item_editor, depth), - style, - depth, - split_char, - port - } + Self::from_editor(ListEditor::new(make_item_editor, depth), style, split_char, depth) } pub fn from_editor( @@ -61,7 +54,10 @@ where ItemEditor: Nested + ?Sized + Send + Sync + 'static split_char: char, depth: usize ) -> Self { - let port = ViewPort::new(); + let port = editor + .get_seg_seq_view() + .pty_decorate(style, depth); + PTYListEditor { editor, split_char, @@ -96,9 +92,7 @@ impl TerminalEditor for PTYListEditor where ItemEditor: Nested + ?Sized + Send + Sync + 'static { fn get_term_view(&self) -> OuterViewPort { - self.editor - .get_seg_seq_view() - .pty_decorate(self.style, self.depth) + self.port.clone() } fn handle_terminal_event(&mut self, event: &TerminalEvent) -> TerminalEditorResult { @@ -250,7 +244,7 @@ where ItemEditor: Nested + ?Sized + Send + Sync + 'static } impl Diagnostics for PTYListEditor -where ItemEditor: Nested + Diagnostics + ?Sized + Send + Sync + 'static +where ItemEditor: Nested + ?Sized + Send + Sync + 'static { fn get_msg_port(&self) -> OuterViewPort> { self.editor diff --git a/nested/src/make_editor.rs b/nested/src/make_editor.rs index 7f3e4ce..27115cd 100644 --- a/nested/src/make_editor.rs +++ b/nested/src/make_editor.rs @@ -1,13 +1,14 @@ use { crate::{ - core::{TypeLadder, Context, OuterViewPort}, + core::{TypeTerm, TypeLadder, Context, OuterViewPort}, terminal::{TerminalView, TerminalEditor, TerminalEvent, TerminalEditorResult, make_label}, tree::{TreeNav}, integer::PosIntEditor, list::{ListEditor, PTYListEditor}, sequence::{decorator::{SeqDecorStyle}}, product::editor::ProductEditor, + sum::SumEditor, char_editor::CharEditor, diagnostics::Diagnostics, Nested @@ -48,226 +49,197 @@ struct GrammarRuleEditor { rhs: Arc>> } -pub fn make_editor(ctx: Arc>, t: &TypeLadder, depth: usize) -> Arc> { - let c = ctx.read().unwrap(); - if t[0] == c.type_term_from_str("( PosInt 16 BigEndian )").unwrap() { - Arc::new(RwLock::new(PosIntEditor::new(16))) as Arc> - } else if t[0] == c.type_term_from_str("( PosInt 10 BigEndian )").unwrap() { - Arc::new(RwLock::new(PosIntEditor::new(10))) as Arc> +pub fn init_ctx() -> Arc> { + let mut ctx = Arc::new(RwLock::new(Context::new())); + for tn in vec![ + "MachineWord", "MachineInt", "MachineSyllab", "Bits", + "Vec", "Stream", "Json", + "Sequence", "AsciiString", "UTF-8-String", "Char", "String", "Symbol", + "PosInt", "Digit", "LittleEndian", "BigEndian", + "DiffStream", "ℕ", "List", "PathSegment", "Path", "Term", "RGB", "Vec3i" + ] { ctx.write().unwrap().add_typename(tn.into()); } - } else if t[0] == c.type_term_from_str("( String )").unwrap() { - Arc::new(RwLock::new( - PTYListEditor::new( - Box::new(|| { + ctx.write().unwrap().add_editor_ctor( + "Char", Box::new( + |ctx: &Context, ty: TypeTerm, _depth: usize| { + Some( Arc::new(RwLock::new(CharEditor::new())) - }), - SeqDecorStyle::DoubleQuote, - '"', - depth - ) - )) - - } else if t[0] == c.type_term_from_str("( Symbol )").unwrap() { - Arc::new(RwLock::new( - PTYListEditor::new( - Box::new(|| { - Arc::new(RwLock::new(CharEditor::new())) - }), - SeqDecorStyle::Plain, - ' ', - depth - ) - )) - - } else if t[0] == c.type_term_from_str("( List String )").unwrap() { - Arc::new(RwLock::new( - PTYListEditor::new( - Box::new({ - let d = depth + 1; - let ctx = ctx.clone(); - move || { - make_editor( - ctx.clone(), - &vec![ctx.read().unwrap().type_term_from_str("( String )").unwrap()], - d - ) + as Arc>) + } + ) + ); + ctx.write().unwrap().add_editor_ctor( + "Symbol", Box::new( + |ctx: &Context, ty: TypeTerm, depth: usize| { + ctx.make_editor( + ctx.type_term_from_str("( List Char 0 )").unwrap(), + depth + ) + } + ) + ); + ctx.write().unwrap().add_editor_ctor( + "String", Box::new( + |ctx: &Context, ty: TypeTerm, depth: usize| { + ctx.make_editor( + ctx.type_term_from_str("( List Char 3 )").unwrap(), + depth + ) + } + ) + ); + ctx.write().unwrap().add_editor_ctor( + "PosInt", Box::new( + |ctx: &Context, ty: TypeTerm, _depth: usize| { + match ty { + TypeTerm::Type { + id, args + } => { + if args.len() > 0 { + match args[0] { + TypeTerm::Num(radix) => { + Some( + Arc::new(RwLock::new(PosIntEditor::new(radix as u32))) + as Arc> + ) + }, + _ => None + } + } else { + None + } } - }), - SeqDecorStyle::EnumSet, - '"', - depth - ) - )) as Arc> - } else if t[0] == c.type_term_from_str("( List Symbol )").unwrap() { - Arc::new(RwLock::new( - PTYListEditor::new( - Box::new({ - let d = depth + 1; - let ctx = ctx.clone(); - move || { - make_editor( - ctx.clone(), - &vec![ctx.read().unwrap().type_term_from_str("( Symbol )").unwrap()], - d - ) + _ => None + } + } + ) + ); + + ctx.write().unwrap().add_editor_ctor( + "List", Box::new({ + let ctx = ctx.clone(); + move |c_: &Context, ty: TypeTerm, depth: usize| { + match ty { + TypeTerm::Type { + id, args + } => { + if args.len() > 0 { + // todod factor style out of type arGS + let style = if args.len() > 1 { + match args[1] { + TypeTerm::Num(0) => SeqDecorStyle::Plain, + TypeTerm::Num(1) => SeqDecorStyle::HorizontalSexpr, + TypeTerm::Num(2) => SeqDecorStyle::VerticalSexpr, + TypeTerm::Num(3) => SeqDecorStyle::DoubleQuote, + TypeTerm::Num(4) => SeqDecorStyle::Tuple, + TypeTerm::Num(5) => SeqDecorStyle::EnumSet, + TypeTerm::Num(6) => SeqDecorStyle::Path, + _ => SeqDecorStyle::HorizontalSexpr + } + }else { + SeqDecorStyle::HorizontalSexpr + }; + + let delim = if args.len() > 1 { + match args[1] { + TypeTerm::Num(0) => ' ', + TypeTerm::Num(1) => ' ', + TypeTerm::Num(2) => '\n', + TypeTerm::Num(3) => '"', + TypeTerm::Num(4) => ',', + TypeTerm::Num(5) => ',', + TypeTerm::Num(6) => '/', + _ => '\0' + } + }else { + '\0' + }; + + Some( + Arc::new(RwLock::new(PTYListEditor::new( + Box::new({ + let ctx = ctx.clone(); + move || { + ctx.read().unwrap().make_editor(args[0].clone(), depth + 1).unwrap() + } + }), + style, + delim, + depth + ))) + as Arc> + ) + } else { + None + } } - }), - SeqDecorStyle::EnumSet, - ' ', - depth - ) - )) as Arc> + _ => None + } + } + } + )); - } else if t[0] == c.type_term_from_str("( List Char )").unwrap() { - Arc::new(RwLock::new( - PTYListEditor::new( - Box::new( - || { Arc::new(RwLock::new(CharEditor::new())) } - ), - SeqDecorStyle::Plain, - '\n', - depth+1 - ) - )) as Arc> + ctx.write().unwrap().add_editor_ctor( + "RGB", Box::new({ + let c = ctx.clone(); + move |ctx: &Context, ty: TypeTerm, depth: usize| { + Some(Arc::new(RwLock::new(ProductEditor::new(depth, c.clone()) + .with_t(Point2::new(0, 0), "{ ") + .with_t(Point2::new(1, 1), "r: ") + .with_n(Point2::new(2, 1), vec![ ctx.type_term_from_str("( PosInt 16 BigEndian )").unwrap() ] ) + .with_t(Point2::new(1, 2), "g: ") + .with_n(Point2::new(2, 2), vec![ ctx.type_term_from_str("( PosInt 16 BigEndian )").unwrap() ] ) + .with_t(Point2::new(1, 3), "b: ") + .with_n(Point2::new(2, 3), vec![ ctx.type_term_from_str("( PosInt 16 BigEndian )").unwrap() ] ) + .with_t(Point2::new(0, 4), "} ") + )) as Arc>) + } + })); - } else if t[0] == c.type_term_from_str("( List ℕ )").unwrap() { - Arc::new(RwLock::new( - PTYListEditor::new( - Box::new(|| { - Arc::new(RwLock::new(PosIntEditor::new(16))) - }), - SeqDecorStyle::EnumSet, - ',', - depth - ) - )) as Arc> + ctx.write().unwrap().add_editor_ctor( + "PathSegment", Box::new( + |ctx: &Context, ty: TypeTerm, depth: usize| { + ctx.make_editor( + ctx.type_term_from_str("( List Char 0 )").unwrap(), + depth + ) + } + ) + ); + ctx.write().unwrap().add_editor_ctor( + "Path", Box::new( + |ctx: &Context, ty: TypeTerm, depth: usize| { + ctx.make_editor( + ctx.type_term_from_str("( List PathSegment 6 )").unwrap(), + depth+1 + ) + } + ) + ); - } else if t[0] == c.type_term_from_str("( Path )").unwrap() { - Arc::new(RwLock::new(PTYListEditor::new( - Box::new({ - let d= depth+1; - move || { - Arc::new(RwLock::new(PTYListEditor::new( - Box::new(|| { - Arc::new(RwLock::new(CharEditor::new())) - }), - SeqDecorStyle::Plain, - '\n', - d - ))) - }}), - SeqDecorStyle::Path, - '/', - depth - ))) as Arc> + ctx.write().unwrap().add_editor_ctor( + "Term", Box::new( + |ctx: &Context, ty: TypeTerm, depth: usize| { + let mut s = SumEditor::new( + vec![ + ctx.make_editor(ctx.type_term_from_str("( Symbol )").unwrap(), depth+1).unwrap(), + ctx.make_editor(ctx.type_term_from_str("( PosInt 10 )").unwrap(), depth+1).unwrap(), + ctx.make_editor(ctx.type_term_from_str("( List Term )").unwrap(), depth+1).unwrap(), + ] + ); + s.select(0); + Some( + Arc::new(RwLock::new( + s + )) + ) + } + ) + ); - } else if t[0] == c.type_term_from_str("( List Path )").unwrap() { - Arc::new(RwLock::new( - PTYListEditor::new( - Box::new({ - let d = depth + 1; - let ctx = ctx.clone(); - move || { - make_editor( - ctx.clone(), - &vec![ctx.read().unwrap().type_term_from_str("( Path )").unwrap()], - d - ) - } - }), - SeqDecorStyle::EnumSet, - ',', - depth - ) - )) as Arc> - - } else if t[0] == c.type_term_from_str("( List RGB )").unwrap() { - Arc::new(RwLock::new( - PTYListEditor::::new( - { - let d = depth+1; - let ctx = ctx.clone(); - Box::new(move || { - make_editor(ctx.clone(), &vec![ ctx.read().unwrap().type_term_from_str("( RGB )").unwrap() ], d) - }) - }, - SeqDecorStyle::VerticalSexpr, - ',', - depth - ) - )) as Arc> - - } else if t[0] == c.type_term_from_str("( RGB )").unwrap() { - Arc::new(RwLock::new(ProductEditor::new(depth, ctx.clone()) - .with_t(Point2::new(0, 0), "{ ") - .with_t(Point2::new(1, 1), "r: ") - .with_n(Point2::new(2, 1), vec![ ctx.read().unwrap().type_term_from_str("( PosInt 16 BigEndian )").unwrap() ] ) - .with_t(Point2::new(1, 2), "g: ") - .with_n(Point2::new(2, 2), vec![ ctx.read().unwrap().type_term_from_str("( PosInt 16 BigEndian )").unwrap() ] ) - .with_t(Point2::new(1, 3), "b: ") - .with_n(Point2::new(2, 3), vec![ ctx.read().unwrap().type_term_from_str("( PosInt 16 BigEndian )").unwrap() ] ) - .with_t(Point2::new(0, 4), "} ") - )) as Arc> - - } else if t[0] == c.type_term_from_str("( Vec3i )").unwrap() { - Arc::new(RwLock::new(ProductEditor::new(depth, ctx.clone()) - .with_t(Point2::new(0, 0), "{") - .with_t(Point2::new(1, 1), "x: ") - .with_n(Point2::new(2, 1), vec![ ctx.read().unwrap().type_term_from_str("( PosInt 10 BigEndian )").unwrap() ] ) - .with_t(Point2::new(1, 2), "y: ") - .with_n(Point2::new(2, 2), vec![ ctx.read().unwrap().type_term_from_str("( PosInt 10 BigEndian )").unwrap() ] ) - .with_t(Point2::new(1, 3), "z: ") - .with_n(Point2::new(2, 3), vec![ ctx.read().unwrap().type_term_from_str("( PosInt 10 BigEndian )").unwrap() ] ) - .with_t(Point2::new(0, 4), "}") - )) as Arc> - - } else if t[0] == c.type_term_from_str("( Json )").unwrap() { - Arc::new(RwLock::new( - PTYListEditor::::new( - Box::new({ - let ctx = ctx.clone(); - move || { - Arc::new(RwLock::new(ProductEditor::new(depth, ctx.clone()) - .with_n(Point2::new(0, 0), vec![ ctx.read().unwrap().type_term_from_str("( String )").unwrap() ] ) - .with_t(Point2::new(1, 0), ": ") - .with_n(Point2::new(2, 0), vec![ ctx.read().unwrap().type_term_from_str("( Json )").unwrap() ] ) - )) as Arc> - } - }), - SeqDecorStyle::VerticalSexpr, - '\n', - depth - ) - )) as Arc> - - } else if t[0] == c.type_term_from_str("( List Term )").unwrap() { - Arc::new(RwLock::new( - PTYListEditor::::new( - Box::new({ - let ctx = ctx.clone(); - move || { - make_editor(ctx.clone(), &vec![ ctx.read().unwrap().type_term_from_str("( Term )").unwrap() ], depth+1) - } - }), - SeqDecorStyle::Tuple, - '\n', - depth - ) - )) as Arc> - - } else { // else: term - Arc::new(RwLock::new( - PTYListEditor::new( - || { - Arc::new(RwLock::new(CharEditor::new())) - }, - SeqDecorStyle::DoubleQuote, - ' ', - depth - ) - )) - } + ctx } + diff --git a/nested/src/product/editor.rs b/nested/src/product/editor.rs index 4ab8357..ec75e3f 100644 --- a/nested/src/product/editor.rs +++ b/nested/src/product/editor.rs @@ -10,12 +10,9 @@ use { list::ListCursorMode, product::{segment::ProductEditorSegment}, sequence::{SequenceView}, - make_editor::make_editor, - tree::{TreeNav, TreeNavResult}, diagnostics::{Diagnostics, Message}, terminal::{TerminalStyle}, - Nested }, cgmath::{Vector2, Point2}, @@ -139,7 +136,6 @@ impl ProductEditor { if cur.tree_addr[0] == idx { *cur_depth = cur.tree_addr.len(); } - *cur_dist = cur.tree_addr[0] - idx } else { @@ -221,7 +217,7 @@ impl TerminalEditor for ProductEditor { } } } else { - let e = make_editor(self.ctx.clone(), t, *ed_depth+1); + let e = self.ctx.read().unwrap().make_editor(t[0].clone(), *ed_depth+1).unwrap(); *editor = Some(e.clone()); update_segment = true; diff --git a/nested/src/product/nav.rs b/nested/src/product/nav.rs index 0a74921..8d8dd49 100644 --- a/nested/src/product/nav.rs +++ b/nested/src/product/nav.rs @@ -3,7 +3,6 @@ use { list::ListCursorMode, tree::{TreeNav, TreeNavResult, TreeCursor}, product::{segment::ProductEditorSegment, ProductEditor}, - make_editor::{make_editor}, Nested }, cgmath::{Point2, Vector2}, @@ -66,14 +65,13 @@ impl TreeNav for ProductEditor { if c.tree_addr.len() > 0 { self.cursor = Some(crate::modulo(c.tree_addr.remove(0), self.n_indices.len() as isize)); - if let Some(mut element) = self.get_cur_segment_mut() { if let Some(ProductEditorSegment::N{ t, editor, ed_depth, cur_depth, cur_dist:_ }) = element.deref_mut() { if let Some(e) = editor { e.write().unwrap().goto(c.clone()); } else if c.tree_addr.len() > 0 { // create editor - let e = make_editor(self.ctx.clone(), t, *ed_depth+1); + let e = self.ctx.read().unwrap().make_editor(t[0].clone(), *ed_depth+1).unwrap(); *editor = Some(e.clone()); let mut e = e.write().unwrap(); e.goto(c.clone()); @@ -91,6 +89,10 @@ impl TreeNav for ProductEditor { TreeNavResult::Continue } else { + if let Some(mut ed) = self.get_cur_editor() { + ed.write().unwrap().goto(TreeCursor::none()); + } + self.cursor = None; if let Some(i) = old_cursor { @@ -127,7 +129,8 @@ impl TreeNav for ProductEditor { e.goby(direction); } else { // create editor - let e = make_editor(self.ctx.clone(), t, *ed_depth+1); + + let e = self.ctx.read().unwrap().make_editor(t[0].clone(), *ed_depth+1).unwrap(); *editor = Some(e.clone()); let mut e = e.write().unwrap(); e.goby(direction); diff --git a/nested/src/sum/editor.rs b/nested/src/sum/editor.rs index 450cdac..f4e28f3 100644 --- a/nested/src/sum/editor.rs +++ b/nested/src/sum/editor.rs @@ -10,8 +10,6 @@ use { list::ListCursorMode, product::{segment::ProductEditorSegment}, sequence::{SequenceView}, - make_editor::make_editor, - tree::{TreeNav, TreeCursor, TreeNavResult}, diagnostics::{Diagnostics, Message}, terminal::{TerminalStyle}, diff --git a/shell/src/command.rs b/shell/src/command.rs index 91a8717..ea5b836 100644 --- a/shell/src/command.rs +++ b/shell/src/command.rs @@ -18,7 +18,6 @@ use { }, tree::{TreeCursor, TreeNav, TreeNavResult}, diagnostics::{Diagnostics}, - make_editor::make_editor, product::ProductEditor, sum::SumEditor, Nested @@ -227,11 +226,9 @@ impl TerminalEditor for Commander { match event { TerminalEvent::Input(Event::Key(Key::Char('\n'))) => { let mut c = cmd_editor.write().unwrap(); - if let TerminalEditorResult::Exit = c.handle_terminal_event(&TerminalEvent::Input(Event::Key(Key::Char('\n')))) { - + if c.nexd() == TreeNavResult::Exit { // run c.goto(TreeCursor::none()); - c.up(); TerminalEditorResult::Exit } else { diff --git a/shell/src/main.rs b/shell/src/main.rs index c380af0..2c9a3bc 100644 --- a/shell/src/main.rs +++ b/shell/src/main.rs @@ -25,6 +25,9 @@ use { tree::{TreeNav, TreeCursor, TreeNavResult}, vec::VecBuffer, integer::{PosIntEditor}, + char_editor::CharEditor, + product::ProductEditor, + sum::SumEditor, diagnostics::{Diagnostics}, Nested }, @@ -50,15 +53,9 @@ async fn main() { }); // Type Context // - let mut ctx = Arc::new(RwLock::new(Context::new())); - for tn in vec![ - "MachineWord", "MachineInt", "MachineSyllab", "Bits", - "Vec", "Stream", "Json", - "Sequence", "AsciiString", "UTF-8-String", "Char", "String", "Symbol", - "PosInt", "Digit", "LittleEndian", "BigEndian", - "DiffStream", "ℕ", "List", "Path", "Term", "RGB", "Vec3i" - ] { ctx.write().unwrap().add_typename(tn.into()); } - + let ctx = nested::make_editor::init_ctx(); + + let c = ctx.clone(); let mut process_list_editor = PTYListEditor::new( Box::new( move || { @@ -215,7 +212,7 @@ async fn main() { } let ev = term.next_event().await; - + if let TerminalEvent::Resize(new_size) = ev { cur_size.set(new_size); term_port.inner().get_broadcast().notify(&IndexArea::Full); @@ -292,3 +289,4 @@ async fn main() { term_writer.show().await.expect("output error!"); } +