replace TerminalTreeEditor with Nested trait

This commit is contained in:
Michael Sippel 2022-11-13 15:26:25 +01:00
parent 97624e1a8e
commit 0a8c77772c
Signed by: senvas
GPG key ID: F96CF119C34B64A6
20 changed files with 244 additions and 138 deletions

View file

@ -8,8 +8,9 @@ use {
TerminalAtom, TerminalEditor, TerminalEditorResult, TerminalEvent, TerminalStyle, TerminalAtom, TerminalEditor, TerminalEditorResult, TerminalEvent, TerminalStyle,
TerminalView, TerminalView,
}, },
tree_nav::{TerminalTreeEditor, TreeCursor, TreeNav, TreeNavResult}, tree::{TreeCursor, TreeNav, TreeNavResult},
diagnostics::Diagnostics diagnostics::Diagnostics,
Nested
}, },
std::sync::Arc, std::sync::Arc,
std::sync::RwLock, std::sync::RwLock,
@ -69,6 +70,6 @@ impl TerminalEditor for CharEditor {
} }
} }
impl TerminalTreeEditor for CharEditor {} impl Nested for CharEditor {}

View file

@ -4,9 +4,7 @@ use {
type_term::{TypeDict, TypeTerm, TypeID}, type_term::{TypeDict, TypeTerm, TypeID},
AnyOuterViewPort, OuterViewPort, View, AnyOuterViewPort, OuterViewPort, View,
}, },
tree_nav::{ Nested
TerminalTreeEditor
}
}, },
std::{ std::{
collections::HashMap, collections::HashMap,
@ -244,7 +242,7 @@ pub struct Context {
objects: HashMap<String, Object>, objects: HashMap<String, Object>,
/// editors /// editors
editor_ctors: HashMap<TypeID, Box<dyn Fn(&Self, TypeTerm) -> Option<Arc<RwLock<dyn TerminalTreeEditor>>> + Send + Sync>>, editor_ctors: HashMap<TypeID, Box<dyn Fn(&Self, TypeTerm) -> Option<Arc<RwLock<dyn Nested>>> + Send + Sync>>,
/// morphisms /// morphisms
default_constructors: HashMap<TypeTerm, Box<dyn Fn() -> Object + Send + Sync>>, default_constructors: HashMap<TypeTerm, Box<dyn Fn() -> Object + Send + Sync>>,
@ -281,7 +279,7 @@ impl Context {
self.type_dict.type_term_to_str(&t) self.type_dict.type_term_to_str(&t)
} }
pub fn add_editor_ctor(&mut self, tn: &str, mk_editor: Box<dyn Fn(&Self, TypeTerm) -> Option<Arc<RwLock<dyn TerminalTreeEditor>>> + Send + Sync>) { pub fn add_editor_ctor(&mut self, tn: &str, mk_editor: Box<dyn Fn(&Self, TypeTerm) -> Option<Arc<RwLock<dyn Nested>>> + Send + Sync>) {
if let Some(tid) = self.type_dict.get_typeid(&tn.into()) { if let Some(tid) = self.type_dict.get_typeid(&tn.into()) {
self.editor_ctors.insert(tid, mk_editor); self.editor_ctors.insert(tid, mk_editor);
} else { } else {
@ -289,7 +287,7 @@ impl Context {
} }
} }
pub fn make_editor(&self, type_term: TypeTerm) -> Option<Arc<RwLock<dyn TerminalTreeEditor>>> { pub fn make_editor(&self, type_term: TypeTerm) -> Option<Arc<RwLock<dyn Nested>>> {
if let TypeTerm::Type{ id, args } = type_term.clone() { if let TypeTerm::Type{ id, args } = type_term.clone() {
let mk_editor = self.editor_ctors.get(&id)?; let mk_editor = self.editor_ctors.get(&id)?;
mk_editor(self, type_term) mk_editor(self, type_term)

View file

@ -330,3 +330,4 @@ where
} }
//<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>> //<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>>

View file

@ -10,8 +10,9 @@ use {
TerminalAtom, TerminalEditor, TerminalEditorResult, TerminalEvent, TerminalStyle, TerminalAtom, TerminalEditor, TerminalEditorResult, TerminalEvent, TerminalStyle,
TerminalView, make_label TerminalView, make_label
}, },
tree_nav::{TerminalTreeEditor, TreeCursor, TreeNav, TreeNavResult}, tree::{TreeCursor, TreeNav, TreeNavResult},
diagnostics::{Diagnostics, Message} diagnostics::{Diagnostics, Message},
Nested
}, },
std::sync::Arc, std::sync::Arc,
std::sync::RwLock, std::sync::RwLock,
@ -95,7 +96,7 @@ impl TerminalEditor for DigitEditor {
} }
} }
impl TerminalTreeEditor for DigitEditor {} impl Nested for DigitEditor {}
impl Diagnostics for DigitEditor { impl Diagnostics for DigitEditor {
fn get_msg_port(&self) -> OuterViewPort<dyn SequenceView<Item = crate::diagnostics::Message>> { fn get_msg_port(&self) -> OuterViewPort<dyn SequenceView<Item = crate::diagnostics::Message>> {
@ -205,5 +206,5 @@ impl TerminalEditor for PosIntEditor {
} }
} }
impl TerminalTreeEditor for PosIntEditor {} impl Nested for PosIntEditor {}

View file

@ -20,7 +20,7 @@ pub mod vec;
pub mod product; pub mod product;
pub mod sum; pub mod sum;
pub mod list; pub mod list;
pub mod tree_nav; pub mod tree;
pub mod diagnostics; pub mod diagnostics;
// high-level types // high-level types
@ -35,3 +35,16 @@ pub mod terminal;
pub fn magic_header() { pub fn magic_header() {
eprintln!("<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>>"); eprintln!("<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>>");
} }
use crate::terminal::{TerminalEditor};
use crate::diagnostics::{Diagnostics};
use crate::tree::{TreeNav, TreeType};
pub trait Nested
: TerminalEditor
+ TreeNav
// + TreeType
+ Diagnostics
+ Send
{}

View file

@ -12,7 +12,8 @@ use {
make_label, TerminalEditor, TerminalEditorResult, TerminalEvent, TerminalStyle, make_label, TerminalEditor, TerminalEditorResult, TerminalEvent, TerminalStyle,
TerminalView, TerminalView,
}, },
tree_nav::{TerminalTreeEditor, TreeCursor, TreeNav, TreeNavResult}, Nested,
tree::{TreeCursor, TreeNav, TreeNavResult},
vec::VecBuffer, vec::VecBuffer,
color::{bg_style_from_depth, fg_style_from_depth} color::{bg_style_from_depth, fg_style_from_depth}
}, },
@ -23,7 +24,7 @@ use {
//<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>> //<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>>
pub struct ListEditor<ItemEditor> pub struct ListEditor<ItemEditor>
where ItemEditor: TerminalTreeEditor + ?Sized + Send + Sync + 'static where ItemEditor: Nested + ?Sized + Send + Sync + 'static
{ {
pub(super) cursor: SingletonBuffer<ListCursor>, pub(super) cursor: SingletonBuffer<ListCursor>,
pub(super) data: VecBuffer<Arc<RwLock<ItemEditor>>>, pub(super) data: VecBuffer<Arc<RwLock<ItemEditor>>>,
@ -34,7 +35,7 @@ where ItemEditor: TerminalTreeEditor + ?Sized + Send + Sync + 'static
} }
impl<ItemEditor> ListEditor<ItemEditor> impl<ItemEditor> ListEditor<ItemEditor>
where ItemEditor: TerminalTreeEditor + ?Sized + Send + Sync + 'static where ItemEditor: Nested + ?Sized + Send + Sync + 'static
{ {
pub fn new(make_item_editor: impl Fn() -> Arc<RwLock<ItemEditor>> + Send + Sync + 'static, depth: usize) -> Self { pub fn new(make_item_editor: impl Fn() -> Arc<RwLock<ItemEditor>> + Send + Sync + 'static, depth: usize) -> Self {
ListEditor { ListEditor {

View file

@ -12,9 +12,10 @@ use {
make_label, TerminalEditor, TerminalEditorResult, TerminalEvent, TerminalStyle, make_label, TerminalEditor, TerminalEditorResult, TerminalEvent, TerminalStyle,
TerminalView, TerminalView,
}, },
tree_nav::{TerminalTreeEditor, TreeCursor, TreeNav, TreeNavResult}, tree::{TreeCursor, TreeNav, TreeNavResult},
vec::VecBuffer, vec::VecBuffer,
color::{bg_style_from_depth, fg_style_from_depth} color::{bg_style_from_depth, fg_style_from_depth},
Nested
}, },
std::sync::{Arc, RwLock}, std::sync::{Arc, RwLock},
termion::event::{Event, Key}, termion::event::{Event, Key},
@ -22,7 +23,7 @@ use {
}; };
impl<ItemEditor> TreeNav for ListEditor<ItemEditor> impl<ItemEditor> TreeNav for ListEditor<ItemEditor>
where ItemEditor: TerminalTreeEditor + ?Sized + Send + Sync + 'static where ItemEditor: Nested + ?Sized + Send + Sync + 'static
{ {
fn get_cursor_warp(&self) -> TreeCursor { fn get_cursor_warp(&self) -> TreeCursor {
let cur = self.cursor.get(); let cur = self.cursor.get();

View file

@ -12,10 +12,11 @@ use {
make_label, TerminalEditor, TerminalEditorResult, TerminalEvent, TerminalStyle, make_label, TerminalEditor, TerminalEditorResult, TerminalEvent, TerminalStyle,
TerminalView, TerminalView,
}, },
tree_nav::{TerminalTreeEditor, TreeCursor, TreeNav, TreeNavResult}, tree::{TreeCursor, TreeNav, TreeNavResult},
diagnostics::{Diagnostics}, diagnostics::{Diagnostics},
vec::VecBuffer, vec::VecBuffer,
color::{bg_style_from_depth, fg_style_from_depth} color::{bg_style_from_depth, fg_style_from_depth},
Nested
}, },
std::sync::{Arc, RwLock}, std::sync::{Arc, RwLock},
termion::event::{Event, Key}, termion::event::{Event, Key},
@ -23,7 +24,7 @@ use {
}; };
pub struct PTYListEditor<ItemEditor> pub struct PTYListEditor<ItemEditor>
where ItemEditor: TerminalTreeEditor + ?Sized + Send + Sync + 'static where ItemEditor: Nested + ?Sized + Send + Sync + 'static
{ {
pub editor: ListEditor<ItemEditor>, pub editor: ListEditor<ItemEditor>,
@ -36,7 +37,7 @@ where ItemEditor: TerminalTreeEditor + ?Sized + Send + Sync + 'static
} }
impl<ItemEditor> PTYListEditor<ItemEditor> impl<ItemEditor> PTYListEditor<ItemEditor>
where ItemEditor: TerminalTreeEditor + ?Sized + Send + Sync + 'static where ItemEditor: Nested + ?Sized + Send + Sync + 'static
{ {
pub fn new( pub fn new(
make_item_editor: impl Fn() -> Arc<RwLock<ItemEditor>> + Send + Sync + 'static, make_item_editor: impl Fn() -> Arc<RwLock<ItemEditor>> + Send + Sync + 'static,
@ -92,7 +93,7 @@ where ItemEditor: TerminalTreeEditor + ?Sized + Send + Sync + 'static
} }
impl<ItemEditor> TerminalEditor for PTYListEditor<ItemEditor> impl<ItemEditor> TerminalEditor for PTYListEditor<ItemEditor>
where ItemEditor: TerminalTreeEditor + ?Sized + Send + Sync + 'static where ItemEditor: Nested + ?Sized + Send + Sync + 'static
{ {
fn get_term_view(&self) -> OuterViewPort<dyn TerminalView> { fn get_term_view(&self) -> OuterViewPort<dyn TerminalView> {
self.editor self.editor
@ -229,7 +230,7 @@ where ItemEditor: TerminalTreeEditor + ?Sized + Send + Sync + 'static
} }
impl<ItemEditor> TreeNav for PTYListEditor<ItemEditor> impl<ItemEditor> TreeNav for PTYListEditor<ItemEditor>
where ItemEditor: TerminalTreeEditor + ?Sized + Send + Sync + 'static where ItemEditor: Nested + ?Sized + Send + Sync + 'static
{ {
fn get_cursor_warp(&self) -> TreeCursor { fn get_cursor_warp(&self) -> TreeCursor {
self.editor.get_cursor_warp() self.editor.get_cursor_warp()
@ -249,7 +250,7 @@ where ItemEditor: TerminalTreeEditor + ?Sized + Send + Sync + 'static
} }
impl<ItemEditor> Diagnostics for PTYListEditor<ItemEditor> impl<ItemEditor> Diagnostics for PTYListEditor<ItemEditor>
where ItemEditor: TerminalTreeEditor + Diagnostics + ?Sized + Send + Sync + 'static where ItemEditor: Nested + Diagnostics + ?Sized + Send + Sync + 'static
{ {
fn get_msg_port(&self) -> OuterViewPort<dyn SequenceView<Item = crate::diagnostics::Message>> { fn get_msg_port(&self) -> OuterViewPort<dyn SequenceView<Item = crate::diagnostics::Message>> {
self.editor self.editor
@ -273,8 +274,8 @@ where ItemEditor: TerminalTreeEditor + Diagnostics + ?Sized + Send + Sync + 'sta
} }
} }
impl<ItemEditor> TerminalTreeEditor for PTYListEditor<ItemEditor> impl<ItemEditor> Nested for PTYListEditor<ItemEditor>
where ItemEditor: TerminalTreeEditor + ?Sized + Send + Sync + 'static where ItemEditor: Nested + ?Sized + Send + Sync + 'static
{} {}
use crate::{ use crate::{

View file

@ -6,7 +6,7 @@ use {
sequence::SequenceView, sequence::SequenceView,
singleton::SingletonView, singleton::SingletonView,
terminal::{TerminalView, TerminalStyle, make_label}, terminal::{TerminalView, TerminalStyle, make_label},
tree_nav::TerminalTreeEditor, Nested,
color::{bg_style_from_depth, fg_style_from_depth} color::{bg_style_from_depth, fg_style_from_depth}
}, },
std::sync::Arc, std::sync::Arc,
@ -14,7 +14,7 @@ use {
}; };
pub enum ListSegment<ItemEditor> pub enum ListSegment<ItemEditor>
where ItemEditor: TerminalTreeEditor + ?Sized + Send + Sync + 'static where ItemEditor: Nested + ?Sized + Send + Sync + 'static
{ {
InsertCursor, InsertCursor,
Item { Item {
@ -29,7 +29,7 @@ pub trait PTYSegment {
} }
impl<ItemEditor> PTYSegment for ListSegment<ItemEditor> impl<ItemEditor> PTYSegment for ListSegment<ItemEditor>
where ItemEditor: TerminalTreeEditor + ?Sized + Send + Sync + 'static where ItemEditor: Nested + ?Sized + Send + Sync + 'static
{ {
fn pty_view(&self) -> OuterViewPort<dyn TerminalView> { fn pty_view(&self) -> OuterViewPort<dyn TerminalView> {
match self { match self {
@ -64,7 +64,7 @@ where ItemEditor: TerminalTreeEditor + ?Sized + Send + Sync + 'static
} }
pub struct ListSegmentSequence<ItemEditor> pub struct ListSegmentSequence<ItemEditor>
where ItemEditor: TerminalTreeEditor + ?Sized + Send + Sync + 'static where ItemEditor: Nested + ?Sized + Send + Sync + 'static
{ {
data: Arc<dyn SequenceView<Item = Arc<RwLock<ItemEditor>>>>, data: Arc<dyn SequenceView<Item = Arc<RwLock<ItemEditor>>>>,
cursor: Arc<dyn SingletonView<Item = ListCursor>>, cursor: Arc<dyn SingletonView<Item = ListCursor>>,
@ -77,13 +77,13 @@ where ItemEditor: TerminalTreeEditor + ?Sized + Send + Sync + 'static
} }
impl<ItemEditor> View for ListSegmentSequence<ItemEditor> impl<ItemEditor> View for ListSegmentSequence<ItemEditor>
where ItemEditor: TerminalTreeEditor + ?Sized + Send + Sync + 'static where ItemEditor: Nested + ?Sized + Send + Sync + 'static
{ {
type Msg = usize; type Msg = usize;
} }
impl<ItemEditor> SequenceView for ListSegmentSequence<ItemEditor> impl<ItemEditor> SequenceView for ListSegmentSequence<ItemEditor>
where ItemEditor: TerminalTreeEditor + ?Sized + Send + Sync + 'static where ItemEditor: Nested + ?Sized + Send + Sync + 'static
{ {
type Item = ListSegment<ItemEditor>; type Item = ListSegment<ItemEditor>;
@ -136,7 +136,7 @@ where ItemEditor: TerminalTreeEditor + ?Sized + Send + Sync + 'static
} }
impl<ItemEditor> ListSegmentSequence<ItemEditor> impl<ItemEditor> ListSegmentSequence<ItemEditor>
where ItemEditor: TerminalTreeEditor + ?Sized + Send + Sync + 'static where ItemEditor: Nested + ?Sized + Send + Sync + 'static
{ {
pub fn new( pub fn new(
cursor_port: OuterViewPort<dyn SingletonView<Item = ListCursor>>, cursor_port: OuterViewPort<dyn SingletonView<Item = ListCursor>>,

View file

@ -1,26 +1,60 @@
use { use {
crate::{ crate::{
core::{TypeLadder, Context}, core::{TypeLadder, Context, OuterViewPort},
terminal::{TerminalView}, terminal::{TerminalView, TerminalEditor, TerminalEvent, TerminalEditorResult, make_label},
tree_nav::{TerminalTreeEditor}, tree::{TreeNav},
integer::PosIntEditor, integer::PosIntEditor,
list::{ListEditor, PTYListEditor}, list::{ListEditor, PTYListEditor},
sequence::{decorator::{SeqDecorStyle}}, sequence::{decorator::{SeqDecorStyle}},
product::editor::ProductEditor, product::editor::ProductEditor,
char_editor::CharEditor char_editor::CharEditor,
diagnostics::Diagnostics,
Nested
}, },
cgmath::{Vector2, Point2}, cgmath::{Vector2, Point2},
std::sync::{Arc, RwLock}, std::sync::{Arc, RwLock},
}; };
pub fn make_editor(ctx: Arc<RwLock<Context>>, t: &TypeLadder, depth: usize) -> Arc<RwLock<dyn TerminalTreeEditor + Send + Sync>> { enum RhsNode {
Sum (
Arc<RwLock< PTYListEditor< RhsNode > >>
),
Product (
Arc<RwLock< PTYListEditor< RhsNode > >>
),
String(
Arc<RwLock< PTYListEditor< CharEditor > >>
)
}
impl TreeNav for RhsNode {}
impl TerminalEditor for RhsNode {
fn get_term_view(&self) -> OuterViewPort<dyn TerminalView> {
make_label("todo")
}
fn handle_terminal_event(&mut self, event: &TerminalEvent) -> TerminalEditorResult {
TerminalEditorResult::Continue
}
}
impl Diagnostics for RhsNode {}
impl Nested for RhsNode {}
struct GrammarRuleEditor {
lhs: Arc<RwLock<PTYListEditor<CharEditor>>>,
rhs: Arc<RwLock<PTYListEditor<RhsNode>>>
}
pub fn make_editor(ctx: Arc<RwLock<Context>>, t: &TypeLadder, depth: usize) -> Arc<RwLock<dyn Nested + Send + Sync>> {
let c = ctx.read().unwrap(); let c = ctx.read().unwrap();
if t[0] == c.type_term_from_str("( PosInt 16 BigEndian )").unwrap() { if t[0] == c.type_term_from_str("( PosInt 16 BigEndian )").unwrap() {
Arc::new(RwLock::new(PosIntEditor::new(16))) as Arc<RwLock<dyn TerminalTreeEditor + Send + Sync>> Arc::new(RwLock::new(PosIntEditor::new(16))) as Arc<RwLock<dyn Nested + Send + Sync>>
} else if t[0] == c.type_term_from_str("( PosInt 10 BigEndian )").unwrap() { } else if t[0] == c.type_term_from_str("( PosInt 10 BigEndian )").unwrap() {
Arc::new(RwLock::new(PosIntEditor::new(10))) as Arc<RwLock<dyn TerminalTreeEditor + Send + Sync>> Arc::new(RwLock::new(PosIntEditor::new(10))) as Arc<RwLock<dyn Nested + Send + Sync>>
} else if t[0] == c.type_term_from_str("( String )").unwrap() { } else if t[0] == c.type_term_from_str("( String )").unwrap() {
Arc::new(RwLock::new( Arc::new(RwLock::new(
@ -64,7 +98,7 @@ pub fn make_editor(ctx: Arc<RwLock<Context>>, t: &TypeLadder, depth: usize) -> A
'"', '"',
depth depth
) )
)) as Arc<RwLock<dyn TerminalTreeEditor + Send + Sync>> )) as Arc<RwLock<dyn Nested + Send + Sync>>
} else if t[0] == c.type_term_from_str("( List Symbol )").unwrap() { } else if t[0] == c.type_term_from_str("( List Symbol )").unwrap() {
Arc::new(RwLock::new( Arc::new(RwLock::new(
PTYListEditor::new( PTYListEditor::new(
@ -83,7 +117,7 @@ pub fn make_editor(ctx: Arc<RwLock<Context>>, t: &TypeLadder, depth: usize) -> A
' ', ' ',
depth depth
) )
)) as Arc<RwLock<dyn TerminalTreeEditor + Send + Sync>> )) as Arc<RwLock<dyn Nested + Send + Sync>>
} else if t[0] == c.type_term_from_str("( List Char )").unwrap() { } else if t[0] == c.type_term_from_str("( List Char )").unwrap() {
Arc::new(RwLock::new( Arc::new(RwLock::new(
@ -95,7 +129,7 @@ pub fn make_editor(ctx: Arc<RwLock<Context>>, t: &TypeLadder, depth: usize) -> A
'\n', '\n',
depth+1 depth+1
) )
)) as Arc<RwLock<dyn TerminalTreeEditor + Send + Sync>> )) as Arc<RwLock<dyn Nested + Send + Sync>>
} else if t[0] == c.type_term_from_str("( List )").unwrap() { } else if t[0] == c.type_term_from_str("( List )").unwrap() {
Arc::new(RwLock::new( Arc::new(RwLock::new(
@ -107,7 +141,7 @@ pub fn make_editor(ctx: Arc<RwLock<Context>>, t: &TypeLadder, depth: usize) -> A
',', ',',
depth depth
) )
)) as Arc<RwLock<dyn TerminalTreeEditor + Send + Sync>> )) as Arc<RwLock<dyn Nested + Send + Sync>>
} else if t[0] == c.type_term_from_str("( Path )").unwrap() { } else if t[0] == c.type_term_from_str("( Path )").unwrap() {
Arc::new(RwLock::new(PTYListEditor::new( Arc::new(RwLock::new(PTYListEditor::new(
@ -126,7 +160,7 @@ pub fn make_editor(ctx: Arc<RwLock<Context>>, t: &TypeLadder, depth: usize) -> A
SeqDecorStyle::Path, SeqDecorStyle::Path,
'/', '/',
depth depth
))) as Arc<RwLock<dyn TerminalTreeEditor + Send + Sync>> ))) as Arc<RwLock<dyn Nested + Send + Sync>>
} else if t[0] == c.type_term_from_str("( List Path )").unwrap() { } else if t[0] == c.type_term_from_str("( List Path )").unwrap() {
Arc::new(RwLock::new( Arc::new(RwLock::new(
@ -146,11 +180,11 @@ pub fn make_editor(ctx: Arc<RwLock<Context>>, t: &TypeLadder, depth: usize) -> A
',', ',',
depth depth
) )
)) as Arc<RwLock<dyn TerminalTreeEditor + Send + Sync>> )) as Arc<RwLock<dyn Nested + Send + Sync>>
} else if t[0] == c.type_term_from_str("( List RGB )").unwrap() { } else if t[0] == c.type_term_from_str("( List RGB )").unwrap() {
Arc::new(RwLock::new( Arc::new(RwLock::new(
PTYListEditor::<dyn TerminalTreeEditor + Send +Sync>::new( PTYListEditor::<dyn Nested + Send +Sync>::new(
{ {
let d = depth+1; let d = depth+1;
let ctx = ctx.clone(); let ctx = ctx.clone();
@ -162,7 +196,7 @@ pub fn make_editor(ctx: Arc<RwLock<Context>>, t: &TypeLadder, depth: usize) -> A
',', ',',
depth depth
) )
)) as Arc<RwLock<dyn TerminalTreeEditor + Send + Sync>> )) as Arc<RwLock<dyn Nested + Send + Sync>>
} else if t[0] == c.type_term_from_str("( RGB )").unwrap() { } else if t[0] == c.type_term_from_str("( RGB )").unwrap() {
Arc::new(RwLock::new(ProductEditor::new(depth, ctx.clone()) Arc::new(RwLock::new(ProductEditor::new(depth, ctx.clone())
@ -174,7 +208,7 @@ pub fn make_editor(ctx: Arc<RwLock<Context>>, t: &TypeLadder, depth: usize) -> A
.with_t(Point2::new(1, 3), "b: ") .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_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<RwLock<dyn TerminalTreeEditor + Send + Sync>> )) as Arc<RwLock<dyn Nested + Send + Sync>>
} else if t[0] == c.type_term_from_str("( Vec3i )").unwrap() { } else if t[0] == c.type_term_from_str("( Vec3i )").unwrap() {
Arc::new(RwLock::new(ProductEditor::new(depth, ctx.clone()) Arc::new(RwLock::new(ProductEditor::new(depth, ctx.clone())
@ -186,11 +220,11 @@ pub fn make_editor(ctx: Arc<RwLock<Context>>, t: &TypeLadder, depth: usize) -> A
.with_t(Point2::new(1, 3), "z: ") .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_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<RwLock<dyn TerminalTreeEditor + Send + Sync>> )) as Arc<RwLock<dyn Nested + Send + Sync>>
} else if t[0] == c.type_term_from_str("( Json )").unwrap() { } else if t[0] == c.type_term_from_str("( Json )").unwrap() {
Arc::new(RwLock::new( Arc::new(RwLock::new(
PTYListEditor::<dyn TerminalTreeEditor + Send + Sync>::new( PTYListEditor::<dyn Nested + Send + Sync>::new(
Box::new({ Box::new({
let ctx = ctx.clone(); let ctx = ctx.clone();
move || { move || {
@ -198,18 +232,18 @@ pub fn make_editor(ctx: Arc<RwLock<Context>>, t: &TypeLadder, depth: usize) -> A
.with_n(Point2::new(0, 0), vec![ ctx.read().unwrap().type_term_from_str("( String )").unwrap() ] ) .with_n(Point2::new(0, 0), vec![ ctx.read().unwrap().type_term_from_str("( String )").unwrap() ] )
.with_t(Point2::new(1, 0), ": ") .with_t(Point2::new(1, 0), ": ")
.with_n(Point2::new(2, 0), vec![ ctx.read().unwrap().type_term_from_str("( Json )").unwrap() ] ) .with_n(Point2::new(2, 0), vec![ ctx.read().unwrap().type_term_from_str("( Json )").unwrap() ] )
)) as Arc<RwLock<dyn TerminalTreeEditor + Send + Sync>> )) as Arc<RwLock<dyn Nested + Send + Sync>>
} }
}), }),
SeqDecorStyle::VerticalSexpr, SeqDecorStyle::VerticalSexpr,
'\n', '\n',
depth depth
) )
)) as Arc<RwLock<dyn TerminalTreeEditor + Send + Sync>> )) as Arc<RwLock<dyn Nested + Send + Sync>>
} else if t[0] == c.type_term_from_str("( List Term )").unwrap() { } else if t[0] == c.type_term_from_str("( List Term )").unwrap() {
Arc::new(RwLock::new( Arc::new(RwLock::new(
PTYListEditor::<dyn TerminalTreeEditor + Send + Sync>::new( PTYListEditor::<dyn Nested + Send + Sync>::new(
Box::new({ Box::new({
let ctx = ctx.clone(); let ctx = ctx.clone();
move || { move || {
@ -220,7 +254,7 @@ pub fn make_editor(ctx: Arc<RwLock<Context>>, t: &TypeLadder, depth: usize) -> A
'\n', '\n',
depth depth
) )
)) as Arc<RwLock<dyn TerminalTreeEditor + Send + Sync>> )) as Arc<RwLock<dyn Nested + Send + Sync>>
} else { // else: term } else { // else: term
Arc::new(RwLock::new( Arc::new(RwLock::new(

View file

@ -12,9 +12,11 @@ use {
sequence::{SequenceView}, sequence::{SequenceView},
make_editor::make_editor, make_editor::make_editor,
tree_nav::{TreeNav, TerminalTreeEditor, TreeNavResult}, tree::{TreeNav, TreeNavResult},
diagnostics::{Diagnostics, Message}, diagnostics::{Diagnostics, Message},
terminal::{TerminalStyle} terminal::{TerminalStyle},
Nested
}, },
cgmath::{Vector2, Point2}, cgmath::{Vector2, Point2},
std::sync::{Arc, RwLock}, std::sync::{Arc, RwLock},
@ -111,7 +113,7 @@ impl ProductEditor {
Some(self.get_editor_segment_mut(self.cursor?)) Some(self.get_editor_segment_mut(self.cursor?))
} }
pub fn get_editor(&self, idx: isize) -> Option<Arc<RwLock<dyn TerminalTreeEditor + Send + Sync>>> { pub fn get_editor(&self, idx: isize) -> Option<Arc<RwLock<dyn Nested + Send + Sync>>> {
if let ProductEditorSegment::N{ t: _, editor, ed_depth: _, cur_depth: _, cur_dist: _ } = self.get_editor_segment(idx) { if let ProductEditorSegment::N{ t: _, editor, ed_depth: _, cur_depth: _, cur_dist: _ } = self.get_editor_segment(idx) {
editor editor
} else { } else {
@ -119,7 +121,7 @@ impl ProductEditor {
} }
} }
pub fn get_cur_editor(&self) -> Option<Arc<RwLock<dyn TerminalTreeEditor + Send + Sync>>> { pub fn get_cur_editor(&self) -> Option<Arc<RwLock<dyn Nested + Send + Sync>>> {
self.get_editor(self.cursor?) self.get_editor(self.cursor?)
} }

View file

@ -1,9 +1,10 @@
use { use {
crate::{ crate::{
list::ListCursorMode, list::ListCursorMode,
tree_nav::{TreeNav, TreeNavResult, TreeCursor, TerminalTreeEditor}, tree::{TreeNav, TreeNavResult, TreeCursor},
product::{segment::ProductEditorSegment, ProductEditor}, product::{segment::ProductEditorSegment, ProductEditor},
make_editor::{make_editor} make_editor::{make_editor},
Nested
}, },
cgmath::{Point2, Vector2}, cgmath::{Point2, Vector2},
std::{sync::{Arc, RwLock}, ops::{Deref, DerefMut}}, std::{sync::{Arc, RwLock}, ops::{Deref, DerefMut}},
@ -248,5 +249,5 @@ impl TreeNav for ProductEditor {
} }
} }
impl TerminalTreeEditor for ProductEditor {} impl Nested for ProductEditor {}

View file

@ -6,8 +6,8 @@ use {
make_label make_label
}, },
list::{ListCursorMode}, list::{ListCursorMode},
tree_nav::{TerminalTreeEditor}, color::{bg_style_from_depth, fg_style_from_depth},
color::{bg_style_from_depth, fg_style_from_depth} Nested
}, },
std::{sync::{Arc, RwLock}, ops::{Deref, DerefMut}}, std::{sync::{Arc, RwLock}, ops::{Deref, DerefMut}},
termion::event::{Event, Key}, termion::event::{Event, Key},
@ -18,7 +18,7 @@ pub enum ProductEditorSegment {
T( String, usize ), T( String, usize ),
N { N {
t: TypeLadder, t: TypeLadder,
editor: Option<Arc<RwLock<dyn TerminalTreeEditor + Send + Sync>>>, editor: Option<Arc<RwLock<dyn Nested + Send + Sync>>>,
ed_depth: usize, ed_depth: usize,
cur_depth: usize, cur_depth: usize,
cur_dist: isize cur_dist: isize

View file

@ -12,9 +12,10 @@ use {
sequence::{SequenceView}, sequence::{SequenceView},
make_editor::make_editor, make_editor::make_editor,
tree_nav::{TreeNav, TreeCursor, TerminalTreeEditor, TreeNavResult}, tree::{TreeNav, TreeCursor, TreeNavResult},
diagnostics::{Diagnostics, Message}, diagnostics::{Diagnostics, Message},
terminal::{TerminalStyle} terminal::{TerminalStyle},
Nested
}, },
cgmath::{Vector2, Point2}, cgmath::{Vector2, Point2},
std::sync::{Arc, RwLock}, std::sync::{Arc, RwLock},
@ -24,7 +25,7 @@ use {
pub struct SumEditor { pub struct SumEditor {
cur: usize, cur: usize,
editors: Vec< Arc<RwLock<dyn TerminalTreeEditor + Send + Sync>> >, editors: Vec< Arc<RwLock<dyn Nested + Send + Sync>> >,
port: ViewPort< dyn TerminalView >, port: ViewPort< dyn TerminalView >,
diag_port: OuterViewPort< dyn SequenceView<Item = Message> > diag_port: OuterViewPort< dyn SequenceView<Item = Message> >
@ -32,7 +33,7 @@ pub struct SumEditor {
impl SumEditor { impl SumEditor {
pub fn new( pub fn new(
editors: Vec< Arc<RwLock<dyn TerminalTreeEditor + Send + Sync>> > editors: Vec< Arc<RwLock<dyn Nested + Send + Sync>> >
) -> Self { ) -> Self {
let port = ViewPort::new(); let port = ViewPort::new();
let mut diag_buf = VecBuffer::new(); let mut diag_buf = VecBuffer::new();
@ -49,6 +50,7 @@ impl SumEditor {
self.cur = idx; self.cur = idx;
let tv = self.editors[ self.cur ].read().unwrap().get_term_view(); let tv = self.editors[ self.cur ].read().unwrap().get_term_view();
tv.add_observer( self.port.get_cast() ); tv.add_observer( self.port.get_cast() );
self.port.update_hooks.write().unwrap().clear();
self.port.add_update_hook( Arc::new(tv.0.clone()) ); self.port.add_update_hook( Arc::new(tv.0.clone()) );
self.port.set_view( Some(tv.get_view_arc()) ); self.port.set_view( Some(tv.get_view_arc()) );
} }
@ -81,6 +83,9 @@ impl TerminalEditor for SumEditor {
match event { match event {
TerminalEvent::Input( termion::event::Event::Key(Key::Ctrl('x')) ) => { TerminalEvent::Input( termion::event::Event::Key(Key::Ctrl('x')) ) => {
self.select( (self.cur + 1) % self.editors.len() ); self.select( (self.cur + 1) % self.editors.len() );
if self.editors[ self.cur ].read().unwrap().get_cursor().tree_addr.len() == 0 {
self.dn();
}
TerminalEditorResult::Continue TerminalEditorResult::Continue
}, },
event => { event => {
@ -96,6 +101,6 @@ impl Diagnostics for SumEditor {
} }
} }
impl TerminalTreeEditor for SumEditor {} impl Nested for SumEditor {}

35
nested/src/tree/cursor.rs Normal file
View file

@ -0,0 +1,35 @@
use {
crate::list::ListCursorMode,
cgmath::Vector2
};
//<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>>
#[derive(Clone, Eq, PartialEq)]
pub struct TreeCursor {
pub leaf_mode: ListCursorMode,
pub tree_addr: Vec<isize>,
}
impl TreeCursor {
pub fn home() -> Self {
TreeCursor {
leaf_mode: ListCursorMode::Insert,
tree_addr: vec![0]
}
}
pub fn none() -> Self {
TreeCursor {
leaf_mode: ListCursorMode::Select,
tree_addr: vec![],
}
}
}
impl Default for TreeCursor {
fn default() -> Self {
TreeCursor::none()
}
}

18
nested/src/tree/mod.rs Normal file
View file

@ -0,0 +1,18 @@
pub mod cursor;
pub mod nav;
pub mod typeinfo;
pub struct TreeAddr(Vec<usize>);
impl From<Vec<usize>> for TreeAddr {
fn from(v: Vec<usize>) -> TreeAddr {
TreeAddr(v)
}
}
pub use {
cursor::TreeCursor,
nav::{TreeNav, TreeNavResult},
typeinfo::TreeType
};

View file

@ -1,5 +1,6 @@
use { use {
crate::list::ListCursorMode, crate::list::ListCursorMode,
crate::tree::TreeCursor,
cgmath::Vector2 cgmath::Vector2
}; };
@ -20,34 +21,6 @@ impl From<TreeNavResult> for TerminalEditorResult {
} }
*/ */
#[derive(Clone, Eq, PartialEq)]
pub struct TreeCursor {
pub leaf_mode: ListCursorMode,
pub tree_addr: Vec<isize>,
}
impl TreeCursor {
pub fn home() -> Self {
TreeCursor {
leaf_mode: ListCursorMode::Insert,
tree_addr: vec![0]
}
}
pub fn none() -> Self {
TreeCursor {
leaf_mode: ListCursorMode::Select,
tree_addr: vec![],
}
}
}
impl Default for TreeCursor {
fn default() -> Self {
TreeCursor::none()
}
}
pub trait TreeNav { pub trait TreeNav {
/* CORE /* CORE
*/ */
@ -59,6 +32,10 @@ pub trait TreeNav {
TreeCursor::default() TreeCursor::default()
} }
fn get_max_depth(&self) -> usize {
0
}
fn goby(&mut self, direction: Vector2<isize>) -> TreeNavResult { fn goby(&mut self, direction: Vector2<isize>) -> TreeNavResult {
TreeNavResult::Exit TreeNavResult::Exit
} }
@ -149,8 +126,3 @@ pub trait TreeNav {
} }
} }
use crate::terminal::{TerminalEditor};
use crate::diagnostics::{Diagnostics};
pub trait TerminalTreeEditor : TerminalEditor + TreeNav + Diagnostics + Send {}

View file

@ -16,30 +16,32 @@ use {
terminal::{ terminal::{
TerminalAtom, TerminalEditor, TerminalEditorResult, TerminalEvent, TerminalStyle, TerminalView, make_label TerminalAtom, TerminalEditor, TerminalEditorResult, TerminalEvent, TerminalStyle, TerminalView, make_label
}, },
tree_nav::{TreeCursor, TreeNav, TreeNavResult, TerminalTreeEditor}, tree::{TreeCursor, TreeNav, TreeNavResult},
diagnostics::{Diagnostics}, diagnostics::{Diagnostics},
make_editor::make_editor, make_editor::make_editor,
product::ProductEditor product::ProductEditor,
sum::SumEditor,
Nested
} }
}; };
trait Action { trait Action {
fn make_editor(&self, ctx: Arc<RwLock<Context>>) -> Arc<RwLock<dyn TerminalTreeEditor + Send + Sync>>; fn make_editor(&self, ctx: Arc<RwLock<Context>>) -> Arc<RwLock<dyn Nested + Send + Sync>>;
} }
pub struct ActCd {} pub struct ActCd {}
impl Action for ActCd { impl Action for ActCd {
fn make_editor(&self, ctx: Arc<RwLock<Context>>) -> Arc<RwLock<dyn TerminalTreeEditor + Send + Sync>> { fn make_editor(&self, ctx: Arc<RwLock<Context>>) -> Arc<RwLock<dyn Nested + Send + Sync>> {
let depth = 1; let depth = 1;
Arc::new(RwLock::new(ProductEditor::new(depth, ctx.clone()) Arc::new(RwLock::new(ProductEditor::new(depth, ctx.clone())
.with_n(Point2::new(0, 0), vec![ ctx.read().unwrap().type_term_from_str("( Path )").unwrap() ] ) .with_n(Point2::new(0, 0), vec![ ctx.read().unwrap().type_term_from_str("( Path )").unwrap() ] )
)) as Arc<RwLock<dyn TerminalTreeEditor + Send + Sync>> )) as Arc<RwLock<dyn Nested + Send + Sync>>
} }
} }
pub struct ActLs {} pub struct ActLs {}
impl Action for ActLs { impl Action for ActLs {
fn make_editor(&self, ctx: Arc<RwLock<Context>>) -> Arc<RwLock<dyn TerminalTreeEditor + Send + Sync>> { fn make_editor(&self, ctx: Arc<RwLock<Context>>) -> Arc<RwLock<dyn Nested + Send + Sync>> {
let depth = 1; let depth = 1;
Arc::new(RwLock::new(ProductEditor::new(depth, ctx.clone()) Arc::new(RwLock::new(ProductEditor::new(depth, ctx.clone())
.with_t(Point2::new(1, 0), " Files") .with_t(Point2::new(1, 0), " Files")
@ -47,24 +49,39 @@ impl Action for ActLs {
.with_t(Point2::new(1, 1), " Options") .with_t(Point2::new(1, 1), " Options")
.with_n(Point2::new(0, 1), vec![ ctx.read().unwrap().type_term_from_str("( List String )").unwrap() ] ) .with_n(Point2::new(0, 1), vec![ ctx.read().unwrap().type_term_from_str("( List String )").unwrap() ] )
)) as Arc<RwLock<dyn TerminalTreeEditor + Send + Sync>> )) as Arc<RwLock<dyn Nested + Send + Sync>>
} }
} }
pub struct ActEcho {} pub struct ActEcho {}
impl Action for ActEcho { impl Action for ActEcho {
fn make_editor(&self, ctx: Arc<RwLock<Context>>) -> Arc<RwLock<dyn TerminalTreeEditor + Send + Sync>> { fn make_editor(&self, ctx: Arc<RwLock<Context>>) -> Arc<RwLock<dyn Nested + Send + Sync>> {
let depth = 1; let depth = 1;
Arc::new(RwLock::new(ProductEditor::new(depth, ctx.clone())
let a = Arc::new(RwLock::new(ProductEditor::new(depth, ctx.clone())
.with_n(Point2::new(0, 0), vec![ ctx.read().unwrap().type_term_from_str("( String )").unwrap() ] ) .with_n(Point2::new(0, 0), vec![ ctx.read().unwrap().type_term_from_str("( String )").unwrap() ] )
)) as Arc<RwLock<dyn TerminalTreeEditor + Send + Sync>> )) as Arc<RwLock<dyn Nested + Send + Sync>>;
let b = Arc::new(RwLock::new(ProductEditor::new(depth, ctx.clone())
.with_n(Point2::new(0, 0), vec![ ctx.read().unwrap().type_term_from_str("( PosInt 16 BigEndian )").unwrap() ] )
)) as Arc<RwLock<dyn Nested + Send + Sync>>;
let mut x = Arc::new(RwLock::new( SumEditor::new(
vec![
a, b
]
) ));
x.write().unwrap().select(0);
x
} }
} }
pub struct ActCp {} pub struct ActCp {}
impl Action for ActCp { impl Action for ActCp {
fn make_editor(&self, ctx: Arc<RwLock<Context>>) -> Arc<RwLock<dyn TerminalTreeEditor + Send + Sync>> { fn make_editor(&self, ctx: Arc<RwLock<Context>>) -> Arc<RwLock<dyn Nested + Send + Sync>> {
let depth = 1; let depth = 1;
Arc::new(RwLock::new(ProductEditor::new(depth, ctx.clone()) Arc::new(RwLock::new(ProductEditor::new(depth, ctx.clone())
.with_t(Point2::new(1, 1), " Source") .with_t(Point2::new(1, 1), " Source")
@ -73,13 +90,13 @@ impl Action for ActCp {
.with_n(Point2::new(0, 2), vec![ ctx.read().unwrap().type_term_from_str("( Path )").unwrap() ] ) .with_n(Point2::new(0, 2), vec![ ctx.read().unwrap().type_term_from_str("( Path )").unwrap() ] )
.with_t(Point2::new(1, 3), " Options") .with_t(Point2::new(1, 3), " Options")
.with_n(Point2::new(0, 3), vec![ ctx.read().unwrap().type_term_from_str("( List Symbol )").unwrap() ] ) .with_n(Point2::new(0, 3), vec![ ctx.read().unwrap().type_term_from_str("( List Symbol )").unwrap() ] )
)) as Arc<RwLock<dyn TerminalTreeEditor + Send + Sync>> )) as Arc<RwLock<dyn Nested + Send + Sync>>
} }
} }
pub struct ActNum {} pub struct ActNum {}
impl Action for ActNum { impl Action for ActNum {
fn make_editor(&self, ctx: Arc<RwLock<Context>>) -> Arc<RwLock<dyn TerminalTreeEditor + Send + Sync>> { fn make_editor(&self, ctx: Arc<RwLock<Context>>) -> Arc<RwLock<dyn Nested + Send + Sync>> {
let depth = 1; let depth = 1;
Arc::new(RwLock::new(ProductEditor::new(depth, ctx.clone()) Arc::new(RwLock::new(ProductEditor::new(depth, ctx.clone())
.with_t(Point2::new(1, 1), " Value") .with_t(Point2::new(1, 1), " Value")
@ -87,7 +104,7 @@ impl Action for ActNum {
.with_t(Point2::new(1, 2), " Radix") .with_t(Point2::new(1, 2), " Radix")
.with_n(Point2::new(0, 2), vec![ ctx.read().unwrap().type_term_from_str("( PosInt 10 BigEndian )").unwrap() ] ) .with_n(Point2::new(0, 2), vec![ ctx.read().unwrap().type_term_from_str("( PosInt 10 BigEndian )").unwrap() ] )
)) as Arc<RwLock<dyn TerminalTreeEditor + Send + Sync>> )) as Arc<RwLock<dyn Nested + Send + Sync>>
// Arc::new(RwLock::new(nested::integer::PosIntEditor::new(10))) // Arc::new(RwLock::new(nested::integer::PosIntEditor::new(10)))
} }
@ -95,7 +112,7 @@ impl Action for ActNum {
pub struct ActColor {} pub struct ActColor {}
impl Action for ActColor { impl Action for ActColor {
fn make_editor(&self, ctx: Arc<RwLock<Context>>) -> Arc<RwLock<dyn TerminalTreeEditor + Send + Sync>> { fn make_editor(&self, ctx: Arc<RwLock<Context>>) -> Arc<RwLock<dyn Nested + Send + Sync>> {
let depth = 1; let depth = 1;
Arc::new(RwLock::new(ProductEditor::new(depth, ctx.clone()) Arc::new(RwLock::new(ProductEditor::new(depth, ctx.clone())
.with_t(Point2::new(1, 1), " RGB") .with_t(Point2::new(1, 1), " RGB")
@ -104,19 +121,19 @@ impl Action for ActColor {
.with_n(Point2::new(0, 2), vec![ ctx.read().unwrap().type_term_from_str("( RGB )").unwrap() ] ) .with_n(Point2::new(0, 2), vec![ ctx.read().unwrap().type_term_from_str("( RGB )").unwrap() ] )
.with_t(Point2::new(1, 3), " HSL") .with_t(Point2::new(1, 3), " HSL")
.with_n(Point2::new(0, 3), vec![ ctx.read().unwrap().type_term_from_str("( RGB )").unwrap() ] ) .with_n(Point2::new(0, 3), vec![ ctx.read().unwrap().type_term_from_str("( RGB )").unwrap() ] )
)) as Arc<RwLock<dyn TerminalTreeEditor + Send + Sync>> )) as Arc<RwLock<dyn Nested + Send + Sync>>
} }
} }
pub struct ActLet {} pub struct ActLet {}
impl Action for ActLet { impl Action for ActLet {
fn make_editor(&self, ctx: Arc<RwLock<Context>>) -> Arc<RwLock<dyn TerminalTreeEditor + Send + Sync>> { fn make_editor(&self, ctx: Arc<RwLock<Context>>) -> Arc<RwLock<dyn Nested + Send + Sync>> {
let depth = 1; let depth = 1;
Arc::new(RwLock::new(ProductEditor::new(depth, ctx.clone()) Arc::new(RwLock::new(ProductEditor::new(depth, ctx.clone())
.with_n(Point2::new(0, 0), vec![ ctx.read().unwrap().type_term_from_str("( Symbol )").unwrap() ] ) .with_n(Point2::new(0, 0), vec![ ctx.read().unwrap().type_term_from_str("( Symbol )").unwrap() ] )
.with_t(Point2::new(1, 0), " := ") .with_t(Point2::new(1, 0), " := ")
.with_n(Point2::new(2, 0), vec![ ctx.read().unwrap().type_term_from_str("( PosInt 10 BigEndian )").unwrap() ] ) .with_n(Point2::new(2, 0), vec![ ctx.read().unwrap().type_term_from_str("( PosInt 10 BigEndian )").unwrap() ] )
)) as Arc<RwLock<dyn TerminalTreeEditor + Send + Sync>> )) as Arc<RwLock<dyn Nested + Send + Sync>>
} }
} }
@ -127,7 +144,7 @@ pub struct Commander {
valid: Arc<RwLock<bool>>, valid: Arc<RwLock<bool>>,
confirmed: bool, confirmed: bool,
symbol_editor: PTYListEditor<CharEditor>, symbol_editor: PTYListEditor<CharEditor>,
cmd_editor: Option<Arc<RwLock<dyn TerminalTreeEditor + Send + Sync>>>, cmd_editor: Option<Arc<RwLock<dyn Nested + Send + Sync>>>,
view_elements: VecBuffer<OuterViewPort<dyn TerminalView>>, view_elements: VecBuffer<OuterViewPort<dyn TerminalView>>,
out_port: OuterViewPort<dyn TerminalView>, out_port: OuterViewPort<dyn TerminalView>,
@ -209,9 +226,12 @@ impl TerminalEditor for Commander {
if let (Some(cmd_editor), true) = (self.cmd_editor.as_ref(), self.confirmed) { if let (Some(cmd_editor), true) = (self.cmd_editor.as_ref(), self.confirmed) {
match event { match event {
TerminalEvent::Input(Event::Key(Key::Char('\n'))) => { TerminalEvent::Input(Event::Key(Key::Char('\n'))) => {
if cmd_editor.write().unwrap().nexd() == TreeNavResult::Exit { let mut c = cmd_editor.write().unwrap();
if let TerminalEditorResult::Exit = c.handle_terminal_event(&TerminalEvent::Input(Event::Key(Key::Char('\n')))) {
// run // run
cmd_editor.write().unwrap().goto(TreeCursor::none()); c.goto(TreeCursor::none());
c.up();
TerminalEditorResult::Exit TerminalEditorResult::Exit
} else { } else {
@ -323,5 +343,5 @@ impl TreeNav for Commander {
} }
} }
impl TerminalTreeEditor for Commander {} impl Nested for Commander {}

View file

@ -22,10 +22,11 @@ use {
make_label, Terminal, TerminalAtom, TerminalCompositor, TerminalEditor, make_label, Terminal, TerminalAtom, TerminalCompositor, TerminalEditor,
TerminalEditorResult, TerminalEvent, TerminalStyle, TerminalView, TerminalEditorResult, TerminalEvent, TerminalStyle, TerminalView,
}, },
tree_nav::{TreeNav, TerminalTreeEditor, TreeCursor, TreeNavResult}, tree::{TreeNav, TreeCursor, TreeNavResult},
vec::VecBuffer, vec::VecBuffer,
integer::{PosIntEditor}, integer::{PosIntEditor},
diagnostics::{Diagnostics} diagnostics::{Diagnostics},
Nested
}, },
std::sync::{Arc, RwLock}, std::sync::{Arc, RwLock},
termion::event::{Event, Key}, termion::event::{Event, Key},

View file

@ -10,8 +10,9 @@ use {
TerminalAtom, TerminalEditor, TerminalEditorResult, TerminalEvent, TerminalStyle, TerminalAtom, TerminalEditor, TerminalEditorResult, TerminalEvent, TerminalStyle,
TerminalView, TerminalView,
}, },
tree_nav::{TerminalTreeEditor, TreeCursor, TreeNav, TreeNavResult}, tree::{TreeCursor, TreeNav, TreeNavResult},
diagnostics::Diagnostics diagnostics::Diagnostics,
Nested
}, },
std::sync::Arc, std::sync::Arc,
std::sync::RwLock, std::sync::RwLock,
@ -77,7 +78,7 @@ impl TreeNav for ProcessArg {
impl Diagnostics for ProcessArg { impl Diagnostics for ProcessArg {
} }
impl TerminalTreeEditor for ProcessArg {} impl Nested for ProcessArg {}
pub struct ProcessLauncher { pub struct ProcessLauncher {
cmd_editor: PTYListEditor<ProcessArg>, cmd_editor: PTYListEditor<ProcessArg>,
@ -272,5 +273,5 @@ impl TreeNav for ProcessLauncher {
impl Diagnostics for ProcessLauncher { impl Diagnostics for ProcessLauncher {
} }
impl TerminalTreeEditor for ProcessLauncher {} impl Nested for ProcessLauncher {}