From 84b2a6e66dbe1d75df29f8d5f706d4d93c90db74 Mon Sep 17 00:00:00 2001 From: Michael Sippel Date: Wed, 6 Sep 2023 05:50:48 +0200 Subject: [PATCH] colors by depth; still has some bugs with typeterm morphings --- nested/src/editors/list/editor.rs | 2 +- nested/src/editors/list/pty_editor.rs | 2 +- nested/src/editors/typeterm/mod.rs | 31 ++++++++++++++++----------- nested/src/type_system/context.rs | 2 +- nested/src/utils/color.rs | 13 ++++++----- 5 files changed, 27 insertions(+), 23 deletions(-) diff --git a/nested/src/editors/list/editor.rs b/nested/src/editors/list/editor.rs index a269ee2..0c6f755 100644 --- a/nested/src/editors/list/editor.rs +++ b/nested/src/editors/list/editor.rs @@ -281,7 +281,7 @@ impl ListEditor { self.nexd(); let mut b = item.spillbuf.write().unwrap(); - let mut tail_node = Context::make_node(&self.ctx, self.typ.clone(), 0).unwrap(); + let mut tail_node = Context::make_node(&self.ctx, self.typ.clone(), item.depth.get()).unwrap(); tail_node.goto(TreeCursor::home()); for node in b.iter() { diff --git a/nested/src/editors/list/pty_editor.rs b/nested/src/editors/list/pty_editor.rs index e3524a0..bc5dc8a 100644 --- a/nested/src/editors/list/pty_editor.rs +++ b/nested/src/editors/list/pty_editor.rs @@ -176,7 +176,7 @@ impl PTYListController { match cur.mode { ListCursorMode::Insert => { - let mut new_edit = Context::make_node(&e.ctx, e.typ.clone(), self.depth).unwrap(); + let mut new_edit = Context::make_node(&e.ctx, e.typ.clone(), self.depth+1).unwrap(); new_edit.goto(TreeCursor::home()); match new_edit.send_cmd_obj(cmd_obj.clone()) { diff --git a/nested/src/editors/typeterm/mod.rs b/nested/src/editors/typeterm/mod.rs index 6bc6675..2e260de 100644 --- a/nested/src/editors/typeterm/mod.rs +++ b/nested/src/editors/typeterm/mod.rs @@ -39,6 +39,8 @@ pub struct TypeTermEditor { close_char: SingletonBuffer>, spillbuf: Arc>>>>, + depth: usize, + // editing/parsing state state: State, @@ -134,28 +136,28 @@ impl TypeTermEditor { let mut node = match new_state { State::Any => { - Context::make_node( &self.ctx, (&self.ctx, "( List Char )").into(), 0 ).unwrap() + Context::make_node( &self.ctx, (&self.ctx, "( List Char )").into(), self.depth ).unwrap() .morph( (&self.ctx, "( Type::Sym )").into() ) } State::App => { - Context::make_node( &self.ctx, (&self.ctx, "( List Type )").into(), 0 ).unwrap() + Context::make_node( &self.ctx, (&self.ctx, "( List Type )").into(), self.depth ).unwrap() .morph( (&self.ctx, "( Type::App )").into() ) } State::Ladder => { - Context::make_node( &self.ctx, (&self.ctx, "( List Type )").into(), 0 ).unwrap() + Context::make_node( &self.ctx, (&self.ctx, "( List Type )").into(), self.depth ).unwrap() .morph( (&self.ctx, "( Type::Ladder )").into() ) } State::AnySymbol => { - Context::make_node( &self.ctx, (&self.ctx, "( List Char )").into(), 0 ).unwrap() + Context::make_node( &self.ctx, (&self.ctx, "( List Char )").into(), self.depth ).unwrap() .morph( (&self.ctx, "( Type::Sym )").into() ) }, State::FunSymbol => { - Context::make_node( &self.ctx, (&self.ctx, "( List Char )").into(), 0 ).unwrap() + Context::make_node( &self.ctx, (&self.ctx, "( List Char )").into(), self.depth ).unwrap() .morph( (&self.ctx, "( Type::Sym::Fun )").into() ) }, State::VarSymbol => { - Context::make_node( &self.ctx, (&self.ctx, "( List Char )").into(), 0 ).unwrap() + Context::make_node( &self.ctx, (&self.ctx, "( List Char )").into(), self.depth ).unwrap() .morph( (&self.ctx, "( Type::Sym::Var )").into() ) } State::Num => { @@ -164,7 +166,7 @@ impl TypeTermEditor { .morph( (&self.ctx, "( Type::Lit::Num )").into() ) } State::Char => { - Context::make_node( &self.ctx, (&self.ctx, "( Char )").into(), 0 ).unwrap() + Context::make_node( &self.ctx, (&self.ctx, "( Char )").into(), self.depth ).unwrap() .morph( (&self.ctx, "( Type::Lit::Char )").into() ) } _ => { @@ -184,7 +186,7 @@ impl TypeTermEditor { let ctx : Arc> = Arc::new(RwLock::new(Context::with_parent(Some(ctx)))); ctx.write().unwrap().meta_chars.push('~'); - let mut symb_node = Context::make_node( &ctx, (&ctx, "( List Char )").into(), 0 ).unwrap(); + let mut symb_node = Context::make_node( &ctx, (&ctx, "( List Char )").into(), depth ).unwrap(); symb_node = symb_node.morph( (&ctx, "( Type::Sym )").into() ); Self::with_node( @@ -208,7 +210,8 @@ impl TypeTermEditor { state, cur_node: SingletonBuffer::new(node), close_char: SingletonBuffer::new(None), - spillbuf: Arc::new(RwLock::new(Vec::new())) + spillbuf: Arc::new(RwLock::new(Vec::new())), + depth }; let view = editor.cur_node @@ -399,12 +402,12 @@ impl TypeTermEditor { drop(item_typterm); // else create new ladder - let mut list_node = Context::make_node( &self.ctx, (&self.ctx, "( List Type )").into(), 0 ).unwrap(); + let mut list_node = Context::make_node( &self.ctx, (&self.ctx, "( List Type )").into(), self.depth ).unwrap(); list_node = list_node.morph( (&self.ctx, "( Type::Ladder )").into() ); let mut new_node = TypeTermEditor::with_node( self.ctx.clone(), - 0, + self.depth, list_node, State::Ladder ); @@ -433,10 +436,12 @@ impl TypeTermEditor { eprintln!("morph into ladder"); let old_node = self.cur_node.get().clone(); + *old_node.depth.get_mut() += 1; + /* create a new NestedNode with TerminaltypeEditor, * that has same state & child-node as current node. */ - let mut old_edit_node = TypeTermEditor::new_node( self.ctx.clone(), 0 ); + let mut old_edit_node = TypeTermEditor::new_node( self.ctx.clone(), self.depth ); let mut old_edit_clone = old_edit_node.get_edit::().unwrap(); old_edit_clone.write().unwrap().set_state( self.state ); old_edit_clone.write().unwrap().close_char.set( old_node.close_char.get() ); @@ -444,7 +449,7 @@ impl TypeTermEditor { /* create new list-edit node for the ladder */ - let mut new_node = Context::make_node( &self.ctx, (&self.ctx, "( List Type )").into(), 0 ).unwrap(); + let mut new_node = Context::make_node( &self.ctx, (&self.ctx, "( List Type )").into(), self.depth ).unwrap(); new_node = new_node.morph( (&self.ctx, "( Type::Ladder )").into() ); /* reconfigure current node to display new_node list-editor diff --git a/nested/src/type_system/context.rs b/nested/src/type_system/context.rs index c6a6df6..7e57eb9 100644 --- a/nested/src/type_system/context.rs +++ b/nested/src/type_system/context.rs @@ -287,7 +287,7 @@ impl Context { let _new_depth = depth; mk_node( - NestedNode::new(new_ctx, ReprTree::new_arc(type_term.clone()), 0), + NestedNode::new(new_ctx, ReprTree::new_arc(type_term.clone()), depth), type_term ) } diff --git a/nested/src/utils/color.rs b/nested/src/utils/color.rs index bb43622..25772ee 100644 --- a/nested/src/utils/color.rs +++ b/nested/src/utils/color.rs @@ -16,13 +16,12 @@ pub fn bg_style_from_depth(depth: usize) -> TerminalStyle { pub fn fg_style_from_depth(depth: usize) -> TerminalStyle { match depth % 6 { - 0 => TerminalStyle::fg_color((180, 180, 180)), - 1 => TerminalStyle::fg_color((120, 120, 120)), - 2 => TerminalStyle::fg_color((250, 165, 40)), - 3 => TerminalStyle::fg_color((80, 180, 200)), - 4 => TerminalStyle::fg_color((180, 240, 85)), - 5 => TerminalStyle::fg_color((200, 190, 70)), + 0 => TerminalStyle::fg_color((120, 120, 0)), + 1 => TerminalStyle::fg_color((250, 165, 40)), + 2 => TerminalStyle::fg_color((80, 180, 180)), + 3 => TerminalStyle::fg_color((180, 240, 85)), + 4 => TerminalStyle::fg_color((200, 190, 70)), _ => TerminalStyle::default() - } + } }