From 273f20d3db876e4381db8035d439f736b9027340 Mon Sep 17 00:00:00 2001 From: Michael Sippel Date: Sun, 23 Oct 2022 21:28:06 +0200 Subject: [PATCH] pty list: add split key --- nested/src/integer/editor.rs | 1 + nested/src/list/editor.rs | 14 ++++++++++++++ nested/src/list/pty_editor.rs | 32 ++++++++++++++++++++++++++++++++ nested/src/make_editor.rs | 15 +++++++++++++-- nested/src/product/editor.rs | 2 +- shell/src/command.rs | 17 +++++++++++++++++ shell/src/main.rs | 11 +++++++---- shell/src/process.rs | 2 ++ 8 files changed, 87 insertions(+), 7 deletions(-) diff --git a/nested/src/integer/editor.rs b/nested/src/integer/editor.rs index 21afafa..d4dd244 100644 --- a/nested/src/integer/editor.rs +++ b/nested/src/integer/editor.rs @@ -115,6 +115,7 @@ impl PosIntEditor { digits_editor: PTYListEditor::new( Box::new(move || Arc::new(RwLock::new(DigitEditor::new(radix)))) as Box Arc> + Send + Sync>, SeqDecorStyle::Hex, + ' ', 0 ), } diff --git a/nested/src/list/editor.rs b/nested/src/list/editor.rs index 80a58cf..78d9c94 100644 --- a/nested/src/list/editor.rs +++ b/nested/src/list/editor.rs @@ -80,6 +80,20 @@ where ItemEditor: TerminalTreeEditor + ?Sized + Send + Sync + 'static } } + /// split the list off at the current cursor position and return the second half + /* + pub fn split(&mut self) -> ListEditor { + let mut le = ListEditor::new(self.make_item_editor.clone()); + let p = self.cursor.get(); + for i in p.idx .. self.data.len() { + le.data.push( self.data[p.idx] ); + self.data.remove(p.idx); + } + le.goto(TreeCursor::home()); + le + } + */ + pub fn clear(&mut self) { self.data.clear(); } diff --git a/nested/src/list/pty_editor.rs b/nested/src/list/pty_editor.rs index f4510a9..8f402fc 100644 --- a/nested/src/list/pty_editor.rs +++ b/nested/src/list/pty_editor.rs @@ -27,6 +27,8 @@ where ItemEditor: TerminalTreeEditor + ?Sized + Send + Sync + 'static { pub editor: ListEditor, + split_char: char, + style: SeqDecorStyle, depth: usize, @@ -39,6 +41,7 @@ where ItemEditor: TerminalTreeEditor + ?Sized + Send + Sync + 'static pub fn new( make_item_editor: impl Fn() -> Arc> + Send + Sync + 'static, style: SeqDecorStyle, + split_char: char, depth: usize ) -> Self { let port = ViewPort::new(); @@ -46,6 +49,7 @@ where ItemEditor: TerminalTreeEditor + ?Sized + Send + Sync + 'static editor: ListEditor::new(make_item_editor, depth), style, depth, + split_char, port } } @@ -53,11 +57,13 @@ where ItemEditor: TerminalTreeEditor + ?Sized + Send + Sync + 'static pub fn from_editor( editor: ListEditor, style: SeqDecorStyle, + split_char: char, depth: usize ) -> Self { let port = ViewPort::new(); PTYListEditor { editor, + split_char, style, depth, port @@ -158,6 +164,32 @@ where ItemEditor: TerminalTreeEditor + ?Sized + Send + Sync + 'static self.editor.set_leaf_mode(ListCursorMode::Insert); TerminalEditorResult::Continue } + + TerminalEvent::Input(Event::Key(Key::Char(c))) => { + if *c == self.split_char { + let c = self.editor.cursor.get(); + self.editor.goto(TreeCursor::none()); + self.editor.cursor.set(ListCursor { + mode: ListCursorMode::Insert, + idx: Some(1 + c.idx.unwrap_or(0)) + }); + } else { + if let Some(e) = self.editor.get_item() { + match e.write().unwrap().handle_terminal_event(&TerminalEvent::Input(Event::Key(Key::Char(*c)))) { + TerminalEditorResult::Exit => { + self.editor.cursor.set(ListCursor { + mode: ListCursorMode::Insert, + idx: Some(idx as isize + 1), + }); + } + TerminalEditorResult::Continue => { + + } + } + } + } + TerminalEditorResult::Continue + } ev => { if let Some(e) = self.editor.get_item() { match e.write().unwrap().handle_terminal_event(ev) { diff --git a/nested/src/make_editor.rs b/nested/src/make_editor.rs index 14de5fd..027832e 100644 --- a/nested/src/make_editor.rs +++ b/nested/src/make_editor.rs @@ -29,6 +29,7 @@ pub fn make_editor(ctx: Arc>, t: &TypeLadder, depth: usize) -> A Arc::new(RwLock::new(CharEditor::new())) }), SeqDecorStyle::DoubleQuote, + '"', depth ) )) @@ -48,6 +49,7 @@ pub fn make_editor(ctx: Arc>, t: &TypeLadder, depth: usize) -> A } }), SeqDecorStyle::EnumSet, + '"', depth ) )) as Arc> @@ -59,6 +61,7 @@ pub fn make_editor(ctx: Arc>, t: &TypeLadder, depth: usize) -> A || { Arc::new(RwLock::new(CharEditor::new())) } ), SeqDecorStyle::Plain, + '\n', depth+1 ) )) as Arc> @@ -70,6 +73,7 @@ pub fn make_editor(ctx: Arc>, t: &TypeLadder, depth: usize) -> A Arc::new(RwLock::new(PosIntEditor::new(16))) }), SeqDecorStyle::EnumSet, + ',', depth ) )) as Arc> @@ -84,10 +88,12 @@ pub fn make_editor(ctx: Arc>, t: &TypeLadder, depth: usize) -> A Arc::new(RwLock::new(CharEditor::new())) }), SeqDecorStyle::Plain, + '\n', d ))) }}), SeqDecorStyle::Path, + '/', depth ))) as Arc> @@ -106,6 +112,7 @@ pub fn make_editor(ctx: Arc>, t: &TypeLadder, depth: usize) -> A } }), SeqDecorStyle::EnumSet, + ',', depth ) )) as Arc> @@ -121,20 +128,21 @@ pub fn make_editor(ctx: Arc>, t: &TypeLadder, depth: usize) -> A }) }, SeqDecorStyle::VerticalSexpr, + ',', depth ) )) as Arc> } else if t[0] == c.type_term_from_str("( RGB )").unwrap() { Arc::new(RwLock::new(ProductEditor::new(depth, ctx.clone()) - .with_t(Point2::new(0, 0), "{") + .with_t(Point2::new(0, 0), "{ ") .with_t(Point2::new(1, 1), "r: ") .with_n(Point2::new(2, 1), vec![ ctx.read().unwrap().type_term_from_str("( PosInt 16 BigEndian )").unwrap() ] ) .with_t(Point2::new(1, 2), "g: ") .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() { @@ -163,6 +171,7 @@ pub fn make_editor(ctx: Arc>, t: &TypeLadder, depth: usize) -> A } }), SeqDecorStyle::VerticalSexpr, + '\n', depth ) )) as Arc> @@ -177,6 +186,7 @@ pub fn make_editor(ctx: Arc>, t: &TypeLadder, depth: usize) -> A } }), SeqDecorStyle::Tuple, + '\n', depth ) )) as Arc> @@ -188,6 +198,7 @@ pub fn make_editor(ctx: Arc>, t: &TypeLadder, depth: usize) -> A Arc::new(RwLock::new(CharEditor::new())) }, SeqDecorStyle::DoubleQuote, + ' ', depth ) )) diff --git a/nested/src/product/editor.rs b/nested/src/product/editor.rs index 27b0253..35a0e7e 100644 --- a/nested/src/product/editor.rs +++ b/nested/src/product/editor.rs @@ -147,7 +147,7 @@ impl ProductEditor { } else { let mut b = VecBuffer::new(); b.push(crate::diagnostics::make_todo(crate::terminal::make_label(&format!("complete {}", self.ctx.read().unwrap().type_term_to_str(&t[0]))))); - + self.msg_buf.update(idx as usize, Some(b.get_port().to_sequence())); } diff --git a/shell/src/command.rs b/shell/src/command.rs index 0c96337..5ac9e66 100644 --- a/shell/src/command.rs +++ b/shell/src/command.rs @@ -93,6 +93,21 @@ impl Action for ActNum { } } +pub struct ActColor {} +impl Action for ActColor { + fn make_editor(&self, ctx: Arc>) -> Arc> { + let depth = 1; + Arc::new(RwLock::new(ProductEditor::new(depth, ctx.clone()) + .with_t(Point2::new(1, 1), " RGB") + .with_n(Point2::new(0, 1), vec![ ctx.read().unwrap().type_term_from_str("( RGB )").unwrap() ] ) + .with_t(Point2::new(1, 2), " HSV") + .with_n(Point2::new(0, 2), vec![ ctx.read().unwrap().type_term_from_str("( RGB )").unwrap() ] ) + .with_t(Point2::new(1, 3), " HSL") + .with_n(Point2::new(0, 3), vec![ ctx.read().unwrap().type_term_from_str("( RGB )").unwrap() ] ) + )) as Arc> + } +} + pub struct Commander { ctx: Arc>, cmds: HashMap>, @@ -119,6 +134,7 @@ impl Commander { Arc::new(RwLock::new(CharEditor::new())) }, SeqDecorStyle::Plain, + '\n', 0 ); @@ -144,6 +160,7 @@ impl Commander { cmds.insert("ls".into(), Arc::new(ActLs{}) as Arc); cmds.insert("cp".into(), Arc::new(ActCp{}) as Arc); cmds.insert("num".into(), Arc::new(ActNum{}) as Arc); + cmds.insert("color".into(), Arc::new(ActColor{}) as Arc); let m_buf = VecBuffer::new(); let mut c = Commander { diff --git a/shell/src/main.rs b/shell/src/main.rs index fda49a3..e98c47b 100644 --- a/shell/src/main.rs +++ b/shell/src/main.rs @@ -80,6 +80,7 @@ async fn main() { )}), */ SeqDecorStyle::VerticalSexpr, + '\n', 0 ); @@ -153,6 +154,8 @@ async fn main() { for x in entry.addr.iter() { b.push( make_label(&format!("{}", x)) + .map_item(|p,a| a + .add_style_back(TerminalStyle::fg_color((0, 100, 20)))) ); b.push( make_label(".") @@ -206,7 +209,7 @@ async fn main() { if cur.tree_addr.len() > 0 { status_chars.push(TerminalAtom::new( '@', - TerminalStyle::fg_color((120, 80, 80)).add(TerminalStyle::bold(true)), + TerminalStyle::fg_color((150, 80,230)).add(TerminalStyle::bold(true)), )); for x in cur.tree_addr { for c in format!("{}", x).chars() { @@ -215,13 +218,13 @@ async fn main() { } status_chars.push(TerminalAtom::new( '.', - TerminalStyle::fg_color((120, 80, 80)), + TerminalStyle::fg_color((150, 80,230)) )); } status_chars.push(TerminalAtom::new( ':', - TerminalStyle::fg_color((120, 80, 80)).add(TerminalStyle::bold(true)), + TerminalStyle::fg_color((150, 80,230)).add(TerminalStyle::bold(true)), )); for c in match cur.leaf_mode { ListCursorMode::Insert => "INSERT", @@ -236,7 +239,7 @@ async fn main() { } status_chars.push(TerminalAtom::new( ':', - TerminalStyle::fg_color((120, 80, 80)).add(TerminalStyle::bold(true)), + TerminalStyle::fg_color((150, 80,230)).add(TerminalStyle::bold(true)), )); } else { for c in "Press to enter".chars() { diff --git a/shell/src/process.rs b/shell/src/process.rs index 759ac9f..8fa456c 100644 --- a/shell/src/process.rs +++ b/shell/src/process.rs @@ -106,11 +106,13 @@ impl ProcessLauncher { editor: PTYListEditor::new( Box::new(|| Arc::new(RwLock::new(CharEditor::new()))), SeqDecorStyle::Plain, + '\n', 1 ), })) }) as Box Arc> + Send + Sync>, SeqDecorStyle::HorizontalSexpr, + ' ', 0 );