From 0edbd748a5767e4bd916f683bf3fd0f3724f2642 Mon Sep 17 00:00:00 2001 From: Michael Sippel Date: Mon, 2 Jan 2023 18:49:32 +0100 Subject: [PATCH] further file renaming --- nested/src/{char_editor.rs => char/mod.rs} | 3 +- nested/src/commander.rs | 31 ++++++++++++++ nested/src/core/observer.rs | 2 +- nested/src/integer/editor.rs | 2 +- nested/src/lib.rs | 41 ++----------------- nested/src/list/editor.rs | 5 +-- nested/src/list/nav.rs | 4 +- nested/src/list/pty_editor.rs | 2 +- nested/src/list/segment.rs | 20 ++++----- nested/src/path/mod.rs | 10 ----- nested/src/product/editor.rs | 4 +- nested/src/product/nav.rs | 2 +- nested/src/product/segment.rs | 2 +- nested/src/sum/editor.rs | 2 +- .../src/{ => terminal/widgets}/ascii_box.rs | 0 nested/src/{ => terminal/widgets}/monstera.rs | 0 nested/src/{ => terminal/widgets}/plot.rs | 0 nested/src/tree/node.rs | 2 +- nested/src/{ => type_system}/make_editor.rs | 4 +- nested/src/type_system/mod.rs | 4 ++ nested/src/type_system/type_term.rs | 2 +- .../src/{ => type_system}/type_term_editor.rs | 5 ++- nested/src/{ => utils}/bimap.rs | 0 nested/src/{ => utils}/color.rs | 0 nested/src/utils/mod.rs | 6 +++ nested/src/{ => utils}/modulo.rs | 0 shell/src/incubator.rs | 18 ++++++++ shell/src/main.rs | 13 +++--- 28 files changed, 96 insertions(+), 88 deletions(-) rename nested/src/{char_editor.rs => char/mod.rs} (97%) create mode 100644 nested/src/commander.rs delete mode 100644 nested/src/path/mod.rs rename nested/src/{ => terminal/widgets}/ascii_box.rs (100%) rename nested/src/{ => terminal/widgets}/monstera.rs (100%) rename nested/src/{ => terminal/widgets}/plot.rs (100%) rename nested/src/{ => type_system}/make_editor.rs (99%) rename nested/src/{ => type_system}/type_term_editor.rs (98%) rename nested/src/{ => utils}/bimap.rs (100%) rename nested/src/{ => utils}/color.rs (100%) create mode 100644 nested/src/utils/mod.rs rename nested/src/{ => utils}/modulo.rs (100%) create mode 100644 shell/src/incubator.rs diff --git a/nested/src/char_editor.rs b/nested/src/char/mod.rs similarity index 97% rename from nested/src/char_editor.rs rename to nested/src/char/mod.rs index 8a1e22d..53ab476 100644 --- a/nested/src/char_editor.rs +++ b/nested/src/char/mod.rs @@ -4,7 +4,8 @@ use { type_system::{Context}, singleton::{SingletonBuffer, SingletonView}, terminal::{TerminalAtom, TerminalEvent, TerminalStyle}, - tree::NestedNode, Commander + tree::NestedNode, + commander::Commander }, std::sync::Arc, std::sync::RwLock, diff --git a/nested/src/commander.rs b/nested/src/commander.rs new file mode 100644 index 0000000..a274d2a --- /dev/null +++ b/nested/src/commander.rs @@ -0,0 +1,31 @@ + +pub trait Commander { + type Cmd; + + fn send_cmd(&mut self, cmd: &Self::Cmd); +} + +use std::sync::{Arc, RwLock}; +use crate::{ + type_system::ReprTree, + singleton::SingletonView +}; + +pub trait ObjCommander { + fn send_cmd_obj(&mut self, cmd_obj: Arc>); +} + +//impl> ObjCommander for T { +impl ObjCommander for C +where C::Cmd: 'static +{ + fn send_cmd_obj(&mut self, cmd_obj: Arc>) { + self.send_cmd( + &cmd_obj.read().unwrap() + .get_port::>().unwrap() + .get_view().unwrap() + .get() + ); + } +} + diff --git a/nested/src/core/observer.rs b/nested/src/core/observer.rs index f1b848d..510f44f 100644 --- a/nested/src/core/observer.rs +++ b/nested/src/core/observer.rs @@ -43,7 +43,7 @@ impl> ObserverExt for T { } } -/*\ + /*\ <<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>> Broadcast <<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>> diff --git a/nested/src/integer/editor.rs b/nested/src/integer/editor.rs index 6d99f57..62ed0e9 100644 --- a/nested/src/integer/editor.rs +++ b/nested/src/integer/editor.rs @@ -15,7 +15,7 @@ use { diagnostics::{Diagnostics, Message}, tree::NestedNode, Nested, - Commander + commander::Commander }, std::sync::Arc, std::sync::RwLock, diff --git a/nested/src/lib.rs b/nested/src/lib.rs index 0ed80a3..f7b4da6 100644 --- a/nested/src/lib.rs +++ b/nested/src/lib.rs @@ -4,10 +4,8 @@ pub mod core; pub mod type_system; pub mod projection; -pub mod bimap; -pub mod modulo; -pub use modulo::modulo; - +pub mod commander; +pub mod utils; // semantics pub mod singleton; @@ -26,49 +24,16 @@ pub mod tree; pub mod diagnostics; // high-level types -pub mod char_editor; +pub mod char; pub mod integer; -pub mod make_editor; -pub mod type_term_editor; // display -pub mod color; pub mod terminal; pub fn magic_header() { eprintln!("<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>>"); } -pub trait Commander { - type Cmd; - - fn send_cmd(&mut self, cmd: &Self::Cmd); -} - -use std::sync::{Arc, RwLock}; -use crate::{ - type_system::ReprTree, - singleton::SingletonView -}; - -pub trait ObjCommander { - fn send_cmd_obj(&mut self, cmd_obj: Arc>); -} - -//impl> ObjCommander for T { -impl ObjCommander for C -where C::Cmd: 'static -{ - fn send_cmd_obj(&mut self, cmd_obj: Arc>) { - self.send_cmd( - &cmd_obj.read().unwrap() - .get_port::>().unwrap() - .get_view().unwrap() - .get() - ); - } -} - pub trait StringGen { fn get_string(&self) -> String; } diff --git a/nested/src/list/editor.rs b/nested/src/list/editor.rs index 6f38e2e..7a456f0 100644 --- a/nested/src/list/editor.rs +++ b/nested/src/list/editor.rs @@ -67,7 +67,7 @@ impl ListEditor { pub fn get_item(&self) -> Option { if let Some(idx) = self.cursor.get().idx { - let idx = crate::modulo(idx as isize, self.data.len() as isize) as usize; + let idx = crate::utils::modulo(idx as isize, self.data.len() as isize) as usize; if idx < self.data.len() { Some(self.data.get(idx)) } else { @@ -79,7 +79,7 @@ impl ListEditor { } pub fn get_item_mut(&mut self) -> Option> { if let Some(idx) = self.cursor.get().idx { - let idx = crate::modulo(idx as isize, self.data.len() as isize) as usize; + let idx = crate::utils::modulo(idx as isize, self.data.len() as isize) as usize; if idx < self.data.len() { Some(self.data.get_mut(idx)) } else { @@ -108,4 +108,3 @@ impl ListEditor { self.data.clear(); } } - diff --git a/nested/src/list/nav.rs b/nested/src/list/nav.rs index 7926a8c..d2d2a2a 100644 --- a/nested/src/list/nav.rs +++ b/nested/src/list/nav.rs @@ -98,7 +98,7 @@ impl TreeNav for ListEditor { TreeNavResult::Continue } 1 => { - let idx = crate::modulo(new_cur.tree_addr[0], if new_cur.leaf_mode == ListCursorMode::Insert { 1 } else { 0 } + self.data.len() as isize); + let idx = crate::utils::modulo(new_cur.tree_addr[0], if new_cur.leaf_mode == ListCursorMode::Insert { 1 } else { 0 } + self.data.len() as isize); self.cursor.set(ListCursor { mode: new_cur.leaf_mode, @@ -118,7 +118,7 @@ impl TreeNav for ListEditor { } _ => { if self.data.len() > 0 { - let idx = crate::modulo(new_cur.tree_addr[0], self.data.len() as isize); + let idx = crate::utils::modulo(new_cur.tree_addr[0], self.data.len() as isize); self.cursor.set(ListCursor { mode: ListCursorMode::Select, diff --git a/nested/src/list/pty_editor.rs b/nested/src/list/pty_editor.rs index cc499c3..d1d5286 100644 --- a/nested/src/list/pty_editor.rs +++ b/nested/src/list/pty_editor.rs @@ -14,7 +14,7 @@ use { tree::{TreeCursor, TreeNav, TreeNavResult}, diagnostics::{Diagnostics}, tree::NestedNode, Nested, - Commander + commander::Commander }, std::sync::{Arc, RwLock}, termion::event::{Event, Key}, diff --git a/nested/src/list/segment.rs b/nested/src/list/segment.rs index e400672..fa22663 100644 --- a/nested/src/list/segment.rs +++ b/nested/src/list/segment.rs @@ -7,15 +7,14 @@ use { singleton::SingletonView, terminal::{TerminalView, TerminalStyle, make_label}, tree::{NestedNode, TreeNav}, - color::{bg_style_from_depth, fg_style_from_depth}, + utils::color::{bg_style_from_depth, fg_style_from_depth}, PtySegment }, std::sync::Arc, std::sync::RwLock, }; -pub enum ListSegment -{ +pub enum ListSegment { InsertCursor, Item { editor: NestedNode, @@ -24,8 +23,7 @@ pub enum ListSegment } } -impl PtySegment for ListSegment -{ +impl PtySegment for ListSegment { fn pty_view(&self) -> OuterViewPort { match self { ListSegment::InsertCursor => { @@ -58,8 +56,7 @@ impl PtySegment for ListSegment } } -pub struct ListSegmentSequence -{ +pub struct ListSegmentSequence { data: Arc>, cursor: Arc>, @@ -71,13 +68,11 @@ pub struct ListSegmentSequence proj_helper: ProjectionHelper, } -impl View for ListSegmentSequence -{ +impl View for ListSegmentSequence { type Msg = usize; } -impl SequenceView for ListSegmentSequence -{ +impl SequenceView for ListSegmentSequence { type Item = ListSegment; fn len(&self) -> Option { @@ -128,8 +123,7 @@ impl SequenceView for ListSegmentSequence } } -impl ListSegmentSequence -{ +impl ListSegmentSequence { pub fn new( cursor_port: OuterViewPort>, data_port: OuterViewPort>, diff --git a/nested/src/path/mod.rs b/nested/src/path/mod.rs deleted file mode 100644 index a00124b..0000000 --- a/nested/src/path/mod.rs +++ /dev/null @@ -1,10 +0,0 @@ - -pub struct PathSegmentEditor { - parent: Path, - -} - -pub struct PathEditor { - -} - diff --git a/nested/src/product/editor.rs b/nested/src/product/editor.rs index 4ea4bbb..e44cd63 100644 --- a/nested/src/product/editor.rs +++ b/nested/src/product/editor.rs @@ -86,7 +86,7 @@ impl ProductEditor { } pub fn get_editor_segment(&self, mut idx: isize) -> ProductEditorSegment { - idx = crate::modulo(idx, self.n_indices.len() as isize); + idx = crate::utils::modulo(idx, self.n_indices.len() as isize); if let Some(pos) = self.n_indices.get(idx as usize) { self.segments.get(pos).unwrap() } else { @@ -95,7 +95,7 @@ impl ProductEditor { } pub fn get_editor_segment_mut(&mut self, mut idx: isize) -> MutableIndexAccess, ProductEditorSegment> { - idx = crate::modulo(idx, self.n_indices.len() as isize); + idx = crate::utils::modulo(idx, self.n_indices.len() as isize); if let Some(pos) = self.n_indices.get(idx as usize) { self.segments.get_mut(pos) } else { diff --git a/nested/src/product/nav.rs b/nested/src/product/nav.rs index 01456e4..5a6c073 100644 --- a/nested/src/product/nav.rs +++ b/nested/src/product/nav.rs @@ -63,7 +63,7 @@ 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)); + self.cursor = Some(crate::utils::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 { diff --git a/nested/src/product/segment.rs b/nested/src/product/segment.rs index 30d4851..d1a883f 100644 --- a/nested/src/product/segment.rs +++ b/nested/src/product/segment.rs @@ -6,7 +6,7 @@ use { TerminalStyle, TerminalView, make_label }, - color::{bg_style_from_depth, fg_style_from_depth}, + utils::color::{bg_style_from_depth, fg_style_from_depth}, tree::{NestedNode, TreeNav} }, std::{sync::{Arc, RwLock}}, diff --git a/nested/src/sum/editor.rs b/nested/src/sum/editor.rs index 6712e4f..bc3ddf0 100644 --- a/nested/src/sum/editor.rs +++ b/nested/src/sum/editor.rs @@ -9,7 +9,7 @@ use { tree::{TreeNav, TreeCursor, TreeNavResult}, diagnostics::{Diagnostics, Message}, tree::NestedNode, - Commander, + commander::Commander, PtySegment }, cgmath::{Vector2}, diff --git a/nested/src/ascii_box.rs b/nested/src/terminal/widgets/ascii_box.rs similarity index 100% rename from nested/src/ascii_box.rs rename to nested/src/terminal/widgets/ascii_box.rs diff --git a/nested/src/monstera.rs b/nested/src/terminal/widgets/monstera.rs similarity index 100% rename from nested/src/monstera.rs rename to nested/src/terminal/widgets/monstera.rs diff --git a/nested/src/plot.rs b/nested/src/terminal/widgets/plot.rs similarity index 100% rename from nested/src/plot.rs rename to nested/src/terminal/widgets/plot.rs diff --git a/nested/src/tree/node.rs b/nested/src/tree/node.rs index 07a3edb..724db8f 100644 --- a/nested/src/tree/node.rs +++ b/nested/src/tree/node.rs @@ -9,7 +9,7 @@ use { terminal::{TerminalView, TerminalEvent, TerminalEditor, TerminalEditorResult}, diagnostics::{Diagnostics, Message}, tree::{TreeNav, TreeCursor, TreeNavResult}, - ObjCommander, + commander::ObjCommander, Nested } }; diff --git a/nested/src/make_editor.rs b/nested/src/type_system/make_editor.rs similarity index 99% rename from nested/src/make_editor.rs rename to nested/src/type_system/make_editor.rs index ee7378b..74b7aa7 100644 --- a/nested/src/make_editor.rs +++ b/nested/src/type_system/make_editor.rs @@ -5,8 +5,8 @@ use { list::{PTYListEditor}, sequence::{decorator::{SeqDecorStyle}}, sum::SumEditor, - char_editor::CharEditor, - type_term_editor::TypeTermEditor, + char::CharEditor, + type_system::TypeTermEditor, Nested }, std::sync::{Arc, RwLock}, diff --git a/nested/src/type_system/mod.rs b/nested/src/type_system/mod.rs index 72e2db3..5df9a61 100644 --- a/nested/src/type_system/mod.rs +++ b/nested/src/type_system/mod.rs @@ -1,10 +1,14 @@ pub mod type_term; pub mod repr_tree; pub mod context; +pub mod make_editor; +pub mod type_term_editor; pub use { repr_tree::{ReprTree}, type_term::{TypeDict, TypeID, TypeTerm, TypeLadder}, context::{Context, MorphismMode, MorphismType}, + type_term_editor::TypeTermEditor, + make_editor::* }; diff --git a/nested/src/type_system/type_term.rs b/nested/src/type_system/type_term.rs index d56a8e3..b153177 100644 --- a/nested/src/type_system/type_term.rs +++ b/nested/src/type_system/type_term.rs @@ -1,4 +1,4 @@ -use {crate::bimap::Bimap, std::collections::HashMap}; +use {crate::utils::Bimap, std::collections::HashMap}; //<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>> diff --git a/nested/src/type_term_editor.rs b/nested/src/type_system/type_term_editor.rs similarity index 98% rename from nested/src/type_term_editor.rs rename to nested/src/type_system/type_term_editor.rs index 87eb5b9..6c1881d 100644 --- a/nested/src/type_term_editor.rs +++ b/nested/src/type_system/type_term_editor.rs @@ -8,10 +8,11 @@ use { tree::{TreeNav, TreeCursor, TreeNavResult}, diagnostics::{Diagnostics, Message}, sum::SumEditor, - char_editor::CharEditor, + char::CharEditor, integer::PosIntEditor, tree::NestedNode, - Commander, PtySegment + commander::Commander, + PtySegment }, cgmath::{Vector2}, termion::event::{Key}, diff --git a/nested/src/bimap.rs b/nested/src/utils/bimap.rs similarity index 100% rename from nested/src/bimap.rs rename to nested/src/utils/bimap.rs diff --git a/nested/src/color.rs b/nested/src/utils/color.rs similarity index 100% rename from nested/src/color.rs rename to nested/src/utils/color.rs diff --git a/nested/src/utils/mod.rs b/nested/src/utils/mod.rs new file mode 100644 index 0000000..fe10469 --- /dev/null +++ b/nested/src/utils/mod.rs @@ -0,0 +1,6 @@ +pub mod bimap; +pub mod modulo; +pub mod color; + +pub use modulo::modulo; +pub use bimap::Bimap; diff --git a/nested/src/modulo.rs b/nested/src/utils/modulo.rs similarity index 100% rename from nested/src/modulo.rs rename to nested/src/utils/modulo.rs diff --git a/shell/src/incubator.rs b/shell/src/incubator.rs new file mode 100644 index 0000000..5143489 --- /dev/null +++ b/shell/src/incubator.rs @@ -0,0 +1,18 @@ + +use { + nested::commander::Commander, + nested::terminal::TerminalEvent +}; + +struct Incubator { + +} + +impl Commander for Incubator { + type Cmd = TerminalEvent; + + fn send_cmd(&mut self, cmd: &TerminalEvent) { + + } +} + diff --git a/shell/src/main.rs b/shell/src/main.rs index b1c56c5..80369af 100644 --- a/shell/src/main.rs +++ b/shell/src/main.rs @@ -1,6 +1,7 @@ extern crate portable_pty; mod pty; +mod incubator; // TODO rewrite process & command with incubator rules //mod process; @@ -22,7 +23,7 @@ use { vec::VecBuffer, diagnostics::{Diagnostics}, index::{buffer::IndexBuffer}, - Commander + commander::Commander }, std::sync::{Arc, RwLock}, termion::event::{Event, Key}, @@ -55,10 +56,10 @@ async fn main() { // Type Context // let ctx = Arc::new(RwLock::new(Context::new())); - let ctx = nested::make_editor::init_mem_ctx(ctx); - let ctx = nested::make_editor::init_editor_ctx(ctx); - let ctx = nested::make_editor::init_math_ctx(ctx); - let ctx = nested::make_editor::init_os_ctx(ctx); + let ctx = nested::type_system::init_mem_ctx(ctx); + let ctx = nested::type_system::init_editor_ctx(ctx); + let ctx = nested::type_system::init_math_ctx(ctx); + let ctx = nested::type_system::init_os_ctx(ctx); let vb = VecBuffer::::new(); let rt_char = ReprTree::new_leaf( @@ -237,7 +238,6 @@ async fn main() { tree_addr: vec![0], }); - loop { let ev = term.next_event().await; let _l = portmutex.write().unwrap(); @@ -248,7 +248,6 @@ async fn main() { continue; } - /* if let Some(process_editor) = process_list_editor.get_item() { let mut pe = process_editor.write().unwrap();