From 4e02b41a772d7ca92fdc517a0455248c7251f227 Mon Sep 17 00:00:00 2001 From: Michael Sippel Date: Fri, 12 Aug 2022 18:57:40 +0200 Subject: [PATCH] shell: first commander prototype --- nested/src/char_editor.rs | 4 + nested/src/color.rs | 21 ++-- nested/src/integer/editor.rs | 3 +- nested/src/list/editor.rs | 6 +- nested/src/list/nav.rs | 1 + nested/src/list/pty_editor.rs | 28 +++++- nested/src/list/segment.rs | 2 +- nested/src/make_editor.rs | 17 ++-- nested/src/product/editor.rs | 11 +- nested/src/product/nav.rs | 35 +++++-- nested/src/product/segment.rs | 10 +- nested/src/terminal/terminal.rs | 1 + shell/src/command.rs | 172 ++++++++++++++++---------------- shell/src/main.rs | 49 ++++++--- 14 files changed, 220 insertions(+), 140 deletions(-) diff --git a/nested/src/char_editor.rs b/nested/src/char_editor.rs index 4cd771e..7b235f4 100644 --- a/nested/src/char_editor.rs +++ b/nested/src/char_editor.rs @@ -30,6 +30,10 @@ impl CharEditor { pub fn get_port(&self) -> OuterViewPort>> { self.data.get_port() } + + pub fn get(&self) -> char { + self.get_port().get_view().unwrap().get().unwrap_or('?') + } } impl TreeNav for CharEditor {} diff --git a/nested/src/color.rs b/nested/src/color.rs index e592626..08aaec7 100644 --- a/nested/src/color.rs +++ b/nested/src/color.rs @@ -3,22 +3,23 @@ use { }; pub fn bg_style_from_depth(depth: usize) -> TerminalStyle { - if depth == 0 { - TerminalStyle::default() - } else { - TerminalStyle::bg_color(( - (30.0 / ( 0.90*depth as f64 )) as u8, - (30.0 / ( 0.93*depth as f64 )) as u8, - (50.0 / ( 0.95*depth as f64 )) as u8 - )) + match depth { + 0 => TerminalStyle::default(), + 1 => TerminalStyle::bg_color((20,20,20)), + 2 => TerminalStyle::default(), + 3 => TerminalStyle::default(), + 4 => TerminalStyle::default(), + 5 => TerminalStyle::default(), + _ => TerminalStyle::bg_color((80,80,80)) } } pub fn fg_style_from_depth(depth: usize) -> TerminalStyle { match depth % 3 { 0 => TerminalStyle::fg_color((200, 200, 80)), - 1 => TerminalStyle::fg_color((80, 200, 200)), - 2 => TerminalStyle::fg_color((150, 150, 200)), + 1 => TerminalStyle::fg_color((80, 200, 200)).add(TerminalStyle::bold(true)), + 2 => TerminalStyle::fg_color((80, 80, 200)), + 3 => TerminalStyle::fg_color((200, 80, 200)), _ => TerminalStyle::default() } } diff --git a/nested/src/integer/editor.rs b/nested/src/integer/editor.rs index a2c8231..fe5d194 100644 --- a/nested/src/integer/editor.rs +++ b/nested/src/integer/editor.rs @@ -87,7 +87,7 @@ impl PosIntEditor { PosIntEditor { radix, digits_editor: PTYListEditor::new( - Box::new(move || Arc::new(RwLock::new(DigitEditor::new(radix)))), + Box::new(move || Arc::new(RwLock::new(DigitEditor::new(radix)))) as Box Arc> + Send + Sync>, SeqDecorStyle::Hex, 0 ), @@ -136,7 +136,6 @@ impl TreeNav for PosIntEditor { fn goby(&mut self, cur: Vector2) -> TreeNavResult { self.digits_editor.goby(cur) } - } impl TerminalEditor for PosIntEditor { diff --git a/nested/src/list/editor.rs b/nested/src/list/editor.rs index 39fd85c..80a58cf 100644 --- a/nested/src/list/editor.rs +++ b/nested/src/list/editor.rs @@ -36,11 +36,11 @@ where ItemEditor: TerminalTreeEditor + ?Sized + Send + Sync + 'static impl ListEditor where ItemEditor: TerminalTreeEditor + ?Sized + Send + Sync + 'static { - pub fn new(make_item_editor: impl Into Arc> + Send + Sync>>, depth: usize) -> Self { + pub fn new(make_item_editor: impl Fn() -> Arc> + Send + Sync + 'static, depth: usize) -> Self { ListEditor { cursor: SingletonBuffer::new(ListCursor::default()), data: VecBuffer::>>::new(), - make_item_editor: make_item_editor.into(), + make_item_editor: Box::new(make_item_editor), depth, cur_dist: Arc::new(RwLock::new(0)), } @@ -58,7 +58,7 @@ where ItemEditor: TerminalTreeEditor + ?Sized + Send + Sync + 'static ); segment_view_port.into_outer().map(move |segment| segment.pty_view()) } - + pub fn get_data_port(&self) -> OuterViewPort>>> { self.data.get_port().to_sequence() } diff --git a/nested/src/list/nav.rs b/nested/src/list/nav.rs index 23acb48..d6228f0 100644 --- a/nested/src/list/nav.rs +++ b/nested/src/list/nav.rs @@ -133,6 +133,7 @@ where ItemEditor: TerminalTreeEditor + ?Sized + Send + Sync + 'static if direction.y < 0 { // up + self.cursor.set(ListCursor::none()); TreeNavResult::Exit } else if direction.y > 0 { // dn diff --git a/nested/src/list/pty_editor.rs b/nested/src/list/pty_editor.rs index f3f0a8d..91e729c 100644 --- a/nested/src/list/pty_editor.rs +++ b/nested/src/list/pty_editor.rs @@ -36,7 +36,7 @@ impl PTYListEditor where ItemEditor: TerminalTreeEditor + ?Sized + Send + Sync + 'static { pub fn new( - make_item_editor: Box Arc> + Send + Sync>, + make_item_editor: impl Fn() -> Arc> + Send + Sync + 'static, style: SeqDecorStyle, depth: usize ) -> Self { @@ -49,6 +49,20 @@ where ItemEditor: TerminalTreeEditor + ?Sized + Send + Sync + 'static } } + pub fn from_editor( + editor: ListEditor, + style: SeqDecorStyle, + depth: usize + ) -> Self { + let port = ViewPort::new(); + PTYListEditor { + editor, + style, + depth, + port + } + } + pub fn get_data_port(&self) -> OuterViewPort>>> { self.editor.get_data_port() } @@ -206,3 +220,15 @@ impl TerminalTreeEditor for PTYListEditor where ItemEditor: TerminalTreeEditor + ?Sized + Send + Sync + 'static {} + +use crate::{ + char_editor::CharEditor, + sequence::SequenceViewExt +}; + +impl PTYListEditor { + pub fn get_string(&self) -> String { + self.get_data_port().map(|ce| ce.read().unwrap().get()).get_view().unwrap().iter().collect::() + } +} + diff --git a/nested/src/list/segment.rs b/nested/src/list/segment.rs index 7ff7276..ef0a147 100644 --- a/nested/src/list/segment.rs +++ b/nested/src/list/segment.rs @@ -46,7 +46,7 @@ where ItemEditor: TerminalTreeEditor + ?Sized + Send + Sync + 'static editor.read().unwrap().get_term_view().map_item(move |_pt, atom| { let cur_depth = e.read().unwrap().get_cursor().tree_addr.len(); atom.add_style_back(bg_style_from_depth(cur_depth)) - .add_style_back(fg_style_from_depth(d+cur_depth)) + .add_style_back(fg_style_from_depth(d)) }) } } diff --git a/nested/src/make_editor.rs b/nested/src/make_editor.rs index b489164..e807b66 100644 --- a/nested/src/make_editor.rs +++ b/nested/src/make_editor.rs @@ -76,13 +76,13 @@ pub fn make_editor(ctx: Arc>, t: &TypeLadder, depth: usize) -> A } else if t[0] == c.type_term_from_str("( List RGB )").unwrap() { Arc::new(RwLock::new( PTYListEditor::::new( - Box::new({ + { let d = depth+1; let ctx = ctx.clone(); - move || { + Box::new(move || { make_editor(ctx.clone(), &vec![ ctx.read().unwrap().type_term_from_str("( RGB )").unwrap() ], d) - } - }), + }) + }, SeqDecorStyle::VerticalSexpr, depth ) @@ -97,7 +97,7 @@ pub fn make_editor(ctx: Arc>, t: &TypeLadder, depth: usize) -> A .with_n(Point2::new(2, 2), vec![ ctx.read().unwrap().type_term_from_str("( PosInt 16 BigEndian )").unwrap() ] ) .with_t(Point2::new(1, 3), "b: ") .with_n(Point2::new(2, 3), vec![ ctx.read().unwrap().type_term_from_str("( PosInt 16 BigEndian )").unwrap() ] ) - .with_t(Point2::new(0, 4), " }") + .with_t(Point2::new(0, 4), "}") )) as Arc> } else if t[0] == c.type_term_from_str("( Vec3i )").unwrap() { @@ -109,7 +109,7 @@ pub fn make_editor(ctx: Arc>, t: &TypeLadder, depth: usize) -> A .with_n(Point2::new(2, 2), vec![ ctx.read().unwrap().type_term_from_str("( PosInt 10 BigEndian )").unwrap() ] ) .with_t(Point2::new(1, 3), "z: ") .with_n(Point2::new(2, 3), vec![ ctx.read().unwrap().type_term_from_str("( PosInt 10 BigEndian )").unwrap() ] ) - .with_t(Point2::new(0, 4), " }") + .with_t(Point2::new(0, 4), "}") )) as Arc> } else if t[0] == c.type_term_from_str("( Json )").unwrap() { @@ -147,14 +147,13 @@ pub fn make_editor(ctx: Arc>, t: &TypeLadder, depth: usize) -> A } else { // else: term Arc::new(RwLock::new( PTYListEditor::new( - Box::new(|| { + || { Arc::new(RwLock::new(CharEditor::new())) - }), + }, SeqDecorStyle::DoubleQuote, depth ) )) - } } diff --git a/nested/src/product/editor.rs b/nested/src/product/editor.rs index d1e75a8..2b9db9f 100644 --- a/nested/src/product/editor.rs +++ b/nested/src/product/editor.rs @@ -119,10 +119,11 @@ impl TerminalEditor for ProductEditor { match event { TerminalEvent::Input(Event::Key(Key::Backspace)) => { *editor = None; - *cur_depth -= 1; + *cur_depth = 1; TerminalEditorResult::Continue } _ => { + *cur_depth = ce.get_cursor().tree_addr.len(); drop(ce); match self.nexd() { TreeNavResult::Continue => TerminalEditorResult::Continue, @@ -130,15 +131,17 @@ impl TerminalEditor for ProductEditor { } } }, - TerminalEditorResult::Continue => - TerminalEditorResult::Continue + TerminalEditorResult::Continue => { + *cur_depth = ce.get_cursor().tree_addr.len(); + TerminalEditorResult::Continue + } } } else { let e = make_editor(self.ctx.clone(), t, self.depth+1); *editor = Some(e.clone()); e.write().unwrap().dn(); let x = e.write().unwrap().handle_terminal_event(event); - *cur_depth = self.get_cursor().tree_addr.len()+1; + *cur_depth = e.write().unwrap().get_cursor().tree_addr.len(); x } } else { diff --git a/nested/src/product/nav.rs b/nested/src/product/nav.rs index f831e8e..803e9b2 100644 --- a/nested/src/product/nav.rs +++ b/nested/src/product/nav.rs @@ -66,9 +66,15 @@ impl TreeNav for ProductEditor { self.cursor = Some(crate::modulo(c.tree_addr.remove(0), self.n_indices.len() as isize)); if let Some(mut element) = self.get_cur_segment_mut() { - if let Some(ProductEditorSegment::N{ t: _t, editor, cur_depth }) = element.deref_mut() { + if let Some(ProductEditorSegment::N{ t, editor, cur_depth }) = element.deref_mut() { if let Some(e) = editor { e.write().unwrap().goto(c.clone()); + } else if c.tree_addr.len() > 0 { + // create editor + let e = make_editor(self.ctx.clone(), t, self.depth+1); + *editor = Some(e.clone()); + let mut e = e.write().unwrap(); + e.goto(c.clone()); } *cur_depth = c.tree_addr.len(); } @@ -111,7 +117,7 @@ impl TreeNav for ProductEditor { if let Some(e) = editor { let mut e = e.write().unwrap(); e.goby(direction); - *cur_depth = e.get_cursor().tree_addr.len(); + *cur_depth = e.get_cursor().tree_addr.len() + 1; } else { // create editor let e = make_editor(self.ctx.clone(), t, self.depth+1); @@ -133,6 +139,12 @@ impl TreeNav for ProductEditor { self.cursor = None; TreeNavResult::Exit } else { + if let Some(mut element) = self.get_cur_segment_mut() { + if let Some(ProductEditorSegment::N{ t, editor, cur_depth }) = element.deref_mut() { + *cur_depth = 0; + } + } + // horizontal if (cur.tree_addr[0]+direction.x >= 0) && (cur.tree_addr[0]+direction.x < self.n_indices.len() as isize) @@ -142,6 +154,7 @@ impl TreeNav for ProductEditor { *cur_depth = 0; } } + self.cursor = Some(cur.tree_addr[0] + direction.x); if let Some(mut element) = self.get_cur_segment_mut() { if let Some(ProductEditorSegment::N{ t, editor, cur_depth }) = element.deref_mut() { @@ -165,21 +178,31 @@ impl TreeNav for ProductEditor { //\\//\\//\\//\\ match ce.goby(direction) { TreeNavResult::Exit => { - *cur_depth = 0; + *cur_depth = 1; drop(ce); drop(e); + if direction.y < 0 { if depth <= (1-direction.y) as usize { // up - TreeNavResult::Exit + *cur_depth = 1; + TreeNavResult::Continue } else { + panic!("unplausible direction.y on exit"); TreeNavResult::Continue } } else if direction.y > 0 { // dn + *cur_depth = depth + direction.y as usize; + TreeNavResult::Continue } else if direction.y == 0 { // horizontal + + if direction.x != 0 { + *cur_depth = 0; + } + if (cur.tree_addr[0]+direction.x >= 0) && (cur.tree_addr[0]+direction.x < self.n_indices.len() as isize) { @@ -205,9 +228,7 @@ impl TreeNav for ProductEditor { } } TreeNavResult::Continue => { - if direction.y > 0 { - *cur_depth = depth + direction.y as usize - 1; - } + *cur_depth = (depth as isize + direction.y - 1) as usize; TreeNavResult::Continue } } diff --git a/nested/src/product/segment.rs b/nested/src/product/segment.rs index bc87e0f..b984a69 100644 --- a/nested/src/product/segment.rs +++ b/nested/src/product/segment.rs @@ -37,16 +37,20 @@ impl ProductEditorSegment { ProductEditorSegment::N { t: _, editor: Some(e), cur_depth } => e.read().unwrap() .get_term_view() - .map_item({ let cur_depth = *cur_depth;//e.read().unwrap().get_cursor().tree_addr.len()+1; - move |i, x| x + .map_item({ + let e = e.clone(); + move |i, x| { + let cur_depth = e.read().unwrap().get_cursor().tree_addr.len(); + x .add_style_back(fg_style_from_depth(cur_depth))//fg_color((250,210,0))) .add_style_back(bg_style_from_depth(cur_depth)) + } }), ProductEditorSegment::N{ t, editor: None, cur_depth } => make_label(&ctx.read().unwrap().type_term_to_str(&t[0])) .map_item({ - let cur_depth = *cur_depth; + let cur_depth = 0; move |i, x| x .add_style_back(TerminalStyle::fg_color((130,90,40))) .add_style_back(bg_style_from_depth(cur_depth)) diff --git a/nested/src/terminal/terminal.rs b/nested/src/terminal/terminal.rs index 2ef265f..8c3e76d 100644 --- a/nested/src/terminal/terminal.rs +++ b/nested/src/terminal/terminal.rs @@ -24,6 +24,7 @@ use { }, }; +#[derive(PartialEq, Eq)] pub enum TerminalEvent { Resize(Vector2), Input(termion::event::Event), diff --git a/shell/src/command.rs b/shell/src/command.rs index b408f4c..359fb28 100644 --- a/shell/src/command.rs +++ b/shell/src/command.rs @@ -3,81 +3,107 @@ use { sync::{Arc, RwLock}, collections::HashMap }, - cgmath::{Point2}, + cgmath::{Vector2, Point2}, termion::event::{Event, Key}, nested::{ - list::{sexpr::ListDecoration, ListEditor, ListEditorStyle}, - core::TypeTerm, + vec::VecBuffer, + list::{ListEditor, PTYListEditor}, + sequence::decorator::{Separate, Wrap, SeqDecorStyle}, + core::{TypeTerm, Context}, core::{OuterViewPort, ViewPort}, index::{IndexArea, IndexView}, - string_editor::StringEditor, - vec::VecBuffer, + char_editor::CharEditor, terminal::{ TerminalAtom, TerminalEditor, TerminalEditorResult, TerminalEvent, TerminalStyle, TerminalView, make_label }, - tree_nav::{TreeCursor, TreeNav, TreeNavResult}, + tree_nav::{TreeCursor, TreeNav, TreeNavResult, TerminalTreeEditor}, + make_editor::make_editor, + product::ProductEditor } }; trait Action { - fn make_editor(&self) -> - (Arc>, - Arc>); + fn make_editor(&self, ctx: Arc>) -> Arc>; } pub struct ActCd {} impl Action for ActCd { - fn make_editor(&self) -> - (Arc>, - Arc>) - { - let ed = - Arc::new(RwLock::new(ListEditor::new( - Box::new(|| { - Arc::new(RwLock::new(StringEditor::new())) - }) as Box Arc> + Send + Sync>, - ListEditorStyle::HorizontalSexpr, - ))); - //Arc::new(RwLock::new(StringEditor::new())); - - (ed.clone() as Arc>, ed as Arc>) + fn make_editor(&self, ctx: Arc>) -> Arc> { + make_editor( + ctx.clone(), + &vec![ctx.read().unwrap().type_term_from_str("( Path )").unwrap()], + 1 + ) } } +pub struct ActEcho {} +impl Action for ActEcho { + fn make_editor(&self, ctx: Arc>) -> Arc> { + make_editor( + ctx.clone(), + &vec![ctx.read().unwrap().type_term_from_str("( String )").unwrap()], + 2 + ) + } +} + +pub struct ActCp {} +impl Action for ActCp { + fn make_editor(&self, ctx: Arc>) -> Arc> { + let depth = 1; + Arc::new(RwLock::new(ProductEditor::new(depth, ctx.clone()) + .with_t(Point2::new(0, 0), "Source ") + .with_n(Point2::new(1, 0), vec![ ctx.read().unwrap().type_term_from_str("( Path )").unwrap() ] ) + .with_t(Point2::new(0, 1), "Destination ") + .with_n(Point2::new(1, 1), vec![ ctx.read().unwrap().type_term_from_str("( Path )").unwrap() ] ) + .with_t(Point2::new(0, 2), "Options ") + .with_n(Point2::new(1, 2), vec![ ctx.read().unwrap().type_term_from_str("( List String )").unwrap() ] ) + )) as Arc> + } +} pub struct Commander { + ctx: Arc>, cmds: HashMap>, - symbol_editor: StringEditor, - cmd_editor: Option<( - Arc>, - Arc> - )>, + symbol_editor: PTYListEditor, + cmd_editor: Option>>, view_elements: VecBuffer>, out_port: OuterViewPort, } impl Commander { - pub fn new() -> Self { + pub fn new(ctx: Arc>) -> Self { let port = ViewPort::new(); - let mut view_elements = VecBuffer::new(port.inner()); - let symbol_editor = StringEditor::new(); + let mut view_elements = VecBuffer::with_port(port.inner()); - view_elements.push(symbol_editor.get_plain_editor_view()); + let symbol_editor = PTYListEditor::new( + || { + Arc::new(RwLock::new(CharEditor::new())) + }, + SeqDecorStyle::Plain, + 0 + ); + + view_elements.push(symbol_editor.get_term_view()); let mut cmds = HashMap::new(); cmds.insert("cd".into(), Arc::new(ActCd{}) as Arc); - cmds.insert("echo".into(), Arc::new(ActCd{}) as Arc); + cmds.insert("echo".into(), Arc::new(ActEcho{}) as Arc); cmds.insert("ls".into(), Arc::new(ActCd{}) as Arc); + cmds.insert("cp".into(), Arc::new(ActCp{}) as Arc); let mut c = Commander { + ctx, cmds, symbol_editor, cmd_editor: None, view_elements, out_port: port.outer() .to_sequence() + .separate(make_label(" ")) .to_grid_horizontal() .flatten() }; @@ -96,11 +122,11 @@ impl TerminalEditor for Commander { match event { TerminalEvent::Input(Event::Key(Key::Char('\n'))) => { // run - cmd_editor.1.write().unwrap().up(); + cmd_editor.write().unwrap().goto(TreeCursor::none()); TerminalEditorResult::Exit } event => { - cmd_editor.0.write().unwrap().handle_terminal_event(event) + cmd_editor.write().unwrap().handle_terminal_event(event) } } } else { @@ -110,14 +136,19 @@ impl TerminalEditor for Commander { let symbol = self.symbol_editor.get_string(); if let Some(action) = self.cmds.get(&symbol) { - let editor = action.make_editor(); + let editor = action.make_editor(self.ctx.clone()); self.symbol_editor.up(); - self.view_elements.push(make_label(" ")); - self.view_elements.push(editor.0.read().unwrap().get_term_view()); + self.view_elements.push(editor.read().unwrap().get_term_view()); - editor.1.write().unwrap().goto_home(); + editor.write().unwrap().qpxev(); self.cmd_editor = Some(editor); + + if *event == TerminalEvent::Input(Event::Key(Key::Char('\n'))) { + return self.handle_terminal_event(event); + } + } else { + // undefined command } TerminalEditorResult::Continue @@ -134,61 +165,34 @@ impl TerminalEditor for Commander { impl TreeNav for Commander { fn get_cursor(&self) -> TreeCursor { if let Some(cmd_editor) = self.cmd_editor.as_ref() { - cmd_editor.1.write().unwrap().get_cursor() + cmd_editor.write().unwrap().get_cursor() } else { self.symbol_editor.get_cursor() } } - + fn get_cursor_warp(&self) -> TreeCursor { + if let Some(cmd_editor) = self.cmd_editor.as_ref() { + cmd_editor.write().unwrap().get_cursor_warp() + } else { + self.symbol_editor.get_cursor_warp() + } + } + fn goby(&mut self, dir: Vector2) -> TreeNavResult { + if let Some(cmd_editor) = self.cmd_editor.as_ref() { + cmd_editor.write().unwrap().goby(dir) + } else { + self.symbol_editor.goby(dir) + } + } fn goto(&mut self, cur: TreeCursor) -> TreeNavResult { if let Some(cmd_editor) = self.cmd_editor.as_ref() { - cmd_editor.1.write().unwrap().goto(cur) + cmd_editor.write().unwrap().goto(cur) } else { self.symbol_editor.goto(cur) } } - fn goto_home(&mut self) -> TreeNavResult { - if let Some(cmd_editor) = self.cmd_editor.as_ref() { - cmd_editor.1.write().unwrap().goto_home() - } else { - self.symbol_editor.goto_home() - } - } - fn goto_end(&mut self) -> TreeNavResult { - if let Some(cmd_editor) = self.cmd_editor.as_ref() { - cmd_editor.1.write().unwrap().goto_end() - } else { - self.symbol_editor.goto_end() - } - } - fn pxev(&mut self) -> TreeNavResult { - if let Some(cmd_editor) = self.cmd_editor.as_ref() { - cmd_editor.1.write().unwrap().pxev() - } else { - self.symbol_editor.pxev() - } - } - fn nexd(&mut self) -> TreeNavResult { - if let Some(cmd_editor) = self.cmd_editor.as_ref() { - cmd_editor.1.write().unwrap().nexd() - } else { - self.symbol_editor.nexd() - } - } - fn up(&mut self) -> TreeNavResult { - if let Some(cmd_editor) = self.cmd_editor.as_ref() { - cmd_editor.1.write().unwrap().up() - } else { - self.symbol_editor.up() - } - } - fn dn(&mut self) -> TreeNavResult { - if let Some(cmd_editor) = self.cmd_editor.as_ref() { - cmd_editor.1.write().unwrap().dn() - } else { - self.symbol_editor.dn() - } - } + } +impl TerminalTreeEditor for Commander {} diff --git a/shell/src/main.rs b/shell/src/main.rs index 43f8353..36404d8 100644 --- a/shell/src/main.rs +++ b/shell/src/main.rs @@ -4,14 +4,17 @@ mod ascii_box; mod monstera; mod process; mod pty; - +mod command; mod plot; use { - crate::process::ProcessLauncher, + crate::{ + process::ProcessLauncher, + command::Commander + }, cgmath::{Point2, Vector2}, nested::{ - core::{port::UpdateTask, Observer, OuterViewPort, ViewPort}, + core::{port::UpdateTask, Observer, OuterViewPort, ViewPort, Context, TypeTerm}, index::IndexArea, list::{ListCursorMode, PTYListEditor}, sequence::{decorator::{SeqDecorStyle}}, @@ -34,9 +37,28 @@ async fn main() { let mut term = Terminal::new(term_port.outer()); let term_writer = term.get_writer(); + // Update Loop // + let tp = term_port.clone(); + async_std::task::spawn(async move { + loop { + tp.update(); + async_std::task::sleep(std::time::Duration::from_millis(20)).await; + } + }); + async_std::task::spawn(async move { let mut table = nested::index::buffer::IndexBuffer::new(); + // Type Context // + let mut ctx = Arc::new(RwLock::new(Context::new())); + for tn in vec![ + "MachineWord", "MachineInt", "MachineSyllab", "Bits", + "Vec", "Stream", "Json", + "Sequence", "AsciiString", "UTF-8-String", "Char", "String", + "PosInt", "Digit", "LittleEndian", "BigEndian", + "DiffStream", "ℕ", "List", "Path", "Term", "RGB", "Vec3i" + ] { ctx.write().unwrap().add_typename(tn.into()); } + let magic = make_label("<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>>").map_item(|pos, atom| { atom.add_style_back(TerminalStyle::fg_color(( @@ -50,7 +72,7 @@ async fn main() { let mut status_chars = VecBuffer::new(); let mut process_list_editor = PTYListEditor::new( - Box::new(|| Arc::new(RwLock::new(ProcessLauncher::new()))), + Box::new({let ctx = ctx.clone(); move || Arc::new(RwLock::new(Commander::new(ctx.clone())))}), SeqDecorStyle::VerticalSexpr, 0 ); @@ -85,7 +107,7 @@ async fn main() { let plot_port = ViewPort::new(); let _plot = crate::plot::Plot::new(plist_port.to_sequence(), plot_port.inner()); - + table.insert_iter(vec![ (Point2::new(0, 0), magic.clone()), ( @@ -93,7 +115,8 @@ async fn main() { status_chars.get_port().to_sequence().to_grid_horizontal(), ), (Point2::new(0, 2), magic.clone()), - (Point2::new(0, 3), process_list_editor.get_term_view()), + + (Point2::new(0, 4), process_list_editor.get_term_view()), ]); let (w, h) = termion::terminal_size().unwrap(); @@ -124,15 +147,7 @@ async fn main() { leaf_mode: ListCursorMode::Insert, tree_addr: vec![0], }); - - let tp = term_port.clone(); - async_std::task::spawn(async move { - loop { - tp.update(); - async_std::task::sleep(std::time::Duration::from_millis(10)).await; - } - }); - + loop { status_chars.clear(); let cur = process_list_editor.get_cursor(); @@ -191,6 +206,7 @@ async fn main() { if let Some(process_editor) = process_list_editor.get_item() { let mut pe = process_editor.write().unwrap(); + /* if pe.is_captured() { if let TerminalEditorResult::Exit = pe.handle_terminal_event(&ev) { drop(pe); @@ -198,7 +214,8 @@ async fn main() { process_list_editor.nexd(); } continue; - } + } + */ } match ev {