From fe4707e7b2efab28d889915ba8b479d7c9880ac3 Mon Sep 17 00:00:00 2001 From: Michael Sippel Date: Tue, 31 Aug 2021 03:03:51 +0200 Subject: [PATCH] StringEditor & PosIntEditor: add get_data_port() --- nested/src/integer/editor.rs | 12 +++++-- nested/src/string_editor.rs | 66 ++++++++++++++++++++++++++++-------- 2 files changed, 61 insertions(+), 17 deletions(-) diff --git a/nested/src/integer/editor.rs b/nested/src/integer/editor.rs index 6c9db6d..0281a94 100644 --- a/nested/src/integer/editor.rs +++ b/nested/src/integer/editor.rs @@ -6,6 +6,7 @@ use { crate::{ core::{ViewPort, OuterViewPort, Observer}, singleton::{SingletonView, SingletonBuffer}, + sequence::{SequenceView}, vec::VecBuffer, terminal::{TerminalAtom, TerminalStyle, TerminalView, TerminalEvent, TerminalEditor, TerminalEditorResult}, tree_nav::{TreeNav, TreeNavResult, TerminalTreeEditor, TreeCursor}, @@ -34,7 +35,7 @@ impl DigitEditor { pub fn get_data_port(&self) -> OuterViewPort>> { let radix = self.radix; self.data_port.outer().map( - move |c| c.unwrap_or('?').to_digit(radix) + move |c| c?.to_digit(radix) ) } } @@ -95,6 +96,12 @@ impl PosIntEditor { ) } } + + pub fn get_data_port(&self) -> OuterViewPort> { + let radix = self.radix; + self.digits_editor.get_data_port() + .filter_map(move |digit_editor| digit_editor.read().unwrap().data.get()?.to_digit(radix)) + } } impl TreeNav for PosIntEditor { @@ -105,7 +112,7 @@ impl TreeNav for PosIntEditor { fn pxev(&mut self) -> TreeNavResult { self.digits_editor.pxev() } fn nexd(&mut self) -> TreeNavResult { self.digits_editor.nexd() } fn up(&mut self) -> TreeNavResult { self.digits_editor.up() } - fn dn(&mut self) -> TreeNavResult { TreeNavResult::Exit } + fn dn(&mut self) -> TreeNavResult { self.digits_editor.dn() } } impl TerminalEditor for PosIntEditor { @@ -132,6 +139,7 @@ impl TerminalEditor for PosIntEditor { match event { TerminalEvent::Input(Event::Key(Key::Char(' '))) | TerminalEvent::Input(Event::Key(Key::Char('\n'))) => { + self.digits_editor.up(); TerminalEditorResult::Exit } diff --git a/nested/src/string_editor.rs b/nested/src/string_editor.rs index 477e375..c0be63f 100644 --- a/nested/src/string_editor.rs +++ b/nested/src/string_editor.rs @@ -1,12 +1,15 @@ use { + std::sync::Arc, std::sync::RwLock, termion::event::{Key, Event}, crate::{ core::{ViewPort, OuterViewPort}, singleton::{SingletonView, SingletonBuffer}, + sequence::{SequenceView}, vec::VecBuffer, terminal::{TerminalView, TerminalStyle, TerminalEvent, TerminalEditor, TerminalEditorResult}, - tree_nav::{TreeNav, TreeNavResult} + list::{ListEditor, sexpr::ListDecoration}, + tree_nav::{TreeNav, TreeNavResult, TreeCursor} } }; @@ -64,30 +67,63 @@ impl TerminalEditor for CharEditor { } } -/* -pub struct ArgListEditor { - +//<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>> + +pub struct StringEditor { + chars_editor: ListEditor< CharEditor, + Box Arc> + Send + Sync + 'static> > } -impl TreeNav for ArgListEditor { - +impl StringEditor { + pub fn new() -> Self { + StringEditor { + chars_editor: ListEditor::new( + Box::new( + move || { + Arc::new(RwLock::new(CharEditor::new())) + } + ), + crate::list::ListEditorStyle::String + ) + } + } + + pub fn get_data_port(&self) -> OuterViewPort> { + self.chars_editor.get_data_port() + .map( + |char_editor| char_editor.read().unwrap().data.get().unwrap() + ) + } } -impl TerminalEditor for ArgListEditor { +impl TreeNav for StringEditor { + fn get_cursor(&self) -> TreeCursor { self.chars_editor.get_cursor() } + fn goto(&mut self, cur: TreeCursor) -> TreeNavResult { self.chars_editor.goto(cur) } + fn goto_home(&mut self) -> TreeNavResult { self.chars_editor.goto_home() } + fn goto_end(&mut self) -> TreeNavResult { self.chars_editor.goto_end() } + fn pxev(&mut self) -> TreeNavResult { self.chars_editor.pxev() } + fn nexd(&mut self) -> TreeNavResult { self.chars_editor.nexd() } + fn up(&mut self) -> TreeNavResult { self.chars_editor.up() } + fn dn(&mut self) -> TreeNavResult { TreeNavResult::Exit } +} + +impl TerminalEditor for StringEditor { fn get_term_view(&self) -> OuterViewPort { - + self.chars_editor + .get_seg_seq_view() + .decorate("\"", "\"", "", 1) + .to_grid_horizontal() + .flatten() } fn handle_terminal_event(&mut self, event: &TerminalEvent) -> TerminalEditorResult { match event { - TerminalEvent::Input(Event::Key(Key::Char(' '))) => { - // list.get_arg() - // split - } - _ => { - + TerminalEvent::Input(Event::Key(Key::Char('\n'))) => { + self.chars_editor.up(); + TerminalEditorResult::Exit } + event => self.chars_editor.handle_terminal_event(event) } } } -*/ +