From 4bf03c356db5517a4132dc2439d7512bc3183eb5 Mon Sep 17 00:00:00 2001 From: Michael Sippel Date: Fri, 24 Nov 2023 21:26:17 +0100 Subject: [PATCH] wip refactor crates --- Cargo.toml | 10 +- {nested => lib-nested-core}/Cargo.toml | 10 +- .../src/editors/char/mod.rs | 16 +- .../src/editors/integer/add.rs | 0 .../src/editors/integer/ctx.rs | 3 +- .../src/editors/integer/editor.rs | 19 +- .../src/editors/integer/mod.rs | 0 .../src/editors/integer/radix.rs | 0 .../src/editors/list/cmd.rs | 3 +- .../src/editors/list/ctx.rs | 6 +- .../src/editors/list/cursor.rs | 0 .../src/editors/list/editor.rs | 8 +- .../src/editors/list/mod.rs | 3 - .../src/editors/list/nav.rs | 0 .../src/editors/list/segment.rs | 38 +- .../src/editors/mod.rs | 9 + .../src/editors/product/editor.rs | 4 - .../src/editors/product/mod.rs | 0 .../src/editors/product/nav.rs | 0 .../src/editors/product/segment.rs | 0 .../src/editors/sum/editor.rs | 27 +- .../src/editors/sum/mod.rs | 0 .../src/editors/typeterm/cmd.rs | 3 +- .../src/editors/typeterm/ctx.rs | 9 +- .../src/editors/typeterm/mod.rs | 8 +- .../src/editors/typeterm/nav.rs | 0 lib-nested-core/src/lib.rs | 8 + {nested => lib-nested-core}/src/tree/addr.rs | 0 .../src/tree/cursor.rs | 0 lib-nested-core/src/tree/diagnostics.rs | 24 ++ {nested => lib-nested-core}/src/tree/mod.rs | 1 + {nested => lib-nested-core}/src/tree/nav.rs | 32 +- {nested => lib-nested-core}/src/tree/node.rs | 38 +- .../src/tree/treetype.rs | 0 .../src/type_system/context.rs | 0 .../src/type_system/mod.rs | 0 .../src/type_system/repr_tree.rs | 8 + .../src/utils/bimap.rs | 0 {nested => lib-nested-core}/src/utils/mod.rs | 1 - .../src/utils/modulo.rs | 0 .../ansi_parser => lib-nested-tty}/Cargo.toml | 15 +- .../src}/ansi_parser.rs | 2 +- .../terminal => lib-nested-tty/src}/atom.rs | 0 .../src/utils => lib-nested-tty/src}/color.rs | 0 .../src}/compositor.rs | 2 +- lib-nested-tty/src/cursor_widget.rs | 33 ++ {nested => lib-nested-tty}/src/diagnostics.rs | 24 -- .../mod.rs => lib-nested-tty/src/lib.rs | 31 +- .../src/list_editor.rs | 41 ++- .../terminal => lib-nested-tty/src}/style.rs | 0 lib-nested-tty/src/sum_editor.rs | 8 + .../src}/terminal.rs | 0 .../src}/widgets/ascii_box.rs | 0 .../src}/widgets/mod.rs | 0 .../src}/widgets/monstera.rs | 0 .../src}/widgets/plot.rs | 0 math/fib/Cargo.toml | 9 - math/fib/src/main.rs | 62 ---- math/int2str/Cargo.toml | 9 - math/int2str/src/main.rs | 36 -- math/radix_transform/Cargo.toml | 13 - math/radix_transform/src/main.rs | 137 -------- math/str2int/Cargo.toml | 9 - math/str2int/src/main.rs | 69 ---- nested/src/editors/mod.rs | 9 - nested/src/lib.rs | 34 -- terminal/ansi_parser/src/main.rs | 331 ------------------ terminal/display_server/Cargo.toml | 12 - terminal/display_server/src/main.rs | 67 ---- 69 files changed, 238 insertions(+), 1003 deletions(-) rename {nested => lib-nested-core}/Cargo.toml (69%) rename {nested => lib-nested-core}/src/editors/char/mod.rs (91%) rename {nested => lib-nested-core}/src/editors/integer/add.rs (100%) rename {nested => lib-nested-core}/src/editors/integer/ctx.rs (99%) rename {nested => lib-nested-core}/src/editors/integer/editor.rs (96%) rename {nested => lib-nested-core}/src/editors/integer/mod.rs (100%) rename {nested => lib-nested-core}/src/editors/integer/radix.rs (100%) rename {nested => lib-nested-core}/src/editors/list/cmd.rs (98%) rename {nested => lib-nested-core}/src/editors/list/ctx.rs (80%) rename {nested => lib-nested-core}/src/editors/list/cursor.rs (100%) rename {nested => lib-nested-core}/src/editors/list/editor.rs (98%) rename {nested => lib-nested-core}/src/editors/list/mod.rs (77%) rename {nested => lib-nested-core}/src/editors/list/nav.rs (100%) rename {nested => lib-nested-core}/src/editors/list/segment.rs (74%) rename nested/src/commander.rs => lib-nested-core/src/editors/mod.rs (75%) rename {nested => lib-nested-core}/src/editors/product/editor.rs (98%) rename {nested => lib-nested-core}/src/editors/product/mod.rs (100%) rename {nested => lib-nested-core}/src/editors/product/nav.rs (100%) rename {nested => lib-nested-core}/src/editors/product/segment.rs (100%) rename {nested => lib-nested-core}/src/editors/sum/editor.rs (87%) rename {nested => lib-nested-core}/src/editors/sum/mod.rs (100%) rename {nested => lib-nested-core}/src/editors/typeterm/cmd.rs (99%) rename {nested => lib-nested-core}/src/editors/typeterm/ctx.rs (97%) rename {nested => lib-nested-core}/src/editors/typeterm/mod.rs (99%) rename {nested => lib-nested-core}/src/editors/typeterm/nav.rs (100%) create mode 100644 lib-nested-core/src/lib.rs rename {nested => lib-nested-core}/src/tree/addr.rs (100%) rename {nested => lib-nested-core}/src/tree/cursor.rs (100%) create mode 100644 lib-nested-core/src/tree/diagnostics.rs rename {nested => lib-nested-core}/src/tree/mod.rs (91%) rename {nested => lib-nested-core}/src/tree/nav.rs (74%) rename {nested => lib-nested-core}/src/tree/node.rs (91%) rename {nested => lib-nested-core}/src/tree/treetype.rs (100%) rename {nested => lib-nested-core}/src/type_system/context.rs (100%) rename {nested => lib-nested-core}/src/type_system/mod.rs (100%) rename {nested => lib-nested-core}/src/type_system/repr_tree.rs (96%) rename {nested => lib-nested-core}/src/utils/bimap.rs (100%) rename {nested => lib-nested-core}/src/utils/mod.rs (83%) rename {nested => lib-nested-core}/src/utils/modulo.rs (100%) rename {terminal/ansi_parser => lib-nested-tty}/Cargo.toml (51%) rename {nested/src/terminal => lib-nested-tty/src}/ansi_parser.rs (99%) rename {nested/src/terminal => lib-nested-tty/src}/atom.rs (100%) rename {nested/src/utils => lib-nested-tty/src}/color.rs (100%) rename {nested/src/terminal => lib-nested-tty/src}/compositor.rs (97%) create mode 100644 lib-nested-tty/src/cursor_widget.rs rename {nested => lib-nested-tty}/src/diagnostics.rs (82%) rename nested/src/terminal/mod.rs => lib-nested-tty/src/lib.rs (82%) rename nested/src/editors/list/pty_editor.rs => lib-nested-tty/src/list_editor.rs (85%) rename {nested/src/terminal => lib-nested-tty/src}/style.rs (100%) create mode 100644 lib-nested-tty/src/sum_editor.rs rename {nested/src/terminal => lib-nested-tty/src}/terminal.rs (100%) rename {nested/src/terminal => lib-nested-tty/src}/widgets/ascii_box.rs (100%) rename {nested/src/terminal => lib-nested-tty/src}/widgets/mod.rs (100%) rename {nested/src/terminal => lib-nested-tty/src}/widgets/monstera.rs (100%) rename {nested/src/terminal => lib-nested-tty/src}/widgets/plot.rs (100%) delete mode 100644 math/fib/Cargo.toml delete mode 100644 math/fib/src/main.rs delete mode 100644 math/int2str/Cargo.toml delete mode 100644 math/int2str/src/main.rs delete mode 100644 math/radix_transform/Cargo.toml delete mode 100644 math/radix_transform/src/main.rs delete mode 100644 math/str2int/Cargo.toml delete mode 100644 math/str2int/src/main.rs delete mode 100644 nested/src/editors/mod.rs delete mode 100644 nested/src/lib.rs delete mode 100644 terminal/ansi_parser/src/main.rs delete mode 100644 terminal/display_server/Cargo.toml delete mode 100644 terminal/display_server/src/main.rs diff --git a/Cargo.toml b/Cargo.toml index 641b295..26d3208 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,10 +1,6 @@ [workspace] members = [ - "nested", -# "terminal/display_server", -# "terminal/ansi_parser", -# "math/str2int", -# "math/int2str", -# "math/radix_transform", -# "math/fib" + "lib-nested-core", + "lib-nested-tty" ] + diff --git a/nested/Cargo.toml b/lib-nested-core/Cargo.toml similarity index 69% rename from nested/Cargo.toml rename to lib-nested-core/Cargo.toml index 8814165..984b580 100644 --- a/nested/Cargo.toml +++ b/lib-nested-core/Cargo.toml @@ -10,15 +10,7 @@ r3vi = { path = "../../lib-r3vi" } laddertypes = { path = "../../lib-laddertypes" } no_deadlocks = "*" cgmath = { version = "0.18.0", features = ["serde"] } -termion = "2.0.1" -vte = "0.10.1" -ansi_colours = "1.0" -signal-hook = "0.3.1" -signal-hook-async-std = "0.2.0" + serde = { version = "1.0", features = ["derive"] } bincode = "1.3.3" serde_json = "*" - -[dependencies.async-std] -version = "1.9.0" -features = ["unstable", "attributes"] diff --git a/nested/src/editors/char/mod.rs b/lib-nested-core/src/editors/char/mod.rs similarity index 91% rename from nested/src/editors/char/mod.rs rename to lib-nested-core/src/editors/char/mod.rs index 2521cb1..a42dcf3 100644 --- a/nested/src/editors/char/mod.rs +++ b/lib-nested-core/src/editors/char/mod.rs @@ -9,9 +9,8 @@ use { laddertypes::{TypeTerm}, crate::{ type_system::{Context, ReprTree}, - terminal::{TerminalAtom}, tree::{NestedNode, TreeNavResult}, - commander::{ObjCommander} + editors::ObjCommander, }, std::sync::Arc, std::sync::RwLock @@ -49,7 +48,7 @@ impl ObjCommander for CharEditor { TreeNavResult::Exit } } else { - TreeNavResult::Exit + TreeNavResult::Exit } } } @@ -83,20 +82,15 @@ impl CharEditor { ), depth ) + /* todo: move to lib-nested-term .set_view(data .get_port() .map(move |c| TerminalAtom::from(if c == '\0' { ' ' } else { c })) .to_grid() ) + */ .set_cmd( editor.clone() ) .set_editor( editor.clone() ) } } -/* -use crate::StringGen; -impl StringGen for CharEditor { - fn get_string(&self) -> String { - String::from(self.get()) - } -} -*/ + diff --git a/nested/src/editors/integer/add.rs b/lib-nested-core/src/editors/integer/add.rs similarity index 100% rename from nested/src/editors/integer/add.rs rename to lib-nested-core/src/editors/integer/add.rs diff --git a/nested/src/editors/integer/ctx.rs b/lib-nested-core/src/editors/integer/ctx.rs similarity index 99% rename from nested/src/editors/integer/ctx.rs rename to lib-nested-core/src/editors/integer/ctx.rs index 99c9aa7..95b138d 100644 --- a/nested/src/editors/integer/ctx.rs +++ b/lib-nested-core/src/editors/integer/ctx.rs @@ -62,6 +62,7 @@ pub fn init_ctx(ctx: &mut Context) { if args.len() > 1 { match args[1] { TypeTerm::Num(_radix) => { + /* FIXME PTYListController::for_node( &mut node, Some(','), @@ -72,7 +73,7 @@ pub fn init_ctx(ctx: &mut Context) { &mut node, ("0d", "", "") ); - +*/ Some(node) }, _ => None diff --git a/nested/src/editors/integer/editor.rs b/lib-nested-core/src/editors/integer/editor.rs similarity index 96% rename from nested/src/editors/integer/editor.rs rename to lib-nested-core/src/editors/integer/editor.rs index 3e11b34..73bd353 100644 --- a/nested/src/editors/integer/editor.rs +++ b/lib-nested-core/src/editors/integer/editor.rs @@ -13,13 +13,8 @@ use { laddertypes::{TypeTerm}, crate::{ type_system::{Context, ReprTree}, - editors::list::{ListCmd, PTYListController, PTYListStyle}, - terminal::{ - TerminalAtom, TerminalStyle, make_label - }, - diagnostics::{Message}, - tree::{NestedNode, TreeNav, TreeNavResult, TreeCursor}, - commander::ObjCommander + editors::{list::{ListCmd}, ObjCommander}, + tree::{NestedNode, TreeNav, TreeNavResult, TreeCursor, diagnostics::{Message}}, }, std::sync::Arc, std::sync::RwLock, @@ -56,6 +51,8 @@ impl ObjCommander for DigitEditor { add a message to the diagnostics view */ +/* + let message = IndexBuffer::from_iter(vec![ (Point2::new(1, 0), make_label("invalid digit '")), (Point2::new(2, 0), make_label(&format!("{}", c)) @@ -64,6 +61,8 @@ impl ObjCommander for DigitEditor { ]); self.msg.push(crate::diagnostics::make_error(message.get_port().flatten())); +*/ + self.data.set(Some(c)); } else { self.data.set(Some(c)); @@ -93,6 +92,7 @@ impl DigitEditor { NestedNode::new(ed.ctx.clone(), data, depth) .set_cmd(editor.clone()) + /* .set_view( ed.data .get_port() @@ -112,6 +112,7 @@ impl DigitEditor { .set_diag( ed.msg.get_port().to_sequence() ) + */ } pub fn get_data_port(&self) -> OuterViewPort>> { @@ -159,7 +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, ( @@ -174,7 +175,7 @@ impl PosIntEditor { "".into() ) ); - +*/ PosIntEditor { radix, digits: node diff --git a/nested/src/editors/integer/mod.rs b/lib-nested-core/src/editors/integer/mod.rs similarity index 100% rename from nested/src/editors/integer/mod.rs rename to lib-nested-core/src/editors/integer/mod.rs diff --git a/nested/src/editors/integer/radix.rs b/lib-nested-core/src/editors/integer/radix.rs similarity index 100% rename from nested/src/editors/integer/radix.rs rename to lib-nested-core/src/editors/integer/radix.rs diff --git a/nested/src/editors/list/cmd.rs b/lib-nested-core/src/editors/list/cmd.rs similarity index 98% rename from nested/src/editors/list/cmd.rs rename to lib-nested-core/src/editors/list/cmd.rs index 74c7fee..ffcb9f1 100644 --- a/nested/src/editors/list/cmd.rs +++ b/lib-nested-core/src/editors/list/cmd.rs @@ -3,10 +3,9 @@ use { view::{singleton::*} }, crate::{ - editors::list::{ListEditor, ListCursor, ListCursorMode}, + editors::{list::{ListEditor, ListCursor, ListCursorMode}, ObjCommander}, type_system::{Context, ReprTree}, tree::{NestedNode, TreeNav, TreeNavResult, TreeCursor}, - commander::{ObjCommander} }, std::sync::{Arc, RwLock} }; diff --git a/nested/src/editors/list/ctx.rs b/lib-nested-core/src/editors/list/ctx.rs similarity index 80% rename from nested/src/editors/list/ctx.rs rename to lib-nested-core/src/editors/list/ctx.rs index 91474f0..89376b7 100644 --- a/nested/src/editors/list/ctx.rs +++ b/lib-nested-core/src/editors/list/ctx.rs @@ -3,7 +3,7 @@ use { laddertypes::{TypeTerm}, crate::{ type_system::{Context}, - editors::list::{ListEditor, PTYListController, PTYListStyle} + editors::list::{ListEditor}//, PTYListController, PTYListStyle} }, std::sync::{Arc, RwLock} }; @@ -24,8 +24,8 @@ pub fn init_ctx(ctx: &mut Context) { let mut node = ListEditor::new(ctx.clone(), typ).into_node(depth); - PTYListController::for_node( &mut node, Some(','), Some('}') ); - PTYListStyle::for_node( &mut node, ("{",", ","}") ); +// PTYListController::for_node( &mut node, Some(','), Some('}') ); +// PTYListStyle::for_node( &mut node, ("{",", ","}") ); Some(node) } else { diff --git a/nested/src/editors/list/cursor.rs b/lib-nested-core/src/editors/list/cursor.rs similarity index 100% rename from nested/src/editors/list/cursor.rs rename to lib-nested-core/src/editors/list/cursor.rs diff --git a/nested/src/editors/list/editor.rs b/lib-nested-core/src/editors/list/editor.rs similarity index 98% rename from nested/src/editors/list/editor.rs rename to lib-nested-core/src/editors/list/editor.rs index 31c1f1b..63b4644 100644 --- a/nested/src/editors/list/editor.rs +++ b/lib-nested-core/src/editors/list/editor.rs @@ -1,15 +1,13 @@ use { r3vi::{ - view::{ViewPort, OuterViewPort, singleton::*, sequence::*}, + view::{OuterViewPort, singleton::*, sequence::*}, buffer::{singleton::*, vec::*} }, laddertypes::{TypeTerm}, crate::{ type_system::{Context, ReprTree}, - editors::list::{ListCursor, ListCursorMode, ListCmd}, - tree::{NestedNode, TreeNav, TreeCursor}, - diagnostics::Diagnostics, - commander::ObjCommander + editors::{list::{ListCursor, ListCursorMode, ListCmd}, ObjCommander}, + tree::{NestedNode, TreeNav, TreeCursor, diagnostics::Diagnostics}, }, std::sync::{Arc, RwLock} }; diff --git a/nested/src/editors/list/mod.rs b/lib-nested-core/src/editors/list/mod.rs similarity index 77% rename from nested/src/editors/list/mod.rs rename to lib-nested-core/src/editors/list/mod.rs index c929369..b788aae 100644 --- a/nested/src/editors/list/mod.rs +++ b/lib-nested-core/src/editors/list/mod.rs @@ -1,10 +1,8 @@ - pub mod cursor; pub mod editor; pub mod nav; pub mod segment; -pub mod pty_editor; pub mod cmd; pub mod ctx; @@ -12,7 +10,6 @@ pub use { cursor::{ListCursor, ListCursorMode}, editor::ListEditor, segment::{ListSegment, ListSegmentSequence}, - pty_editor::{PTYListStyle, PTYListController}, cmd::ListCmd, ctx::init_ctx }; diff --git a/nested/src/editors/list/nav.rs b/lib-nested-core/src/editors/list/nav.rs similarity index 100% rename from nested/src/editors/list/nav.rs rename to lib-nested-core/src/editors/list/nav.rs diff --git a/nested/src/editors/list/segment.rs b/lib-nested-core/src/editors/list/segment.rs similarity index 74% rename from nested/src/editors/list/segment.rs rename to lib-nested-core/src/editors/list/segment.rs index 4ae0368..5e8b611 100644 --- a/nested/src/editors/list/segment.rs +++ b/lib-nested-core/src/editors/list/segment.rs @@ -9,10 +9,7 @@ use { }, crate::{ editors::list::{ListCursor, ListCursorMode}, - terminal::{TerminalView, TerminalStyle, make_label}, - tree::{NestedNode, TreeNav}, - utils::color::{bg_style_from_depth, fg_style_from_depth}, - PtySegment + tree::{NestedNode} }, std::sync::Arc, std::sync::RwLock, @@ -26,39 +23,6 @@ pub enum ListSegment { } } -impl PtySegment for ListSegment { - fn pty_view(&self) -> OuterViewPort { - match self { - ListSegment::InsertCursor => { - make_label("|") - .map_item(move |_pt, atom| { - atom.add_style_front(TerminalStyle::fg_color((150,80,230))) - .add_style_front(TerminalStyle::bold(true)) - }) - } - ListSegment::Item{ editor, cur_dist } => { - let e = editor.clone(); - let cur_dist = *cur_dist; - editor.get_view().map_item(move |_pt, atom| { - let c = e.get_cursor(); - let cur_depth = c.tree_addr.len(); - let select = - if cur_dist == 0 { - cur_depth - } else { - usize::MAX - }; - - atom - .add_style_back(bg_style_from_depth(select)) - .add_style_back(TerminalStyle::bold(select==1)) - .add_style_back(fg_style_from_depth(e.depth.get_view().get())) - }) - } - } - } -} - pub struct ListSegmentSequence { data: Arc>, cursor: Arc>, diff --git a/nested/src/commander.rs b/lib-nested-core/src/editors/mod.rs similarity index 75% rename from nested/src/commander.rs rename to lib-nested-core/src/editors/mod.rs index fdbeaee..d48a5b3 100644 --- a/nested/src/commander.rs +++ b/lib-nested-core/src/editors/mod.rs @@ -1,4 +1,13 @@ +pub mod list; +//pub mod product; +pub mod sum; + +pub mod char; +pub mod integer; +pub mod typeterm; + + pub trait Commander { type Cmd; diff --git a/nested/src/editors/product/editor.rs b/lib-nested-core/src/editors/product/editor.rs similarity index 98% rename from nested/src/editors/product/editor.rs rename to lib-nested-core/src/editors/product/editor.rs index d3bdd9a..80acc24 100644 --- a/nested/src/editors/product/editor.rs +++ b/lib-nested-core/src/editors/product/editor.rs @@ -12,10 +12,6 @@ use { laddertypes::{TypeTerm}, crate::{ type_system::{Context}, - terminal::{ - TerminalEditor, TerminalEditorResult, - TerminalEvent, TerminalView - }, editors::{ list::ListCursorMode, product::{ diff --git a/nested/src/editors/product/mod.rs b/lib-nested-core/src/editors/product/mod.rs similarity index 100% rename from nested/src/editors/product/mod.rs rename to lib-nested-core/src/editors/product/mod.rs diff --git a/nested/src/editors/product/nav.rs b/lib-nested-core/src/editors/product/nav.rs similarity index 100% rename from nested/src/editors/product/nav.rs rename to lib-nested-core/src/editors/product/nav.rs diff --git a/nested/src/editors/product/segment.rs b/lib-nested-core/src/editors/product/segment.rs similarity index 100% rename from nested/src/editors/product/segment.rs rename to lib-nested-core/src/editors/product/segment.rs diff --git a/nested/src/editors/sum/editor.rs b/lib-nested-core/src/editors/sum/editor.rs similarity index 87% rename from nested/src/editors/sum/editor.rs rename to lib-nested-core/src/editors/sum/editor.rs index 14b7798..195c6b2 100644 --- a/nested/src/editors/sum/editor.rs +++ b/lib-nested-core/src/editors/sum/editor.rs @@ -8,14 +8,9 @@ use { }, laddertypes::{TypeTerm}, crate::{ - terminal::TerminalView, - editors::list::ListCursorMode, + editors::{list::ListCursorMode, ObjCommander}, type_system::{Context, ReprTree}, - tree::{TreeNav, TreeCursor, TreeNavResult}, - diagnostics::{Diagnostics, Message}, - tree::NestedNode, - commander::{ObjCommander}, - PtySegment + tree::{TreeNav, TreeCursor, TreeNavResult, diagnostics::{Diagnostics, Message}, NestedNode}, }, cgmath::{Vector2}, std::sync::{Arc, RwLock} @@ -28,7 +23,7 @@ pub struct SumEditor { addr_port: ViewPort< dyn SequenceView >, mode_port: ViewPort< dyn SingletonView >, - port: ViewPort< dyn TerminalView >, +// port: ViewPort< dyn TerminalView >, diag_port: ViewPort< dyn SequenceView > } @@ -36,12 +31,12 @@ impl SumEditor { pub fn new( editors: Vec< NestedNode > ) -> Self { - let port = ViewPort::new(); +// let port = ViewPort::new(); SumEditor { cur: 0, editors, - port, +// port, diag_port: ViewPort::new(), @@ -55,7 +50,7 @@ impl SumEditor { } pub fn into_node(self, ctx: Arc>) -> NestedNode { - let view = self.pty_view(); +// let view = self.pty_view(); let editor = Arc::new(RwLock::new(self)); NestedNode::new( @@ -63,7 +58,7 @@ impl SumEditor { ReprTree::new_arc(TypeTerm::TypeID(ctx.read().unwrap().get_typeid("Sum").unwrap())), r3vi::buffer::singleton::SingletonBuffer::new(0).get_port() ) - .set_view(view) +// .set_view(view) .set_editor(editor.clone()) .set_cmd(editor.clone()) .set_nav(editor.clone()) @@ -76,6 +71,7 @@ impl SumEditor { pub fn select(&mut self, idx: usize) { self.cur = idx; +/* FIXME let tv = self.editors[ self.cur ].get_view(); tv.add_observer( self.port.get_cast() ); @@ -100,6 +96,7 @@ impl SumEditor { self.mode_port.update_hooks.write().unwrap().clear(); self.mode_port.add_update_hook( Arc::new(dv.0.clone()) ); self.mode_port.set_view( Some(dv.get_view_arc()) ); + */ } } @@ -129,12 +126,6 @@ impl TreeNav for SumEditor { } } -impl PtySegment for SumEditor { - fn pty_view(&self) -> OuterViewPort { - self.port.outer() - } -} - impl ObjCommander for SumEditor { fn send_cmd_obj(&mut self, obj: Arc>) -> TreeNavResult { self.editors[ self.cur ].send_cmd_obj( obj ) diff --git a/nested/src/editors/sum/mod.rs b/lib-nested-core/src/editors/sum/mod.rs similarity index 100% rename from nested/src/editors/sum/mod.rs rename to lib-nested-core/src/editors/sum/mod.rs diff --git a/nested/src/editors/typeterm/cmd.rs b/lib-nested-core/src/editors/typeterm/cmd.rs similarity index 99% rename from nested/src/editors/typeterm/cmd.rs rename to lib-nested-core/src/editors/typeterm/cmd.rs index e219cc8..29ec6cb 100644 --- a/nested/src/editors/typeterm/cmd.rs +++ b/lib-nested-core/src/editors/typeterm/cmd.rs @@ -4,9 +4,8 @@ use { }, crate::{ type_system::{Context, ReprTree}, - editors::{list::{ListEditor, ListCmd, ListCursorMode}}, + editors::{list::{ListEditor, ListCmd, ListCursorMode}, ObjCommander}, tree::{NestedNode, TreeNav, TreeNavResult, TreeCursor}, - commander::ObjCommander }, std::{sync::{Arc, RwLock}}, diff --git a/nested/src/editors/typeterm/ctx.rs b/lib-nested-core/src/editors/typeterm/ctx.rs similarity index 97% rename from nested/src/editors/typeterm/ctx.rs rename to lib-nested-core/src/editors/typeterm/ctx.rs index 4ad5b55..58a65e4 100644 --- a/nested/src/editors/typeterm/ctx.rs +++ b/lib-nested-core/src/editors/typeterm/ctx.rs @@ -5,12 +5,10 @@ use { laddertypes::{TypeTerm}, crate::{ type_system::{Context, MorphismTypePattern}, - terminal::{TerminalStyle, TerminalProjections}, editors::{ - list::{PTYListStyle, PTYListController, ListEditor, ListSegmentSequence}, + list::{ListEditor, ListSegmentSequence}, typeterm::{State, TypeTermEditor} - }, - PtySegment + } }, std::{sync::{Arc, RwLock}}, cgmath::{Point2} @@ -36,7 +34,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() }, Arc::new(|mut node, _dst_type: _| { @@ -140,5 +138,6 @@ pub fn init_ctx(ctx: &mut Context) { |ctx: Arc>, _ty: TypeTerm, depth: OuterViewPort>| { Some(TypeTermEditor::new_node(ctx, depth)) })); + */ } diff --git a/nested/src/editors/typeterm/mod.rs b/lib-nested-core/src/editors/typeterm/mod.rs similarity index 99% rename from nested/src/editors/typeterm/mod.rs rename to lib-nested-core/src/editors/typeterm/mod.rs index d15cbb4..a0c4c5c 100644 --- a/nested/src/editors/typeterm/mod.rs +++ b/lib-nested-core/src/editors/typeterm/mod.rs @@ -12,9 +12,8 @@ use { laddertypes::{TypeID, TypeTerm}, crate::{ type_system::{Context, ReprTree}, - editors::{list::{ListCursorMode, ListEditor, ListCmd}}, + editors::{list::{ListCursorMode, ListEditor, ListCmd}, ObjCommander}, tree::{NestedNode, TreeNav, TreeNavResult, TreeCursor}, - commander::ObjCommander }, std::{sync::{Arc, RwLock}} }; @@ -207,7 +206,7 @@ impl TypeTermEditor { spillbuf: Arc::new(RwLock::new(Vec::new())), depth: cur_node.depth.clone() }; - +/* FIXME let view = editor.cur_node .get_port() .map(|node| { @@ -215,11 +214,12 @@ impl TypeTermEditor { }) .to_grid() .flatten(); + */ let _cc = editor.cur_node.get().close_char; let editor = Arc::new(RwLock::new(editor)); let mut super_node = NestedNode::new(ctx, data, cur_node.depth) - .set_view(view) +// .set_view(view) .set_nav(editor.clone()) .set_cmd(editor.clone()) .set_editor(editor.clone()); diff --git a/nested/src/editors/typeterm/nav.rs b/lib-nested-core/src/editors/typeterm/nav.rs similarity index 100% rename from nested/src/editors/typeterm/nav.rs rename to lib-nested-core/src/editors/typeterm/nav.rs diff --git a/lib-nested-core/src/lib.rs b/lib-nested-core/src/lib.rs new file mode 100644 index 0000000..285710c --- /dev/null +++ b/lib-nested-core/src/lib.rs @@ -0,0 +1,8 @@ +pub mod utils; +pub mod editors; +pub mod tree; +pub mod type_system; + +pub fn magic_header() { + eprintln!("<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>>"); +} diff --git a/nested/src/tree/addr.rs b/lib-nested-core/src/tree/addr.rs similarity index 100% rename from nested/src/tree/addr.rs rename to lib-nested-core/src/tree/addr.rs diff --git a/nested/src/tree/cursor.rs b/lib-nested-core/src/tree/cursor.rs similarity index 100% rename from nested/src/tree/cursor.rs rename to lib-nested-core/src/tree/cursor.rs diff --git a/lib-nested-core/src/tree/diagnostics.rs b/lib-nested-core/src/tree/diagnostics.rs new file mode 100644 index 0000000..71fb079 --- /dev/null +++ b/lib-nested-core/src/tree/diagnostics.rs @@ -0,0 +1,24 @@ +use { + r3vi::{ + view::{OuterViewPort, sequence::*}, + buffer::{vec::*, index_hashmap::*} + }, + crate::{ + type_system::ReprTree + }, + std::sync::{Arc, RwLock}, + cgmath::Point2 +}; + +#[derive(Clone)] +pub struct Message { + pub addr: Vec, + pub disp: Arc> +} + +pub trait Diagnostics { + fn get_msg_port(&self) -> OuterViewPort> { + VecBuffer::new().get_port().to_sequence() + } +} + diff --git a/nested/src/tree/mod.rs b/lib-nested-core/src/tree/mod.rs similarity index 91% rename from nested/src/tree/mod.rs rename to lib-nested-core/src/tree/mod.rs index 71e40c8..81251d0 100644 --- a/nested/src/tree/mod.rs +++ b/lib-nested-core/src/tree/mod.rs @@ -3,6 +3,7 @@ pub mod cursor; pub mod nav; pub mod node; pub mod treetype; +pub mod diagnostics; pub use { addr::TreeAddr, diff --git a/nested/src/tree/nav.rs b/lib-nested-core/src/tree/nav.rs similarity index 74% rename from nested/src/tree/nav.rs rename to lib-nested-core/src/tree/nav.rs index 9d85cdd..962834d 100644 --- a/nested/src/tree/nav.rs +++ b/lib-nested-core/src/tree/nav.rs @@ -15,8 +15,7 @@ use { }, crate::{ editors::list::ListCursorMode, - tree::TreeCursor, - terminal::{TerminalView, TerminalProjections, make_label} + tree::TreeCursor }, cgmath::Vector2, }; @@ -150,35 +149,6 @@ pub trait TreeNav { } } - fn get_cursor_widget(&self) -> OuterViewPort { - VecBuffer::with_data( - vec![ - make_label("@").with_fg_color((150, 80,230)), - self.get_addr_view() - .map(|i| - make_label(&format!("{}", i)).with_fg_color((0, 100, 20))) - .separate(make_label(".").with_fg_color((150, 80,230))) - .to_grid_horizontal() - .flatten(), - make_label(":").with_fg_color((150, 80,230)), - self.get_mode_view() - .map(|mode| { - make_label( - match mode { - ListCursorMode::Insert => "INSERT", - ListCursorMode::Select => "SELECT" - }) - .with_fg_color((200, 200, 20)) - }) - .to_grid() - .flatten(), - make_label(":").with_fg_color((150, 80,230)) - ] - ).get_port() - .to_sequence() - .to_grid_horizontal() - .flatten() - } } diff --git a/nested/src/tree/node.rs b/lib-nested-core/src/tree/node.rs similarity index 91% rename from nested/src/tree/node.rs rename to lib-nested-core/src/tree/node.rs index 1406c96..f0c9d16 100644 --- a/nested/src/tree/node.rs +++ b/lib-nested-core/src/tree/node.rs @@ -3,30 +3,28 @@ use { cgmath::{Vector2, Point2}, r3vi::{ view::{View, ViewPort, OuterViewPort, AnyOuterViewPort, singleton::*, sequence::*}, - buffer::{singleton::*} + buffer::{singleton::*, vec::*} }, laddertypes::{TypeTerm}, crate::{ type_system::{ReprTree, Context}, - terminal::{TerminalView, TerminalEvent, TerminalEditor, TerminalEditorResult, TerminalAtom}, - diagnostics::{Diagnostics, Message}, - tree::{TreeNav, TreeCursor, TreeNavResult, TreeHeightOp}, - editors::list::{ListCursorMode}, - commander::ObjCommander, + tree::{TreeNav, TreeCursor, TreeNavResult, TreeHeightOp, diagnostics::{Diagnostics, Message}}, + editors::{list::{ListCursorMode}, ObjCommander} } }; -/* TODO: refactoring proposal +//* TODO: refactoring proposal +/* struct NestedNodeDisplay { /// display view - pub view: Option< OuterViewPort >, + pub view: Option< Arc> >, /// diagnostics - pub diag: Option< OuterViewPort> >, + pub diag: Option< OuterViewPort> >, /// depth - pub depth: SingletonBuffer< usize >, + pub depth: SingletonBuffer< usize >, } struct NestedNodeEdit { @@ -40,7 +38,9 @@ struct NestedNodeEdit { /// commander & navigation pub cmd: SingletonBuffer< Option< Arc> > - >, + >, /// abstract data view + pub data: Arc>, + pub close_char: SingletonBuffer< Option< char > >, // could be replaced by cmd when TreeNav -CmdObjects are used @@ -62,7 +62,6 @@ pub struct NewNestedNode { /// editor & commander objects pub edit: NestedNodeEdit } - */ #[derive(Clone)] @@ -74,7 +73,7 @@ pub struct NestedNode { pub data: Arc>, /// display view - pub view: Option< OuterViewPort >, + pub view: Option< Arc> >, /// diagnostics pub diag: Option< OuterViewPort> >, @@ -129,7 +128,8 @@ impl NestedNode { buf.get_port().into() ), SingletonBuffer::new(0).get_port() - ) + ) + /* .set_view(buf.get_port() .map(|c| TerminalAtom::from(c)) .to_index() @@ -141,6 +141,7 @@ impl NestedNode { if *p == Point2::new(0,0) { Some(()) } else { None } }) ) + */ .set_editor(Arc::new(RwLock::new(buf))) } @@ -162,7 +163,7 @@ impl NestedNode { self } - pub fn set_view(mut self, view: OuterViewPort) -> Self { + pub fn set_view(mut self, view: Arc>) -> Self { self.view = Some(view); self } @@ -188,8 +189,8 @@ impl NestedNode { self.diag.clone().unwrap_or(ViewPort::new().into_outer()) } - pub fn get_view(&self) -> OuterViewPort { - self.view.clone().unwrap_or(ViewPort::new().into_outer()) + pub fn get_view(&self) -> Option< Arc> > { + self.view.clone() } pub fn get_data_port<'a, V: View + ?Sized + 'static>(&'a self, type_str: impl Iterator) -> Option> @@ -246,6 +247,7 @@ impl TreeType for NestedNode { /* TODO: remove that at some point */ +/* impl TerminalEditor for NestedNode { fn get_term_view(&self) -> OuterViewPort { self.get_view() @@ -265,7 +267,7 @@ impl TerminalEditor for NestedNode { TerminalEditorResult::Continue } } - +*/ impl TreeNav for NestedNode { fn get_cursor(&self) -> TreeCursor { if let Some(tn) = self.tree_nav.get() { diff --git a/nested/src/tree/treetype.rs b/lib-nested-core/src/tree/treetype.rs similarity index 100% rename from nested/src/tree/treetype.rs rename to lib-nested-core/src/tree/treetype.rs diff --git a/nested/src/type_system/context.rs b/lib-nested-core/src/type_system/context.rs similarity index 100% rename from nested/src/type_system/context.rs rename to lib-nested-core/src/type_system/context.rs diff --git a/nested/src/type_system/mod.rs b/lib-nested-core/src/type_system/mod.rs similarity index 100% rename from nested/src/type_system/mod.rs rename to lib-nested-core/src/type_system/mod.rs diff --git a/nested/src/type_system/repr_tree.rs b/lib-nested-core/src/type_system/repr_tree.rs similarity index 96% rename from nested/src/type_system/repr_tree.rs rename to lib-nested-core/src/type_system/repr_tree.rs index 611565c..7e226f9 100644 --- a/nested/src/type_system/repr_tree.rs +++ b/lib-nested-core/src/type_system/repr_tree.rs @@ -56,6 +56,14 @@ impl ReprTree { ) } + pub fn from_u64(ctx: &Arc>, v: u64) -> Arc> { + let buf = r3vi::buffer::singleton::SingletonBuffer::::new(v); + ReprTree::new_leaf( + Context::parse(ctx, ""), + buf.get_port().into() + ) + } + pub fn new_leaf(type_tag: impl Into, port: AnyOuterViewPort) -> Arc> { let mut tree = ReprTree::new(type_tag.into()); tree.insert_leaf(vec![].into_iter(), port); diff --git a/nested/src/utils/bimap.rs b/lib-nested-core/src/utils/bimap.rs similarity index 100% rename from nested/src/utils/bimap.rs rename to lib-nested-core/src/utils/bimap.rs diff --git a/nested/src/utils/mod.rs b/lib-nested-core/src/utils/mod.rs similarity index 83% rename from nested/src/utils/mod.rs rename to lib-nested-core/src/utils/mod.rs index fe10469..8e8f5dd 100644 --- a/nested/src/utils/mod.rs +++ b/lib-nested-core/src/utils/mod.rs @@ -1,6 +1,5 @@ pub mod bimap; pub mod modulo; -pub mod color; pub use modulo::modulo; pub use bimap::Bimap; diff --git a/nested/src/utils/modulo.rs b/lib-nested-core/src/utils/modulo.rs similarity index 100% rename from nested/src/utils/modulo.rs rename to lib-nested-core/src/utils/modulo.rs diff --git a/terminal/ansi_parser/Cargo.toml b/lib-nested-tty/Cargo.toml similarity index 51% rename from terminal/ansi_parser/Cargo.toml rename to lib-nested-tty/Cargo.toml index 2b1ca1d..e85b2d9 100644 --- a/terminal/ansi_parser/Cargo.toml +++ b/lib-nested-tty/Cargo.toml @@ -1,13 +1,22 @@ [package] authors = ["Michael Sippel "] -name = "ansi_parser" +name = "nested-tty" version = "0.1.0" edition = "2018" [dependencies] -nested = { path = "../../nested" } +r3vi = { path = "../../lib-r3vi" } +nested = { path = "../lib-nested-core" } cgmath = { version = "0.18.0", features = ["serde"] } serde = { version = "1.0", features = ["serde_derive"] } -bincode = "1.3.3" +termion = "2.0.3" vte = "0.10.1" ansi_colours = "1.0" +signal-hook = "*" +signal-hook-async-std = "*" + +[dependencies.async-std] +version = "1.9.0" +features = ["unstable", "attributes"] + + diff --git a/nested/src/terminal/ansi_parser.rs b/lib-nested-tty/src/ansi_parser.rs similarity index 99% rename from nested/src/terminal/ansi_parser.rs rename to lib-nested-tty/src/ansi_parser.rs index 669ee06..efd8a83 100644 --- a/nested/src/terminal/ansi_parser.rs +++ b/lib-nested-tty/src/ansi_parser.rs @@ -10,7 +10,7 @@ use { projection::projection_helper::ProjectionHelper, }, crate::{ - terminal::{TerminalAtom, TerminalStyle, TerminalView}, + TerminalAtom, TerminalStyle, TerminalView, }, cgmath::{Point2, Vector2}, std::io::Read, diff --git a/nested/src/terminal/atom.rs b/lib-nested-tty/src/atom.rs similarity index 100% rename from nested/src/terminal/atom.rs rename to lib-nested-tty/src/atom.rs diff --git a/nested/src/utils/color.rs b/lib-nested-tty/src/color.rs similarity index 100% rename from nested/src/utils/color.rs rename to lib-nested-tty/src/color.rs diff --git a/nested/src/terminal/compositor.rs b/lib-nested-tty/src/compositor.rs similarity index 97% rename from nested/src/terminal/compositor.rs rename to lib-nested-tty/src/compositor.rs index d8a53e4..e0774d6 100644 --- a/nested/src/terminal/compositor.rs +++ b/lib-nested-tty/src/compositor.rs @@ -6,7 +6,7 @@ use { }, projection::projection_helper::*, }, - crate::{terminal::{TerminalAtom, TerminalView}}, + crate::{TerminalAtom, TerminalView}, cgmath::Point2, std::sync::Arc, std::sync::RwLock, diff --git a/lib-nested-tty/src/cursor_widget.rs b/lib-nested-tty/src/cursor_widget.rs new file mode 100644 index 0000000..2504428 --- /dev/null +++ b/lib-nested-tty/src/cursor_widget.rs @@ -0,0 +1,33 @@ + +impl TreeNav { + fn get_cursor_widget(&self) -> OuterViewPort { + VecBuffer::with_data( + vec![ + make_label("@").with_fg_color((150, 80,230)), + self.get_addr_view() + .map(|i| + make_label(&format!("{}", i)).with_fg_color((0, 100, 20))) + .separate(make_label(".").with_fg_color((150, 80,230))) + .to_grid_horizontal() + .flatten(), + make_label(":").with_fg_color((150, 80,230)), + self.get_mode_view() + .map(|mode| { + make_label( + match mode { + ListCursorMode::Insert => "INSERT", + ListCursorMode::Select => "SELECT" + }) + .with_fg_color((200, 200, 20)) + }) + .to_grid() + .flatten(), + make_label(":").with_fg_color((150, 80,230)) + ] + ).get_port() + .to_sequence() + .to_grid_horizontal() + .flatten() + } +} + diff --git a/nested/src/diagnostics.rs b/lib-nested-tty/src/diagnostics.rs similarity index 82% rename from nested/src/diagnostics.rs rename to lib-nested-tty/src/diagnostics.rs index c1230c5..6ffad73 100644 --- a/nested/src/diagnostics.rs +++ b/lib-nested-tty/src/diagnostics.rs @@ -1,27 +1,3 @@ -use { - r3vi::{ - view::{OuterViewPort, sequence::*}, - buffer::{vec::*, index_hashmap::*} - }, - crate::{ - terminal::{ - TerminalView, TerminalStyle, make_label - } - }, - cgmath::Point2 -}; - -#[derive(Clone)] -pub struct Message { - pub addr: Vec, - pub port: OuterViewPort -} - -pub trait Diagnostics { - fn get_msg_port(&self) -> OuterViewPort> { - VecBuffer::new().get_port().to_sequence() - } -} pub fn make_error(msg: OuterViewPort) -> Message { let mut mb = IndexBuffer::new(); diff --git a/nested/src/terminal/mod.rs b/lib-nested-tty/src/lib.rs similarity index 82% rename from nested/src/terminal/mod.rs rename to lib-nested-tty/src/lib.rs index 61e41b2..21e89e4 100644 --- a/nested/src/terminal/mod.rs +++ b/lib-nested-tty/src/lib.rs @@ -1,9 +1,20 @@ -pub mod ansi_parser; + +#![feature(trait_alias)] + +//<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>> + pub mod atom; -pub mod compositor; pub mod style; + +pub mod compositor; +pub mod ansi_parser; + pub mod terminal; -pub mod widgets; + +//pub mod list_editor; +//pub mod widgets; + +//<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>> pub use { atom::TerminalAtom, @@ -32,10 +43,17 @@ pub trait TerminalEditor { //<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>> +use r3vi::view::OuterViewPort; + +pub trait DisplaySegment { + fn display_view(&self) -> OuterViewPort; +} + +//<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>> + use { r3vi::{ - view::{OuterViewPort}, - buffer::vec::*, + buffer::vec::*, }, cgmath::Point2, }; @@ -55,6 +73,8 @@ pub fn make_label(s: &str) -> OuterViewPort { v } +//<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>> + pub trait TerminalProjections { fn with_style(&self, style: TerminalStyle) -> OuterViewPort; fn with_fg_color(&self, col: (u8, u8, u8)) -> OuterViewPort; @@ -78,3 +98,4 @@ impl TerminalProjections for OuterViewPort { } } + diff --git a/nested/src/editors/list/pty_editor.rs b/lib-nested-tty/src/list_editor.rs similarity index 85% rename from nested/src/editors/list/pty_editor.rs rename to lib-nested-tty/src/list_editor.rs index 829aef4..663079d 100644 --- a/nested/src/editors/list/pty_editor.rs +++ b/lib-nested-tty/src/list_editor.rs @@ -3,20 +3,57 @@ use { view::{ViewPort, OuterViewPort, sequence::*}, projection::decorate_sequence::*, }, - crate::{ + nested::{ type_system::{Context, ReprTree}, editors::list::*, - terminal::{TerminalEvent, TerminalView, make_label}, tree::{TreeCursor, TreeNav, TreeNavResult}, tree::NestedNode, PtySegment }, + crate::{ + TerminalEvent, TerminalView, make_label + } std::sync::{Arc, RwLock}, termion::event::{Event, Key} }; //<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>> +impl PtySegment for ListSegment { + fn pty_view(&self) -> OuterViewPort { + match self { + ListSegment::InsertCursor => { + make_label("|") + .map_item(move |_pt, atom| { + atom.add_style_front(TerminalStyle::fg_color((150,80,230))) + .add_style_front(TerminalStyle::bold(true)) + }) + } + ListSegment::Item{ editor, cur_dist } => { + let e = editor.clone(); + let cur_dist = *cur_dist; + editor.get_view().map_item(move |_pt, atom| { + let c = e.get_cursor(); + let cur_depth = c.tree_addr.len(); + let select = + if cur_dist == 0 { + cur_depth + } else { + usize::MAX + }; + + atom + .add_style_back(bg_style_from_depth(select)) + .add_style_back(TerminalStyle::bold(select==1)) + .add_style_back(fg_style_from_depth(e.depth.get_view().get())) + }) + } + } + } +} + +//<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>> + pub struct PTYListStyle { style: (String, String, String) } diff --git a/nested/src/terminal/style.rs b/lib-nested-tty/src/style.rs similarity index 100% rename from nested/src/terminal/style.rs rename to lib-nested-tty/src/style.rs diff --git a/lib-nested-tty/src/sum_editor.rs b/lib-nested-tty/src/sum_editor.rs new file mode 100644 index 0000000..626f249 --- /dev/null +++ b/lib-nested-tty/src/sum_editor.rs @@ -0,0 +1,8 @@ + + +impl PtySegment for SumEditor { + fn pty_view(&self) -> OuterViewPort { + self.port.outer() + } +} + diff --git a/nested/src/terminal/terminal.rs b/lib-nested-tty/src/terminal.rs similarity index 100% rename from nested/src/terminal/terminal.rs rename to lib-nested-tty/src/terminal.rs diff --git a/nested/src/terminal/widgets/ascii_box.rs b/lib-nested-tty/src/widgets/ascii_box.rs similarity index 100% rename from nested/src/terminal/widgets/ascii_box.rs rename to lib-nested-tty/src/widgets/ascii_box.rs diff --git a/nested/src/terminal/widgets/mod.rs b/lib-nested-tty/src/widgets/mod.rs similarity index 100% rename from nested/src/terminal/widgets/mod.rs rename to lib-nested-tty/src/widgets/mod.rs diff --git a/nested/src/terminal/widgets/monstera.rs b/lib-nested-tty/src/widgets/monstera.rs similarity index 100% rename from nested/src/terminal/widgets/monstera.rs rename to lib-nested-tty/src/widgets/monstera.rs diff --git a/nested/src/terminal/widgets/plot.rs b/lib-nested-tty/src/widgets/plot.rs similarity index 100% rename from nested/src/terminal/widgets/plot.rs rename to lib-nested-tty/src/widgets/plot.rs diff --git a/math/fib/Cargo.toml b/math/fib/Cargo.toml deleted file mode 100644 index 7f4efbb..0000000 --- a/math/fib/Cargo.toml +++ /dev/null @@ -1,9 +0,0 @@ -[package] -name = "fib" -version = "0.1.0" -edition = "2018" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -nested = { path = "../../nested" } diff --git a/math/fib/src/main.rs b/math/fib/src/main.rs deleted file mode 100644 index b528448..0000000 --- a/math/fib/src/main.rs +++ /dev/null @@ -1,62 +0,0 @@ -use std::{ - fs::File, - io::{Read, Write}, - os::unix::io::FromRawFd, -}; - -fn fib(n: u64) -> u64 { - let mut y = 0; - let mut y1 = 1; - let mut y2 = 0; - - for _ in 0..n { - y = y1 + y2; - y2 = y1; - y1 = y; - } - - y -} - -fn main() { - nested::magic_header(); - - eprintln!(" Fibonacci Sequence"); - - nested::magic_header(); - - eprintln!( - " -interface (Sequence ℕ) 0 1" - ); - - let mut f0 = unsafe { File::from_raw_fd(0) }; - eprintln!( - " ->0: n - ( ℕ ) - ( MachineInt ) - ( MachineWord ) - ( Stream MachineSyllab ) -" - ); - - let mut f1 = unsafe { File::from_raw_fd(1) }; - eprintln!( - " -<1: n'th fibonacci number - ( ℕ ) - ( MachineInt ) - ( MachineWord ) - ( Stream MachineSyllab ) -" - ); - - nested::magic_header(); - - let mut bytes = [0 as u8; 8]; - f0.read_exact(&mut bytes).expect(""); - let n = u64::from_le_bytes(bytes); - bytes = fib(n).to_le_bytes(); - f1.write(&bytes).expect(""); -} diff --git a/math/int2str/Cargo.toml b/math/int2str/Cargo.toml deleted file mode 100644 index cdac039..0000000 --- a/math/int2str/Cargo.toml +++ /dev/null @@ -1,9 +0,0 @@ -[package] -name = "int2str" -version = "0.1.0" -edition = "2018" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -nested = { path = "../../nested" } diff --git a/math/int2str/src/main.rs b/math/int2str/src/main.rs deleted file mode 100644 index 00cc669..0000000 --- a/math/int2str/src/main.rs +++ /dev/null @@ -1,36 +0,0 @@ -use std::{fs::File, io::Read, os::unix::io::FromRawFd}; - -fn main() { - nested::magic_header(); - eprintln!(" Human-readably Print MachineInt"); - nested::magic_header(); - - let mut f0 = unsafe { File::from_raw_fd(0) }; - eprintln!( - " ->0: - ( ℕ ) - ( MachineInt ) - ( MachineWord ) - ( Stream MachineSyllab ) -" - ); - - eprintln!( - " -<1: - ( ℕ ) - ( PositionalInt 10 BigEndian ) - ( Sequence ( Digit 10 ) ) - ( Sequence UTF-8-Char ) - ( Stream UTF-8-Char ) - ( Stream MachineSyllab ) -" - ); - - nested::magic_header(); - - let mut bytes = [0 as u8; 8]; - f0.read_exact(&mut bytes).expect(""); - println!("{}", u64::from_le_bytes(bytes)); -} diff --git a/math/radix_transform/Cargo.toml b/math/radix_transform/Cargo.toml deleted file mode 100644 index 678a012..0000000 --- a/math/radix_transform/Cargo.toml +++ /dev/null @@ -1,13 +0,0 @@ -[package] -name = "radix_transform" -version = "0.1.0" -edition = "2018" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -nested = { path = "../../nested" } - -[dependencies.async-std] -version = "1.9.0" -features = ["unstable", "attributes"] diff --git a/math/radix_transform/src/main.rs b/math/radix_transform/src/main.rs deleted file mode 100644 index b1b48ff..0000000 --- a/math/radix_transform/src/main.rs +++ /dev/null @@ -1,137 +0,0 @@ -use nested::{ - core::{TypeDict, ViewPort}, - integer::RadixProjection, - vec::VecBuffer, -}; - -#[async_std::main] -async fn main() { - let mut td = TypeDict::new(); - for tn in vec![ - "MachineWord", - "MachineInt", - "MachineSyllab", - "Vec", - "Stream", - "Json", - "Sequence", - "UTF-8-Char", - "PositionalInt", - "Digit", - "LittleEndian", - "BigEndian", - "DiffStream", - "ℕ", - "$src_radix", - "$dst_radix", - ] { - td.add_typename(tn.into()); - } - - let radix_types = vec![ - td.type_term_from_str("( ℕ )").unwrap(), - td.type_term_from_str("( PositionalInt 10 LittleEndian )") - .unwrap(), - td.type_term_from_str("( Sequence ( Digit 10 ) )").unwrap(), - td.type_term_from_str("( Sequence UTF-8-Char )").unwrap(), - td.type_term_from_str("( Sequence MachineSyllab )").unwrap(), - ]; - - let src_types = vec![ - td.type_term_from_str("( ℕ )").unwrap(), - td.type_term_from_str("( PositionalInt $src_radix LittleEndian )") - .unwrap(), - td.type_term_from_str("( Sequence ( Digit $src_radix ) )") - .unwrap(), - td.type_term_from_str("( Sequence MachineInt )").unwrap(), - td.type_term_from_str("( DiffStream ( Vec MachineInt ) )") - .unwrap(), - td.type_term_from_str("( Json )").unwrap(), - td.type_term_from_str("( Stream UTF-8-Char )").unwrap(), - td.type_term_from_str("( Stream MachineSyllab )").unwrap(), - ]; - - let dst_types = vec![ - td.type_term_from_str("( ℕ )").unwrap(), - td.type_term_from_str("( PositionalInt $dst_radix LittleEndian )") - .unwrap(), - td.type_term_from_str("( Sequence ( Digit $dst_radix ) )") - .unwrap(), - td.type_term_from_str("( Sequence MachineInt )").unwrap(), - td.type_term_from_str("( DiffStream ( Vec MachineInt ) )") - .unwrap(), - td.type_term_from_str("( Json )").unwrap(), - td.type_term_from_str("( Stream UTF-8-Char )").unwrap(), - td.type_term_from_str("( Stream MachineSyllab )").unwrap(), - ]; - - nested::magic_header(); - eprintln!(" Convert Radix of Positional Integer"); - nested::magic_header(); - - eprintln!("\n$1: src_radix"); - for t in radix_types.iter() { - eprintln!(" {}", td.type_term_to_str(t)); - } - - eprintln!("\n$2: dst_radix"); - for t in radix_types.iter() { - eprintln!(" {}", td.type_term_to_str(t)); - } - - eprintln!("\n>0: n"); - for t in src_types.iter() { - eprintln!(" {}", td.type_term_to_str(t)); - } - - eprintln!("\n<1: n"); - for t in dst_types.iter() { - eprintln!(" {}", td.type_term_to_str(t)); - } - - nested::magic_header(); - - let mut args = std::env::args(); - args.next().expect("Arg $0 missing!"); - - let src_radix_str = args.next().expect("Arg $1 required!"); - let dst_radix_str = args.next().expect("Arg $2 required!"); - - let src_radix = usize::from_str_radix(&src_radix_str, 10).expect("could not parse src_radix"); - let dst_radix = usize::from_str_radix(&dst_radix_str, 10).expect("could not parse dst_radix"); - - assert!(src_radix > 1); - assert!(dst_radix > 1); - - let src_digits_port = ViewPort::new(); - let dst_digits_port = ViewPort::new(); - - let mut src_digits = VecBuffer::::new(src_digits_port.inner()); - - let _proj = RadixProjection::new( - src_radix, - dst_radix, - src_digits_port.outer().to_sequence(), - dst_digits_port.inner(), - ); - - // output dst digits - let writer = { - use std::os::unix::io::FromRawFd; - - dst_digits_port - .outer() - .serialize_json(unsafe { std::fs::File::from_raw_fd(1) }) - }; - - // start reading src digits - { - use async_std::os::unix::io::FromRawFd; - - src_digits - .from_json(unsafe { async_std::fs::File::from_raw_fd(0) }) - .await; - } - - drop(writer); -} diff --git a/math/str2int/Cargo.toml b/math/str2int/Cargo.toml deleted file mode 100644 index b85bed6..0000000 --- a/math/str2int/Cargo.toml +++ /dev/null @@ -1,9 +0,0 @@ -[package] -name = "str2int" -version = "0.1.0" -edition = "2018" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -nested = { path = "../../nested" } diff --git a/math/str2int/src/main.rs b/math/str2int/src/main.rs deleted file mode 100644 index fa900b5..0000000 --- a/math/str2int/src/main.rs +++ /dev/null @@ -1,69 +0,0 @@ -use std::{ - fs::File, - io::{Read, Write}, - os::unix::io::FromRawFd, -}; - -fn main() { - nested::magic_header(); - eprintln!(" Parse MachineInt from String"); - nested::magic_header(); - - eprintln!( - " -$1: radix - ( ℕ ) - ( PositionalInt 10 BigEndian ) - ( Sequence ( Digit 10 ) ) - ( Sequence UTF-8-Char ) - ( Sequence MachineSyllab ) -" - ); - - eprintln!( - " ->0: n - ( ℕ ) - ( PositionalInt $radix BigEndian ) - ( Sequence ( Digit $radix ) ) - ( Sequence UTF-8-Char ) - ( Stream UTF-8-Char ) - ( Stream MachineSyllab ) -" - ); - - eprintln!( - " -<1: n - ( ℕ ) - ( MachineInt ) - ( MachineWord ) - ( Stream MachineSyllab ) -" - ); - - nested::magic_header(); - - let mut f0 = unsafe { File::from_raw_fd(0) }; - let mut f1 = unsafe { File::from_raw_fd(1) }; - - let mut args = std::env::args(); - args.next().expect("Arg $0 missing!"); - - let radix_str = args.next().expect("Arg $1 required!"); - - let radix = u32::from_str_radix(&radix_str, 10).expect("could not parse radix"); - if radix > 16 { - panic!("invalid radix! (radix<=16 required)"); - } - - let mut chars = Vec::new(); - f0.read_to_end(&mut chars).expect(""); - chars.retain(|c| (*c as char).is_alphanumeric()); - f1.write( - &u64::from_str_radix(&String::from_utf8_lossy(&chars), radix) - .unwrap() - .to_le_bytes(), - ) - .expect(""); -} diff --git a/nested/src/editors/mod.rs b/nested/src/editors/mod.rs deleted file mode 100644 index a93800c..0000000 --- a/nested/src/editors/mod.rs +++ /dev/null @@ -1,9 +0,0 @@ - -pub mod list; -pub mod product; -pub mod sum; - -pub mod char; -pub mod integer; -pub mod typeterm; - diff --git a/nested/src/lib.rs b/nested/src/lib.rs deleted file mode 100644 index c81e77d..0000000 --- a/nested/src/lib.rs +++ /dev/null @@ -1,34 +0,0 @@ -#![feature(trait_alias)] - -pub mod terminal; - -pub mod utils; -pub mod editors; -pub mod tree; -pub mod type_system; - -pub mod diagnostics; -pub mod commander; -//pub mod product; -//pub mod sum; -//pub mod list; - -pub fn magic_header() { - eprintln!("<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>>"); -} - -/* -pub trait StringGen { - fn get_string(&self) -> String; -} - -use crate::{tree::{TreeNav}, diagnostics::Diagnostics, terminal::TerminalView, core::{OuterViewPort}}; - */ - -use r3vi::view::OuterViewPort; -use crate::terminal::TerminalView; - -pub trait PtySegment { - fn pty_view(&self) -> OuterViewPort; -} - diff --git a/terminal/ansi_parser/src/main.rs b/terminal/ansi_parser/src/main.rs deleted file mode 100644 index 0e4d532..0000000 --- a/terminal/ansi_parser/src/main.rs +++ /dev/null @@ -1,331 +0,0 @@ -#![feature(iter_advance_by)] - -use { - cgmath::Point2, - nested::terminal::{TerminalAtom, TerminalStyle}, - std::{ - fs::File, - io::{stdin, Read, Write}, - os::unix::io::FromRawFd, - }, - vte::{Params, Parser, Perform}, -}; - -struct ColorPalett { - black: (u8, u8, u8), - red: (u8, u8, u8), - green: (u8, u8, u8), - yellow: (u8, u8, u8), - blue: (u8, u8, u8), - magenta: (u8, u8, u8), - cyan: (u8, u8, u8), - white: (u8, u8, u8), -} - -struct PerfAtom { - colors: ColorPalett, - term_width: i16, - - cursor: Point2, - style: TerminalStyle, - - out: File, -} - -impl PerfAtom { - fn write_atom(&mut self, pos: Point2, atom: Option) { - self.out - .write(&bincode::serialize(&(pos, atom)).unwrap()) - .expect(""); - } -} - -impl Perform for PerfAtom { - fn print(&mut self, c: char) { - //eprintln!("[print] {:?}", c); - self.write_atom(self.cursor, Some(TerminalAtom::new(c, self.style))); - - self.cursor.x += 1; - if self.cursor.x > self.term_width { - self.cursor.x = 0; - self.cursor.y += 1; - } - } - - fn execute(&mut self, byte: u8) { - //eprintln!("[execute] {:02x}", byte); - match byte { - b'\n' => { - self.cursor.x = 0; - self.cursor.y += 1; - } - _ => {} - } - } - - fn hook(&mut self, params: &Params, intermediates: &[u8], ignore: bool, c: char) { - eprintln!( - "[hook] params={:?}, intermediates={:?}, ignore={:?}, char={:?}", - params, intermediates, ignore, c - ); - } - - fn put(&mut self, byte: u8) { - eprintln!("[put] {:02x}", byte); - } - - fn unhook(&mut self) { - eprintln!("[unhook]"); - } - - fn osc_dispatch(&mut self, params: &[&[u8]], bell_terminated: bool) { - eprintln!( - "[osc_dispatch] params={:?} bell_terminated={}", - params, bell_terminated - ); - } - - fn csi_dispatch(&mut self, params: &Params, intermediates: &[u8], ignore: bool, c: char) { - eprintln!( - "[csi_dispatch] params={:#?}, intermediates={:?}, ignore={:?}, char={:?}", - params, intermediates, ignore, c - ); - - let mut piter = params.into_iter(); - - match c { - // Set SGR - 'm' => { - while let Some(n) = piter.next() { - match n[0] { - 0 => self.style = TerminalStyle::default(), - 1 => self.style = self.style.add(TerminalStyle::bold(true)), - 3 => self.style = self.style.add(TerminalStyle::italic(true)), - 4 => self.style = self.style.add(TerminalStyle::underline(true)), - - 30 => { - self.style = self.style.add(TerminalStyle::fg_color(self.colors.black)) - } - 40 => { - self.style = self.style.add(TerminalStyle::bg_color(self.colors.black)) - } - 31 => self.style = self.style.add(TerminalStyle::fg_color(self.colors.red)), - 41 => self.style = self.style.add(TerminalStyle::bg_color(self.colors.red)), - 32 => { - self.style = self.style.add(TerminalStyle::fg_color(self.colors.green)) - } - 42 => { - self.style = self.style.add(TerminalStyle::bg_color(self.colors.green)) - } - 33 => { - self.style = self.style.add(TerminalStyle::fg_color(self.colors.yellow)) - } - 43 => { - self.style = self.style.add(TerminalStyle::bg_color(self.colors.yellow)) - } - 34 => { - self.style = self.style.add(TerminalStyle::fg_color(self.colors.blue)) - } - 44 => { - self.style = self.style.add(TerminalStyle::bg_color(self.colors.blue)) - } - 35 => { - self.style = - self.style.add(TerminalStyle::fg_color(self.colors.magenta)) - } - 45 => { - self.style = - self.style.add(TerminalStyle::bg_color(self.colors.magenta)) - } - 36 => { - self.style = self.style.add(TerminalStyle::fg_color(self.colors.cyan)) - } - 46 => { - self.style = self.style.add(TerminalStyle::bg_color(self.colors.cyan)) - } - 37 => { - self.style = self.style.add(TerminalStyle::fg_color(self.colors.white)) - } - 47 => { - self.style = self.style.add(TerminalStyle::bg_color(self.colors.white)) - } - - 38 => { - let x = piter.next().unwrap(); - match x[0] { - 2 => { - let r = piter.next().unwrap(); - let g = piter.next().unwrap(); - let b = piter.next().unwrap(); - self.style = self.style.add(TerminalStyle::fg_color(( - r[0] as u8, - g[0] as u8, - b[30] as u8, - ))) - } - 5 => { - let v = piter.next().unwrap(); - self.style = self.style.add(TerminalStyle::fg_color( - ansi_colours::rgb_from_ansi256(v[0] as u8), - )) - } - _ => {} - } - } - - 48 => { - let x = piter.next().unwrap(); - match x[0] { - 2 => { - let r = piter.next().unwrap(); - let g = piter.next().unwrap(); - let b = piter.next().unwrap(); - self.style = self.style.add(TerminalStyle::bg_color(( - r[0] as u8, - g[0] as u8, - b[30] as u8, - ))) - } - 5 => { - let v = piter.next().unwrap(); - self.style = self.style.add(TerminalStyle::bg_color( - ansi_colours::rgb_from_ansi256(v[0] as u8), - )) - } - _ => {} - } - } - - _ => {} - } - } - } - - 'H' => { - if let Some(y) = piter.next() { - self.cursor.y = y[0] as i16 - 1 - }; - if let Some(x) = piter.next() { - self.cursor.x = x[0] as i16 - 1 - }; - - eprintln!("cursor at {:?}", self.cursor); - } - - 'A' => { - self.cursor.y -= piter.next().unwrap()[0] as i16; - } - 'B' => { - self.cursor.y += piter.next().unwrap()[0] as i16; - } - 'C' => { - self.cursor.x += piter.next().unwrap()[0] as i16; - } - 'D' => { - self.cursor.x -= piter.next().unwrap()[0] as i16; - } - 'E' => { - self.cursor.x = 0; - self.cursor.y += piter.next().unwrap()[0] as i16; - } - - 'J' => { - let x = piter.next().unwrap_or(&[0 as u16; 1]); - match x[0] { - 0 => {} - 1 => {} - 2 => { - for y in 0..100 { - for x in 0..self.term_width { - self.write_atom(Point2::new(x, y), None); - } - } - } - - // invalid - _ => {} - } - } - - 'K' => { - let x = piter.next().unwrap(); - match x[0] { - // clear cursor until end - 0 => { - for x in self.cursor.x..self.term_width { - self.write_atom(Point2::new(x, self.cursor.y), None); - } - } - - // clear start until cursor - 1 => { - for x in 0..self.cursor.x { - self.write_atom(Point2::new(x, self.cursor.y), None); - } - } - - // clear entire line - 2 => { - for x in 0..self.term_width { - self.write_atom(Point2::new(x, self.cursor.y), None); - } - } - - // invalid - _ => {} - } - } - - _ => {} - } - } - - fn esc_dispatch(&mut self, intermediates: &[u8], ignore: bool, byte: u8) { - eprintln!( - "[esc_dispatch] intermediates={:?}, ignore={:?}, byte={:02x}", - intermediates, ignore, byte - ); - } -} - -fn main() { - let input = stdin(); - let mut handle = input.lock(); - - let mut statemachine = Parser::new(); - let mut performer = PerfAtom { - cursor: Point2::new(0, 0), - style: TerminalStyle::default(), - term_width: 200, - out: unsafe { File::from_raw_fd(1) }, - - colors: ColorPalett { - black: (1, 1, 1), - red: (222, 56, 43), - green: (0, 64, 0), - yellow: (255, 199, 6), - blue: (0, 111, 184), - magenta: (118, 38, 113), - cyan: (44, 181, 233), - white: (204, 204, 204), - }, - }; - - let mut buf = [0; 2048]; - - loop { - match handle.read(&mut buf) { - Ok(0) => break, - Ok(n) => { - for byte in &buf[..n] { - statemachine.advance(&mut performer, *byte); - performer.out.flush().unwrap(); - } - } - Err(err) => { - println!("err: {}", err); - break; - } - } - } -} diff --git a/terminal/display_server/Cargo.toml b/terminal/display_server/Cargo.toml deleted file mode 100644 index 4d933da..0000000 --- a/terminal/display_server/Cargo.toml +++ /dev/null @@ -1,12 +0,0 @@ -[package] -authors = ["Michael Sippel "] -name = "display_server" -version = "0.1.0" -edition = "2018" - -[dependencies] -nested = { path = "../../nested" } -termion = "1.5.5" -cgmath = { version = "0.18.0", features = ["serde"] } -serde = { version = "1.0", features = ["serde_derive"] } -bincode = "1.3.3" diff --git a/terminal/display_server/src/main.rs b/terminal/display_server/src/main.rs deleted file mode 100644 index a3f52fc..0000000 --- a/terminal/display_server/src/main.rs +++ /dev/null @@ -1,67 +0,0 @@ -use { - cgmath::{Point2, Vector2}, - nested::terminal::{TerminalAtom, TerminalStyle}, - std::io::{stdout, Read, Write}, - termion::raw::IntoRawMode, -}; - -fn main() { - let mut out = stdout().into_raw_mode().unwrap(); - write!( - out, - "{}{}{}", - termion::cursor::Hide, - termion::cursor::Goto(1, 1), - termion::style::Reset - ) - .unwrap(); - - let mut cur_pos = Point2::::new(0, 0); - let mut cur_style = TerminalStyle::default(); - - let mut input = std::io::stdin(); - - loop { - match bincode::deserialize_from::<_, (Point2, Option)>(input.by_ref()) { - Ok((pos, atom)) => { - if pos != cur_pos { - write!( - out, - "{}", - termion::cursor::Goto(pos.x as u16 + 1, pos.y as u16 + 1) - ) - .unwrap(); - } - - if let Some(atom) = atom { - if cur_style != atom.style { - cur_style = atom.style; - write!(out, "{}", atom.style).expect(""); - } - - write!(out, "{}", atom.c.unwrap_or(' ')).expect(""); - } else { - write!(out, "{} ", termion::style::Reset).expect(""); - cur_style = TerminalStyle::default(); - } - - cur_pos = pos + Vector2::new(1, 0); - - out.flush().unwrap(); - } - Err(err) => { - match *err { - bincode::ErrorKind::Io(_io_error) => break, - err => { - eprintln!("deserialization error\n{:?}", err); - } - } - break; - } - } - } - - // restore conventional terminal settings - write!(out, "{}", termion::cursor::Show).unwrap(); - out.flush().unwrap(); -}