From 97a5b580dfd7454d87e8c699cf5c6033fa259b27 Mon Sep 17 00:00:00 2001 From: Michael Sippel Date: Thu, 4 Jan 2024 15:39:39 +0100 Subject: [PATCH] wip: deactivate code to make it compileable --- examples/tty-02-node/src/main.rs | 59 +++++++++++-------- lib-nested-core/src/edit_tree/node.rs | 3 + lib-nested-core/src/editors/char/mod.rs | 4 ++ lib-nested-core/src/editors/integer/editor.rs | 9 ++- lib-nested-core/src/editors/list/ctx.rs | 3 +- lib-nested-core/src/editors/list/editor.rs | 5 +- lib-nested-core/src/editors/mod.rs | 6 +- lib-nested-core/src/editors/sum/editor.rs | 2 +- lib-nested-core/src/editors/typeterm/ctx.rs | 2 + lib-nested-core/src/repr_tree/context.rs | 6 ++ lib-nested-core/src/repr_tree/morphism.rs | 4 +- lib-nested-tty/src/editors/list.rs | 3 + lib-nested-tty/src/editors/mod.rs | 4 +- 13 files changed, 71 insertions(+), 39 deletions(-) diff --git a/examples/tty-02-node/src/main.rs b/examples/tty-02-node/src/main.rs index 2fe3791..d041723 100644 --- a/examples/tty-02-node/src/main.rs +++ b/examples/tty-02-node/src/main.rs @@ -8,19 +8,21 @@ use { cgmath::Vector2, nested::{ editors::ObjCommander, - repr_tree::{Context}, + repr_tree::{Context, ReprTree}, + edit_tree::{NestedNode} }, nested_tty::{ DisplaySegment, TTYApplication, TerminalCompositor, TerminalStyle, TerminalView, }, r3vi::{ - buffer::singleton::*, + buffer::{singleton::*, vec::*}, }, std::sync::{Arc, RwLock}, }; -struct ParseDigit { radix: u32 }; +/* +struct ParseDigit { radix: u32 } impl Morphism for ParseDigit { fn new( ctx: &Arc> @@ -38,24 +40,25 @@ impl Morphism for ParseDigit { get_morphism( ) -> Morphism { } - +*/ #[async_std::main] async fn main() { /* setup context & create Editor-Tree */ - let ctx = Arc::new(RwLock::new(Context::default())); + let ctx = Arc::new(RwLock::new(Context::new())); /* Create a Char-Node with editor & view */ + let mut char_obj = ReprTree::make_leaf( Context::parse(&ctx, "Char"), SingletonBuffer::new('X').get_port().into() ); - +/* char_obj.insert_branch( Context::parse(&ctx, "EditTree"), SingletonBuffer::new( - + NestedNode::new() ) ); @@ -72,12 +75,14 @@ async fn main() { SingletonBuffer::new(0).get_port(), ) .unwrap(); - +*/ // add a display view to the node - node1 = nested_tty::editors::node_make_tty_view(node1); + //node1 = nested_tty::editors::node_make_tty_view(node1); /* Create a -Node with editor & view */ + +/* let mut node2 = Context::make_node( &ctx, // node type @@ -86,12 +91,13 @@ async fn main() { SingletonBuffer::new(0).get_port(), ) .unwrap(); - +*/ // add a display view to the node - node2 = nested_tty::editors::node_make_tty_view(node2); + //node2 = nested_tty::editors::node_make_tty_view(node2); /* Create a -Node with editor & view */ +/* let mut node3 = Context::make_node( &ctx, // node type @@ -100,10 +106,10 @@ async fn main() { SingletonBuffer::new(0).get_port(), ) .unwrap(); - +*/ // add a display view to the node - node3 = nested_tty::editors::node_make_tty_view(node3); - + //node3 = nested_tty::editors::node_make_tty_view(node3); + /* setup terminal */ let app = TTYApplication::new({ @@ -111,16 +117,16 @@ async fn main() { */ let ctx = ctx.clone(); - let node1 = node1.clone(); - let node2 = node2.clone(); - let node3 = node3.clone(); + // let node1 = node1.clone(); +// let node2 = node2.clone(); +// let node3 = node3.clone(); move |ev| { - let mut node1 = node1.clone(); - let mut node2 = node2.clone(); - let mut node3 = node3.clone(); - node1.send_cmd_obj(ev.to_repr_tree(&ctx)); - node2.send_cmd_obj(ev.to_repr_tree(&ctx)); - node3.send_cmd_obj(ev.to_repr_tree(&ctx)); +// let mut node1 = node1.clone(); +// let mut node2 = node2.clone(); +// let mut node3 = node3.clone(); +// node1.send_cmd_obj(ev.to_repr_tree(&ctx)); +// node2.send_cmd_obj(ev.to_repr_tree(&ctx)); +// node3.send_cmd_obj(ev.to_repr_tree(&ctx)); } }); @@ -137,7 +143,7 @@ async fn main() { .offset(Vector2::new(5, 0)), ); - let label = ctx.read().unwrap().type_term_to_str(&node1.get_type()); +/* let label = ctx.read().unwrap().type_term_to_str(&node1.get_type()); compositor .write() .unwrap() @@ -147,7 +153,8 @@ async fn main() { .write() .unwrap() .push(node1.display_view().offset(Vector2::new(15, 2))); - +*/ + /* let label2 = ctx.read().unwrap().type_term_to_str(&node2.get_type()); compositor .write() @@ -170,7 +177,7 @@ async fn main() { .write() .unwrap() .push(node3.display_view().offset(Vector2::new(25, 4))); - +*/ /* write the changes in the view of `term_port` to the terminal */ app.show().await.expect("output error!"); diff --git a/lib-nested-core/src/edit_tree/node.rs b/lib-nested-core/src/edit_tree/node.rs index b60326a..7acfa82 100644 --- a/lib-nested-core/src/edit_tree/node.rs +++ b/lib-nested-core/src/edit_tree/node.rs @@ -47,6 +47,9 @@ pub struct NestedNodeEdit { >, } +/* + * TODO: rename to EditNode + */ #[derive(Clone)] pub struct NestedNode { /// context diff --git a/lib-nested-core/src/editors/char/mod.rs b/lib-nested-core/src/editors/char/mod.rs index 8294576..40ea021 100644 --- a/lib-nested-core/src/editors/char/mod.rs +++ b/lib-nested-core/src/editors/char/mod.rs @@ -17,11 +17,13 @@ use { }; pub fn init_ctx( ctx: &mut Context ) { + /* ctx.add_node_ctor( "Char", Arc::new(|ctx: Arc>, _ty: TypeTerm, depth: OuterViewPort>| { Some(CharEditor::new_node(ctx, depth)) })); + */ } pub struct CharEditor { @@ -76,10 +78,12 @@ impl CharEditor { NestedNode::new( ctx0.clone(), + /* ReprTree::new_leaf( ctx0.read().unwrap().type_term_from_str("Char").unwrap(), data.get_port().into() ), + */ depth ) .set_cmd( editor.clone() ) diff --git a/lib-nested-core/src/editors/integer/editor.rs b/lib-nested-core/src/editors/integer/editor.rs index 67188ec..91d068d 100644 --- a/lib-nested-core/src/editors/integer/editor.rs +++ b/lib-nested-core/src/editors/integer/editor.rs @@ -89,7 +89,7 @@ impl DigitEditor { let ed = editor.write().unwrap(); let r = ed.radix; - NestedNode::new(ed.ctx.clone(), data, depth) + NestedNode::new(ed.ctx.clone(), /*data,*/ depth) .set_cmd(editor.clone()) /* .set_view( @@ -144,6 +144,7 @@ pub struct PosIntEditor { impl PosIntEditor { pub fn new(ctx: Arc>, radix: u32) -> Self { + /* let mut node = Context::make_node( &ctx, Context::parse(&ctx, format!(">", radix).as_str()), @@ -159,6 +160,7 @@ impl PosIntEditor { TypeTerm::TypeID(ctx.read().unwrap().get_typeid("BigEndian").unwrap()) ] )); + */ /* PTYListController::for_node( &mut node, Some(' '), None ); PTYListStyle::for_node( &mut node, @@ -177,7 +179,10 @@ impl PosIntEditor { */ PosIntEditor { radix, - digits: node + digits: NestedNode::new( + ctx, + r3vi::buffer::singleton::SingletonBuffer::new(0).get_port() + ) } } diff --git a/lib-nested-core/src/editors/list/ctx.rs b/lib-nested-core/src/editors/list/ctx.rs index 2eefc7f..8cb8c37 100644 --- a/lib-nested-core/src/editors/list/ctx.rs +++ b/lib-nested-core/src/editors/list/ctx.rs @@ -13,7 +13,7 @@ use { pub fn init_ctx(ctx: &mut Context) { ctx.add_typename("ListCmd".into()); ctx.add_list_typename("List".into()); - +/* ctx.add_node_ctor( "List", Arc::new( |ctx: Arc>, ty: TypeTerm, depth: OuterViewPort>| { @@ -37,5 +37,6 @@ pub fn init_ctx(ctx: &mut Context) { } ) ); + */ } diff --git a/lib-nested-core/src/editors/list/editor.rs b/lib-nested-core/src/editors/list/editor.rs index 8619012..5a971b4 100644 --- a/lib-nested-core/src/editors/list/editor.rs +++ b/lib-nested-core/src/editors/list/editor.rs @@ -307,7 +307,7 @@ impl ListEditor { self.nexd(); let mut b = item.edit.spillbuf.write().unwrap(); - +/* TODO let mut tail_node = Context::make_node(&self.ctx, self.typ.clone(), self.depth.map(|d| d+1)).unwrap(); tail_node.goto(TreeCursor::home()); @@ -322,6 +322,7 @@ impl ListEditor { ) ); } + b.clear(); drop(b); drop(item); @@ -334,7 +335,7 @@ impl ListEditor { self.insert( Arc::new(RwLock::new(tail_node)) ); - +*/ } else { self.up(); self.listlist_split(); diff --git a/lib-nested-core/src/editors/mod.rs b/lib-nested-core/src/editors/mod.rs index 669b5d8..eebac4e 100644 --- a/lib-nested-core/src/editors/mod.rs +++ b/lib-nested-core/src/editors/mod.rs @@ -1,11 +1,11 @@ pub mod list; //pub mod product; -pub mod sum; +//pub mod sum; pub mod char; -pub mod integer; -pub mod typeterm; +//pub mod integer; +//pub mod typeterm; pub trait Commander { diff --git a/lib-nested-core/src/editors/sum/editor.rs b/lib-nested-core/src/editors/sum/editor.rs index aa71f01..b995da5 100644 --- a/lib-nested-core/src/editors/sum/editor.rs +++ b/lib-nested-core/src/editors/sum/editor.rs @@ -55,7 +55,7 @@ impl SumEditor { NestedNode::new( ctx.clone(), - ReprTree::new_arc(TypeTerm::TypeID(ctx.read().unwrap().get_typeid("Sum").unwrap())), +// ReprTree::new_arc(TypeTerm::TypeID(ctx.read().unwrap().get_typeid("Sum").unwrap())), r3vi::buffer::singleton::SingletonBuffer::new(0).get_port() ) // .set_view(view) diff --git a/lib-nested-core/src/editors/typeterm/ctx.rs b/lib-nested-core/src/editors/typeterm/ctx.rs index 984bb19..00d851e 100644 --- a/lib-nested-core/src/editors/typeterm/ctx.rs +++ b/lib-nested-core/src/editors/typeterm/ctx.rs @@ -25,6 +25,7 @@ pub fn init_ctx(ctx: &mut Context) { ctx.add_list_typename("Type::App".into()); // = ctx.add_list_typename("Type::Ladder".into()); // = T1~T2~... +/* ctx.add_morphism( MorphismType { src_tyid: Context::parse(&ctx, ""), dst_tyid: Context::parse(&ctx, "Type") }, Arc::new(move |node, _dst_type:_| { @@ -34,6 +35,7 @@ pub fn init_ctx(ctx: &mut Context) { let new_node = TypeTermEditor::with_node( ctx, node.clone(), State::Any ); Some(new_node) })); + */ /* ctx.add_morphism( MorphismTypePattern { src_tyid: ctx.get_typeid("List"), dst_tyid: ctx.get_typeid("Type::Ladder").unwrap() }, diff --git a/lib-nested-core/src/repr_tree/context.rs b/lib-nested-core/src/repr_tree/context.rs index 264e3cc..dbdd92a 100644 --- a/lib-nested-core/src/repr_tree/context.rs +++ b/lib-nested-core/src/repr_tree/context.rs @@ -66,6 +66,12 @@ impl Context { } } + pub fn make_repr(ctx: &Arc>, t: &TypeTerm) -> Arc> { + let rt = Arc::new(RwLock::new(ReprTree::new( TypeTerm::unit() ))); + ctx.read().unwrap().morphisms.morph( rt.clone(), t ); + rt + } + pub fn parse(ctx: &Arc>, s: &str) -> TypeTerm { ctx.read().unwrap().type_term_from_str(s).expect("could not parse type term") } diff --git a/lib-nested-core/src/repr_tree/morphism.rs b/lib-nested-core/src/repr_tree/morphism.rs index cc08e05..2cb58cc 100644 --- a/lib-nested-core/src/repr_tree/morphism.rs +++ b/lib-nested-core/src/repr_tree/morphism.rs @@ -43,7 +43,7 @@ impl MorphismBase { pub fn add_morphism( &mut self, morph_type: MorphismType, - repr_tree_op: impl Fn( Arc>, &HashMap ) + Send + Sync + repr_tree_op: impl Fn( Arc>, &HashMap ) + Send + Sync + 'static ) { self.morphisms.push( GenericReprTreeMorphism { @@ -82,7 +82,7 @@ impl MorphismBase { target_type: &TypeTerm ) { if let Some((m, σ)) = self.find_morphism( repr_tree.read().unwrap().get_type(), target_type ) { - (m.repr_tree_op)( repr_tree, &σ ); + (m.repr_tree_op)( repr_tree.clone(), &σ ); } else { eprintln!("could not find morphism"); } diff --git a/lib-nested-tty/src/editors/list.rs b/lib-nested-tty/src/editors/list.rs index fb3f9a4..9b0cdd9 100644 --- a/lib-nested-tty/src/editors/list.rs +++ b/lib-nested-tty/src/editors/list.rs @@ -219,6 +219,7 @@ impl PTYListController { match cur.mode { ListCursorMode::Insert => { + /* TODO let mut new_edit = Context::make_node(&e.ctx, e.typ.clone(), self.depth.map(|d| d+1)).unwrap(); new_edit.goto(TreeCursor::home()); @@ -231,6 +232,8 @@ impl PTYListController { TreeNavResult::Exit } } + */ + 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 dfc07ee..3d2a7b4 100644 --- a/lib-nested-tty/src/editors/mod.rs +++ b/lib-nested-tty/src/editors/mod.rs @@ -16,7 +16,7 @@ use { atom::TerminalAtom } }; - +/* pub fn node_make_char_view( node: NestedNode ) -> NestedNode { @@ -81,4 +81,4 @@ pub fn node_make_tty_view( node } } - +*/