StringEditor & PosIntEditor: add get_data_port()
This commit is contained in:
parent
8b19ab94c7
commit
fe4707e7b2
2 changed files with 61 additions and 17 deletions
|
@ -6,6 +6,7 @@ use {
|
||||||
crate::{
|
crate::{
|
||||||
core::{ViewPort, OuterViewPort, Observer},
|
core::{ViewPort, OuterViewPort, Observer},
|
||||||
singleton::{SingletonView, SingletonBuffer},
|
singleton::{SingletonView, SingletonBuffer},
|
||||||
|
sequence::{SequenceView},
|
||||||
vec::VecBuffer,
|
vec::VecBuffer,
|
||||||
terminal::{TerminalAtom, TerminalStyle, TerminalView, TerminalEvent, TerminalEditor, TerminalEditorResult},
|
terminal::{TerminalAtom, TerminalStyle, TerminalView, TerminalEvent, TerminalEditor, TerminalEditorResult},
|
||||||
tree_nav::{TreeNav, TreeNavResult, TerminalTreeEditor, TreeCursor},
|
tree_nav::{TreeNav, TreeNavResult, TerminalTreeEditor, TreeCursor},
|
||||||
|
@ -34,7 +35,7 @@ impl DigitEditor {
|
||||||
pub fn get_data_port(&self) -> OuterViewPort<dyn SingletonView<Item = Option<u32>>> {
|
pub fn get_data_port(&self) -> OuterViewPort<dyn SingletonView<Item = Option<u32>>> {
|
||||||
let radix = self.radix;
|
let radix = self.radix;
|
||||||
self.data_port.outer().map(
|
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<dyn SequenceView<Item = u32>> {
|
||||||
|
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 {
|
impl TreeNav for PosIntEditor {
|
||||||
|
@ -105,7 +112,7 @@ impl TreeNav for PosIntEditor {
|
||||||
fn pxev(&mut self) -> TreeNavResult { self.digits_editor.pxev() }
|
fn pxev(&mut self) -> TreeNavResult { self.digits_editor.pxev() }
|
||||||
fn nexd(&mut self) -> TreeNavResult { self.digits_editor.nexd() }
|
fn nexd(&mut self) -> TreeNavResult { self.digits_editor.nexd() }
|
||||||
fn up(&mut self) -> TreeNavResult { self.digits_editor.up() }
|
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 {
|
impl TerminalEditor for PosIntEditor {
|
||||||
|
@ -132,6 +139,7 @@ impl TerminalEditor for PosIntEditor {
|
||||||
match event {
|
match event {
|
||||||
TerminalEvent::Input(Event::Key(Key::Char(' '))) |
|
TerminalEvent::Input(Event::Key(Key::Char(' '))) |
|
||||||
TerminalEvent::Input(Event::Key(Key::Char('\n'))) => {
|
TerminalEvent::Input(Event::Key(Key::Char('\n'))) => {
|
||||||
|
self.digits_editor.up();
|
||||||
TerminalEditorResult::Exit
|
TerminalEditorResult::Exit
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,12 +1,15 @@
|
||||||
use {
|
use {
|
||||||
|
std::sync::Arc,
|
||||||
std::sync::RwLock,
|
std::sync::RwLock,
|
||||||
termion::event::{Key, Event},
|
termion::event::{Key, Event},
|
||||||
crate::{
|
crate::{
|
||||||
core::{ViewPort, OuterViewPort},
|
core::{ViewPort, OuterViewPort},
|
||||||
singleton::{SingletonView, SingletonBuffer},
|
singleton::{SingletonView, SingletonBuffer},
|
||||||
|
sequence::{SequenceView},
|
||||||
vec::VecBuffer,
|
vec::VecBuffer,
|
||||||
terminal::{TerminalView, TerminalStyle, TerminalEvent, TerminalEditor, TerminalEditorResult},
|
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<dyn Fn() -> Arc<RwLock<CharEditor>> + 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
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TerminalEditor for ArgListEditor {
|
pub fn get_data_port(&self) -> OuterViewPort<dyn SequenceView<Item = char>> {
|
||||||
|
self.chars_editor.get_data_port()
|
||||||
|
.map(
|
||||||
|
|char_editor| char_editor.read().unwrap().data.get().unwrap()
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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<dyn TerminalView> {
|
fn get_term_view(&self) -> OuterViewPort<dyn TerminalView> {
|
||||||
|
self.chars_editor
|
||||||
|
.get_seg_seq_view()
|
||||||
|
.decorate("\"", "\"", "", 1)
|
||||||
|
.to_grid_horizontal()
|
||||||
|
.flatten()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn handle_terminal_event(&mut self, event: &TerminalEvent) -> TerminalEditorResult {
|
fn handle_terminal_event(&mut self, event: &TerminalEvent) -> TerminalEditorResult {
|
||||||
match event {
|
match event {
|
||||||
TerminalEvent::Input(Event::Key(Key::Char(' '))) => {
|
TerminalEvent::Input(Event::Key(Key::Char('\n'))) => {
|
||||||
// list.get_arg()
|
self.chars_editor.up();
|
||||||
// split
|
TerminalEditorResult::Exit
|
||||||
|
}
|
||||||
|
event => self.chars_editor.handle_terminal_event(event)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
_ => {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
Loading…
Reference in a new issue