implement color by depth through viewport to account for dynamic change of tree structure
This commit is contained in:
parent
62cc40c39c
commit
6c80865229
16 changed files with 134 additions and 125 deletions
|
@ -19,8 +19,8 @@ use {
|
||||||
pub fn init_ctx( ctx: &mut Context ) {
|
pub fn init_ctx( ctx: &mut Context ) {
|
||||||
ctx.add_node_ctor(
|
ctx.add_node_ctor(
|
||||||
"Char",
|
"Char",
|
||||||
Arc::new(|ctx: Arc<RwLock<Context>>, _ty: TypeTerm, _depth: usize| {
|
Arc::new(|ctx: Arc<RwLock<Context>>, _ty: TypeTerm, depth: OuterViewPort<dyn SingletonView<Item = usize>>| {
|
||||||
Some(CharEditor::new_node(ctx))
|
Some(CharEditor::new_node(ctx, depth))
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -69,7 +69,7 @@ impl CharEditor {
|
||||||
self.get_port().get_view().unwrap().get()
|
self.get_port().get_view().unwrap().get()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new_node(ctx0: Arc<RwLock<Context>>) -> NestedNode {
|
pub fn new_node(ctx0: Arc<RwLock<Context>>, depth: OuterViewPort<dyn SingletonView<Item = usize>>) -> NestedNode {
|
||||||
let data = SingletonBuffer::new('\0');
|
let data = SingletonBuffer::new('\0');
|
||||||
let ctx = ctx0.clone();
|
let ctx = ctx0.clone();
|
||||||
let editor = Arc::new(RwLock::new(CharEditor{ ctx, data: data.clone() }));
|
let editor = Arc::new(RwLock::new(CharEditor{ ctx, data: data.clone() }));
|
||||||
|
@ -80,7 +80,7 @@ impl CharEditor {
|
||||||
ctx0.read().unwrap().type_term_from_str("( Char )").unwrap(),
|
ctx0.read().unwrap().type_term_from_str("( Char )").unwrap(),
|
||||||
data.get_port().into()
|
data.get_port().into()
|
||||||
),
|
),
|
||||||
0 // fixme
|
depth
|
||||||
)
|
)
|
||||||
.set_view(data
|
.set_view(data
|
||||||
.get_port()
|
.get_port()
|
||||||
|
|
|
@ -1,4 +1,8 @@
|
||||||
|
|
||||||
use {
|
use {
|
||||||
|
r3vi::{
|
||||||
|
view::{OuterViewPort, singleton::*}
|
||||||
|
},
|
||||||
crate::{
|
crate::{
|
||||||
type_system::{Context, TypeTerm},
|
type_system::{Context, TypeTerm},
|
||||||
editors::{
|
editors::{
|
||||||
|
@ -19,7 +23,7 @@ pub fn init_ctx(ctx: &mut Context) {
|
||||||
|
|
||||||
ctx.add_node_ctor(
|
ctx.add_node_ctor(
|
||||||
"Digit", Arc::new(
|
"Digit", Arc::new(
|
||||||
|ctx: Arc<RwLock<Context>>, ty: TypeTerm, depth: usize| {
|
|ctx: Arc<RwLock<Context>>, ty: TypeTerm, depth: OuterViewPort<dyn SingletonView<Item = usize>>| {
|
||||||
match ty {
|
match ty {
|
||||||
TypeTerm::App(args) => {
|
TypeTerm::App(args) => {
|
||||||
if args.len() > 1 {
|
if args.len() > 1 {
|
||||||
|
@ -50,9 +54,6 @@ pub fn init_ctx(ctx: &mut Context) {
|
||||||
ctx.add_morphism(pattern,
|
ctx.add_morphism(pattern,
|
||||||
Arc::new(
|
Arc::new(
|
||||||
|mut node, dst_type| {
|
|mut node, dst_type| {
|
||||||
let _depth = node.depth.get();
|
|
||||||
let _editor = node.editor.get().unwrap().downcast::<RwLock<ListEditor>>().unwrap();
|
|
||||||
|
|
||||||
// todo: check src_type parameter to be ( Digit radix )
|
// todo: check src_type parameter to be ( Digit radix )
|
||||||
|
|
||||||
match dst_type {
|
match dst_type {
|
||||||
|
@ -87,7 +88,7 @@ pub fn init_ctx(ctx: &mut Context) {
|
||||||
|
|
||||||
ctx.add_node_ctor(
|
ctx.add_node_ctor(
|
||||||
"PosInt", Arc::new(
|
"PosInt", Arc::new(
|
||||||
|ctx0: Arc<RwLock<Context>>, dst_typ: TypeTerm, depth: usize| {
|
|ctx0: Arc<RwLock<Context>>, dst_typ: TypeTerm, depth: OuterViewPort<dyn SingletonView<Item = usize>>| {
|
||||||
match dst_typ.clone() {
|
match dst_typ.clone() {
|
||||||
TypeTerm::App(args) => {
|
TypeTerm::App(args) => {
|
||||||
if args.len() > 1 {
|
if args.len() > 1 {
|
||||||
|
@ -105,7 +106,7 @@ pub fn init_ctx(ctx: &mut Context) {
|
||||||
.clone()
|
.clone()
|
||||||
.into()
|
.into()
|
||||||
]),
|
]),
|
||||||
depth+1
|
depth.map(|d| d+1)
|
||||||
).unwrap();
|
).unwrap();
|
||||||
|
|
||||||
node = node.morph(dst_typ);
|
node = node.morph(dst_typ);
|
||||||
|
|
|
@ -84,7 +84,7 @@ impl DigitEditor {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn into_node(self, depth: usize) -> NestedNode {
|
pub fn into_node(self, depth: OuterViewPort<dyn SingletonView<Item = usize>>) -> NestedNode {
|
||||||
let data = self.get_data();
|
let data = self.get_data();
|
||||||
let editor = Arc::new(RwLock::new(self));
|
let editor = Arc::new(RwLock::new(self));
|
||||||
let ed = editor.write().unwrap();
|
let ed = editor.write().unwrap();
|
||||||
|
@ -99,7 +99,7 @@ impl DigitEditor {
|
||||||
TerminalAtom::new(
|
TerminalAtom::new(
|
||||||
c.unwrap_or('?'),
|
c.unwrap_or('?'),
|
||||||
if c.unwrap_or('?').to_digit(r).is_some() {
|
if c.unwrap_or('?').to_digit(r).is_some() {
|
||||||
TerminalStyle::fg_color((100, 140, 100))
|
TerminalStyle::fg_color((90, 160, 90))
|
||||||
} else {
|
} else {
|
||||||
//TerminalStyle::bg_color((90, 10, 10))
|
//TerminalStyle::bg_color((90, 10, 10))
|
||||||
TerminalStyle::fg_color((200, 40, 40))
|
TerminalStyle::fg_color((200, 40, 40))
|
||||||
|
@ -146,7 +146,7 @@ impl PosIntEditor {
|
||||||
let mut node = Context::make_node(
|
let mut node = Context::make_node(
|
||||||
&ctx,
|
&ctx,
|
||||||
(&ctx, format!("( List ( Digit {} ) )", radix).as_str()).into(),
|
(&ctx, format!("( List ( Digit {} ) )", radix).as_str()).into(),
|
||||||
0
|
r3vi::buffer::singleton::SingletonBuffer::new(0).get_port()
|
||||||
).unwrap();
|
).unwrap();
|
||||||
|
|
||||||
// Set Type
|
// Set Type
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
use {
|
use {
|
||||||
|
r3vi::{view::{OuterViewPort, singleton::*}},
|
||||||
crate::{
|
crate::{
|
||||||
type_system::{Context, TypeTerm},
|
type_system::{Context, TypeTerm},
|
||||||
editors::list::{ListEditor, PTYListController, PTYListStyle}
|
editors::list::{ListEditor, PTYListController, PTYListStyle}
|
||||||
|
@ -14,7 +15,7 @@ pub fn init_ctx(ctx: &mut Context) {
|
||||||
|
|
||||||
ctx.add_node_ctor(
|
ctx.add_node_ctor(
|
||||||
"List", Arc::new(
|
"List", Arc::new(
|
||||||
|ctx: Arc<RwLock<Context>>, ty: TypeTerm, depth: usize| {
|
|ctx: Arc<RwLock<Context>>, ty: TypeTerm, depth: OuterViewPort<dyn SingletonView<Item = usize>>| {
|
||||||
match ty {
|
match ty {
|
||||||
TypeTerm::App(args) => {
|
TypeTerm::App(args) => {
|
||||||
if args.len() > 1 {
|
if args.len() > 1 {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use {
|
use {
|
||||||
r3vi::{
|
r3vi::{
|
||||||
view::{OuterViewPort, singleton::*, sequence::*},
|
view::{ViewPort, OuterViewPort, singleton::*, sequence::*},
|
||||||
buffer::{singleton::*, vec::*}
|
buffer::{singleton::*, vec::*}
|
||||||
},
|
},
|
||||||
crate::{
|
crate::{
|
||||||
|
@ -22,10 +22,12 @@ pub struct ListEditor {
|
||||||
pub data: VecBuffer< Arc<RwLock<NestedNode>> >,
|
pub data: VecBuffer< Arc<RwLock<NestedNode>> >,
|
||||||
|
|
||||||
pub spillbuf: Arc<RwLock<Vec<Arc<RwLock<NestedNode>>>>>,
|
pub spillbuf: Arc<RwLock<Vec<Arc<RwLock<NestedNode>>>>>,
|
||||||
|
|
||||||
pub(super) addr_port: OuterViewPort<dyn SequenceView<Item = isize>>,
|
pub(super) addr_port: OuterViewPort<dyn SequenceView<Item = isize>>,
|
||||||
pub(super) mode_port: OuterViewPort<dyn SingletonView<Item = ListCursorMode>>,
|
pub(super) mode_port: OuterViewPort<dyn SingletonView<Item = ListCursorMode>>,
|
||||||
|
|
||||||
|
depth: OuterViewPort<dyn SingletonView<Item = usize>>,
|
||||||
|
|
||||||
pub(crate) ctx: Arc<RwLock<Context>>,
|
pub(crate) ctx: Arc<RwLock<Context>>,
|
||||||
|
|
||||||
/// item type
|
/// item type
|
||||||
|
@ -95,13 +97,16 @@ impl ListEditor {
|
||||||
data,
|
data,
|
||||||
spillbuf: Arc::new(RwLock::new(Vec::new())),
|
spillbuf: Arc::new(RwLock::new(Vec::new())),
|
||||||
ctx,
|
ctx,
|
||||||
typ
|
typ,
|
||||||
|
depth: SingletonBuffer::new(0).get_port()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn into_node(self, depth: usize) -> NestedNode {
|
pub fn into_node(mut self, depth: OuterViewPort<dyn SingletonView<Item = usize>>) -> NestedNode {
|
||||||
let data = self.get_data();
|
let data = self.get_data();
|
||||||
let ctx = self.ctx.clone();
|
let ctx = self.ctx.clone();
|
||||||
|
|
||||||
|
self.depth = depth.clone();
|
||||||
let editor = Arc::new(RwLock::new(self));
|
let editor = Arc::new(RwLock::new(self));
|
||||||
|
|
||||||
let e = editor.read().unwrap();
|
let e = editor.read().unwrap();
|
||||||
|
@ -231,6 +236,10 @@ impl ListEditor {
|
||||||
if let Some(idx) = cur.idx {
|
if let Some(idx) = cur.idx {
|
||||||
match cur.mode {
|
match cur.mode {
|
||||||
ListCursorMode::Insert => {
|
ListCursorMode::Insert => {
|
||||||
|
item.read().unwrap().depth.0.set_view(
|
||||||
|
self.depth.map(|d| d+1).get_view()
|
||||||
|
);
|
||||||
|
|
||||||
self.data.insert(idx as usize, item.clone());
|
self.data.insert(idx as usize, item.clone());
|
||||||
if self.is_listlist() {
|
if self.is_listlist() {
|
||||||
cur.mode = ListCursorMode::Select;
|
cur.mode = ListCursorMode::Select;
|
||||||
|
@ -280,7 +289,7 @@ impl ListEditor {
|
||||||
self.nexd();
|
self.nexd();
|
||||||
|
|
||||||
let mut b = item.spillbuf.write().unwrap();
|
let mut b = item.spillbuf.write().unwrap();
|
||||||
let mut tail_node = Context::make_node(&self.ctx, self.typ.clone(), item.depth.get()).unwrap();
|
let mut tail_node = Context::make_node(&self.ctx, self.typ.clone(), self.depth.map(|d| d+1)).unwrap();
|
||||||
tail_node.goto(TreeCursor::home());
|
tail_node.goto(TreeCursor::home());
|
||||||
|
|
||||||
for node in b.iter() {
|
for node in b.iter() {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use {
|
use {
|
||||||
r3vi::{
|
r3vi::{
|
||||||
view::{OuterViewPort, sequence::*},
|
view::{ViewPort, OuterViewPort, sequence::*},
|
||||||
projection::decorate_sequence::*,
|
projection::decorate_sequence::*,
|
||||||
},
|
},
|
||||||
crate::{
|
crate::{
|
||||||
|
@ -18,23 +18,20 @@ use {
|
||||||
//<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>>
|
//<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>>
|
||||||
|
|
||||||
pub struct PTYListStyle {
|
pub struct PTYListStyle {
|
||||||
style: (String, String, String),
|
style: (String, String, String)
|
||||||
depth: usize
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PTYListStyle {
|
impl PTYListStyle {
|
||||||
pub fn new(style: (&str, &str, &str), depth: usize) -> PTYListStyle {
|
pub fn new(style: (&str, &str, &str)) -> PTYListStyle {
|
||||||
PTYListStyle {
|
PTYListStyle {
|
||||||
style: (style.0.into(), style.1.into(), style.2.into()),
|
style: (style.0.into(), style.1.into(), style.2.into())
|
||||||
depth
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_seg_seq_view(&self, editor: &ListEditor) -> OuterViewPort<dyn SequenceView<Item = OuterViewPort<dyn TerminalView>>> {
|
pub fn get_seg_seq_view(&self, editor: &ListEditor) -> OuterViewPort<dyn SequenceView<Item = OuterViewPort<dyn TerminalView>>> {
|
||||||
let seg_seq = ListSegmentSequence::new(
|
let seg_seq = ListSegmentSequence::new(
|
||||||
editor.get_cursor_port(),
|
editor.get_cursor_port(),
|
||||||
editor.get_data_port(),
|
editor.get_data_port()
|
||||||
self.depth
|
|
||||||
);
|
);
|
||||||
let se = seg_seq.read().unwrap();
|
let se = seg_seq.read().unwrap();
|
||||||
se.get_view().map(move |segment| segment.pty_view())
|
se.get_view().map(move |segment| segment.pty_view())
|
||||||
|
@ -43,8 +40,7 @@ impl PTYListStyle {
|
||||||
pub fn pty_view(&self, editor: &ListEditor) -> OuterViewPort<dyn TerminalView> {
|
pub fn pty_view(&self, editor: &ListEditor) -> OuterViewPort<dyn TerminalView> {
|
||||||
let seg_seq = ListSegmentSequence::new(
|
let seg_seq = ListSegmentSequence::new(
|
||||||
editor.get_cursor_port(),
|
editor.get_cursor_port(),
|
||||||
editor.get_data_port(),
|
editor.get_data_port()
|
||||||
self.depth
|
|
||||||
);
|
);
|
||||||
let seg_seq = seg_seq.read().unwrap();
|
let seg_seq = seg_seq.read().unwrap();
|
||||||
|
|
||||||
|
@ -59,7 +55,7 @@ impl PTYListStyle {
|
||||||
|
|
||||||
pub fn for_node(node: &mut NestedNode, style: (&str, &str, &str)) {
|
pub fn for_node(node: &mut NestedNode, style: (&str, &str, &str)) {
|
||||||
node.view = Some(
|
node.view = Some(
|
||||||
Self::new(style, node.depth.get())
|
Self::new(style)
|
||||||
.pty_view(
|
.pty_view(
|
||||||
&node.get_edit::<ListEditor>().unwrap().read().unwrap()
|
&node.get_edit::<ListEditor>().unwrap().read().unwrap()
|
||||||
)
|
)
|
||||||
|
@ -75,7 +71,7 @@ pub struct PTYListController {
|
||||||
split_char: Option<char>,
|
split_char: Option<char>,
|
||||||
close_char: Option<char>,
|
close_char: Option<char>,
|
||||||
|
|
||||||
depth: usize
|
depth: OuterViewPort<dyn SingletonView<Item = usize>>
|
||||||
}
|
}
|
||||||
|
|
||||||
//<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>>
|
//<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>>
|
||||||
|
@ -85,7 +81,7 @@ impl PTYListController {
|
||||||
editor: Arc<RwLock<ListEditor>>,
|
editor: Arc<RwLock<ListEditor>>,
|
||||||
split_char: Option<char>,
|
split_char: Option<char>,
|
||||||
close_char: Option<char>,
|
close_char: Option<char>,
|
||||||
depth: usize
|
depth: OuterViewPort<dyn SingletonView<Item = usize>>
|
||||||
) -> Self {
|
) -> Self {
|
||||||
PTYListController {
|
PTYListController {
|
||||||
editor,
|
editor,
|
||||||
|
@ -113,7 +109,7 @@ impl PTYListController {
|
||||||
}
|
}
|
||||||
|
|
||||||
let editor = node.get_edit::<ListEditor>().unwrap();
|
let editor = node.get_edit::<ListEditor>().unwrap();
|
||||||
let controller = Arc::new(RwLock::new(PTYListController::from_editor( editor, split_char, close_char, node.depth.get() )));
|
let controller = Arc::new(RwLock::new(PTYListController::from_editor( editor, split_char, close_char, node.depth.clone() )));
|
||||||
|
|
||||||
node.cmd.set(Some(controller.clone()));
|
node.cmd.set(Some(controller.clone()));
|
||||||
node.close_char.set(close_char);
|
node.close_char.set(close_char);
|
||||||
|
@ -131,10 +127,6 @@ impl PTYListController {
|
||||||
self.editor.read().unwrap().get_item()
|
self.editor.read().unwrap().get_item()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_depth(&mut self, depth: usize) {
|
|
||||||
self.depth = depth;
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn handle_term_event(&mut self, event: &TerminalEvent, _cmd_obj: Arc<RwLock<ReprTree>>) -> TreeNavResult {
|
pub fn handle_term_event(&mut self, event: &TerminalEvent, _cmd_obj: Arc<RwLock<ReprTree>>) -> TreeNavResult {
|
||||||
let mut e = self.editor.write().unwrap();
|
let mut e = self.editor.write().unwrap();
|
||||||
match event {
|
match event {
|
||||||
|
@ -176,7 +168,7 @@ impl PTYListController {
|
||||||
|
|
||||||
match cur.mode {
|
match cur.mode {
|
||||||
ListCursorMode::Insert => {
|
ListCursorMode::Insert => {
|
||||||
let mut new_edit = Context::make_node(&e.ctx, e.typ.clone(), self.depth+1).unwrap();
|
let mut new_edit = Context::make_node(&e.ctx, e.typ.clone(), self.depth.map(|d| d+1)).unwrap();
|
||||||
new_edit.goto(TreeCursor::home());
|
new_edit.goto(TreeCursor::home());
|
||||||
|
|
||||||
match new_edit.send_cmd_obj(cmd_obj.clone()) {
|
match new_edit.send_cmd_obj(cmd_obj.clone()) {
|
||||||
|
|
|
@ -22,7 +22,6 @@ pub enum ListSegment {
|
||||||
InsertCursor,
|
InsertCursor,
|
||||||
Item {
|
Item {
|
||||||
editor: NestedNode,
|
editor: NestedNode,
|
||||||
depth: usize,
|
|
||||||
cur_dist: isize,
|
cur_dist: isize,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -37,9 +36,8 @@ impl PtySegment for ListSegment {
|
||||||
.add_style_front(TerminalStyle::bold(true))
|
.add_style_front(TerminalStyle::bold(true))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
ListSegment::Item{ editor, depth, cur_dist } => {
|
ListSegment::Item{ editor, cur_dist } => {
|
||||||
let e = editor.clone();
|
let e = editor.clone();
|
||||||
let d = *depth;
|
|
||||||
let cur_dist = *cur_dist;
|
let cur_dist = *cur_dist;
|
||||||
editor.get_view().map_item(move |_pt, atom| {
|
editor.get_view().map_item(move |_pt, atom| {
|
||||||
let c = e.get_cursor();
|
let c = e.get_cursor();
|
||||||
|
@ -50,10 +48,11 @@ impl PtySegment for ListSegment {
|
||||||
} else {
|
} else {
|
||||||
usize::MAX
|
usize::MAX
|
||||||
};
|
};
|
||||||
|
|
||||||
atom
|
atom
|
||||||
.add_style_back(bg_style_from_depth(select))
|
.add_style_back(bg_style_from_depth(select))
|
||||||
.add_style_back(TerminalStyle::bold(select==1))
|
.add_style_back(TerminalStyle::bold(select==1))
|
||||||
.add_style_back(fg_style_from_depth(d))
|
.add_style_back(fg_style_from_depth(e.depth.get_view().get()))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -64,7 +63,6 @@ pub struct ListSegmentSequence {
|
||||||
data: Arc<dyn SequenceView<Item = NestedNode>>,
|
data: Arc<dyn SequenceView<Item = NestedNode>>,
|
||||||
cursor: Arc<dyn SingletonView<Item = ListCursor>>,
|
cursor: Arc<dyn SingletonView<Item = ListCursor>>,
|
||||||
|
|
||||||
depth: usize,
|
|
||||||
cur_cursor: ListCursor,
|
cur_cursor: ListCursor,
|
||||||
|
|
||||||
port: ViewPort<dyn SequenceView<Item = ListSegment>>,
|
port: ViewPort<dyn SequenceView<Item = ListSegment>>,
|
||||||
|
@ -95,7 +93,6 @@ impl SequenceView for ListSegmentSequence {
|
||||||
ListCursorMode::Select => {
|
ListCursorMode::Select => {
|
||||||
ListSegment::Item {
|
ListSegment::Item {
|
||||||
editor: self.data.get(idx)?,
|
editor: self.data.get(idx)?,
|
||||||
depth: self.depth,
|
|
||||||
cur_dist: cur - *idx as isize
|
cur_dist: cur - *idx as isize
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -103,7 +100,6 @@ impl SequenceView for ListSegmentSequence {
|
||||||
if *idx < cur as usize {
|
if *idx < cur as usize {
|
||||||
ListSegment::Item {
|
ListSegment::Item {
|
||||||
editor: self.data.get(idx)?,
|
editor: self.data.get(idx)?,
|
||||||
depth: self.depth,
|
|
||||||
cur_dist: cur - *idx as isize
|
cur_dist: cur - *idx as isize
|
||||||
}
|
}
|
||||||
} else if *idx == cur as usize {
|
} else if *idx == cur as usize {
|
||||||
|
@ -111,7 +107,6 @@ impl SequenceView for ListSegmentSequence {
|
||||||
} else {
|
} else {
|
||||||
ListSegment::Item {
|
ListSegment::Item {
|
||||||
editor: self.data.get(&(*idx - 1))?,
|
editor: self.data.get(&(*idx - 1))?,
|
||||||
depth: self.depth,
|
|
||||||
cur_dist: cur - *idx as isize
|
cur_dist: cur - *idx as isize
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -120,7 +115,6 @@ impl SequenceView for ListSegmentSequence {
|
||||||
} else {
|
} else {
|
||||||
ListSegment::Item {
|
ListSegment::Item {
|
||||||
editor: self.data.get(&idx)?,
|
editor: self.data.get(&idx)?,
|
||||||
depth: self.depth,
|
|
||||||
cur_dist: *idx as isize + 1
|
cur_dist: *idx as isize + 1
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -131,14 +125,12 @@ impl ListSegmentSequence {
|
||||||
pub fn new(
|
pub fn new(
|
||||||
cursor_port: OuterViewPort<dyn SingletonView<Item = ListCursor>>,
|
cursor_port: OuterViewPort<dyn SingletonView<Item = ListCursor>>,
|
||||||
data_port: OuterViewPort<dyn SequenceView<Item = NestedNode>>,
|
data_port: OuterViewPort<dyn SequenceView<Item = NestedNode>>,
|
||||||
depth: usize
|
|
||||||
) -> Arc<RwLock<Self>> {
|
) -> Arc<RwLock<Self>> {
|
||||||
let out_port = ViewPort::new();
|
let out_port = ViewPort::new();
|
||||||
let mut proj_helper = ProjectionHelper::new(out_port.update_hooks.clone());
|
let mut proj_helper = ProjectionHelper::new(out_port.update_hooks.clone());
|
||||||
let proj = Arc::new(RwLock::new(ListSegmentSequence {
|
let proj = Arc::new(RwLock::new(ListSegmentSequence {
|
||||||
cur_cursor: cursor_port.get_view().get(),
|
cur_cursor: cursor_port.get_view().get(),
|
||||||
port: out_port.clone(),
|
port: out_port.clone(),
|
||||||
depth,
|
|
||||||
|
|
||||||
cursor: proj_helper.new_singleton_arg(0, cursor_port, |s: &mut Self, _msg| {
|
cursor: proj_helper.new_singleton_arg(0, cursor_port, |s: &mut Self, _msg| {
|
||||||
let _old_cursor = s.cur_cursor;
|
let _old_cursor = s.cur_cursor;
|
||||||
|
|
|
@ -238,7 +238,7 @@ impl ObjCommander for ProductEditor {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let mut e = Context::make_node(&self.ctx, t.clone(), *ed_depth+1).unwrap();
|
let mut e = Context::make_node(&self.ctx, t.clone(), r3vi::buffer::singleton::SingletonBuffer::new(*ed_depth).get_port()).unwrap();
|
||||||
*editor = Some(e.clone());
|
*editor = Some(e.clone());
|
||||||
update_segment = true;
|
update_segment = true;
|
||||||
|
|
||||||
|
|
|
@ -71,7 +71,7 @@ impl TreeNav for ProductEditor {
|
||||||
e.goto(c.clone());
|
e.goto(c.clone());
|
||||||
} else if c.tree_addr.len() > 0 {
|
} else if c.tree_addr.len() > 0 {
|
||||||
// create editor
|
// create editor
|
||||||
let mut e = Context::make_node(&self.ctx, t.clone(), *ed_depth+1).unwrap();
|
let mut e = Context::make_node(&self.ctx, t.clone(), r3vi::buffer::singleton::SingletonBuffer::new(*ed_depth+1).get_port()).unwrap();
|
||||||
*editor = Some(e.clone());
|
*editor = Some(e.clone());
|
||||||
e.goto(c.clone());
|
e.goto(c.clone());
|
||||||
}
|
}
|
||||||
|
@ -128,7 +128,7 @@ impl TreeNav for ProductEditor {
|
||||||
} else {
|
} else {
|
||||||
// create editor
|
// create editor
|
||||||
|
|
||||||
let mut e = Context::make_node(&self.ctx, t.clone(), *ed_depth+1).unwrap();
|
let mut e = Context::make_node(&self.ctx, t.clone(), r3vi::buffer::singleton::SingletonBuffer::new(*ed_depth+1).get_port()).unwrap();
|
||||||
*editor = Some(e.clone());
|
*editor = Some(e.clone());
|
||||||
e.goby(direction);
|
e.goby(direction);
|
||||||
}
|
}
|
||||||
|
|
|
@ -60,7 +60,7 @@ impl SumEditor {
|
||||||
NestedNode::new(
|
NestedNode::new(
|
||||||
ctx.clone(),
|
ctx.clone(),
|
||||||
ReprTree::new_arc(TypeTerm::TypeID(ctx.read().unwrap().get_typeid("Sum").unwrap())),
|
ReprTree::new_arc(TypeTerm::TypeID(ctx.read().unwrap().get_typeid("Sum").unwrap())),
|
||||||
0
|
r3vi::buffer::singleton::SingletonBuffer::new(0).get_port()
|
||||||
)
|
)
|
||||||
.set_view(view)
|
.set_view(view)
|
||||||
.set_editor(editor.clone())
|
.set_editor(editor.clone())
|
||||||
|
|
|
@ -44,7 +44,7 @@ impl ObjCommander for TypeTermEditor {
|
||||||
TreeNavResult::Exit
|
TreeNavResult::Exit
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
self.set_state( State::AnySymbol );
|
self.set_state( State::FunSymbol );
|
||||||
self.cur_node.get_mut().goto(TreeCursor::home());
|
self.cur_node.get_mut().goto(TreeCursor::home());
|
||||||
self.send_child_cmd( co )
|
self.send_child_cmd( co )
|
||||||
}
|
}
|
||||||
|
@ -67,9 +67,9 @@ impl ObjCommander for TypeTermEditor {
|
||||||
if c == '~' {
|
if c == '~' {
|
||||||
let i0 = self.cur_node.get().get_edit::<ListEditor>().unwrap();
|
let i0 = self.cur_node.get().get_edit::<ListEditor>().unwrap();
|
||||||
|
|
||||||
let cur_it = i0.clone().read().unwrap().get_item().clone();
|
if self.get_cursor().tree_addr.len() > 1 {
|
||||||
|
let cur_it = i0.clone().read().unwrap().get_item().clone();
|
||||||
if let Some(i) = cur_it {
|
if let Some(i) = cur_it {
|
||||||
let tte = i.get_edit::<TypeTermEditor>().unwrap();
|
let tte = i.get_edit::<TypeTermEditor>().unwrap();
|
||||||
|
|
||||||
if tte.read().unwrap().state != State::App {
|
if tte.read().unwrap().state != State::App {
|
||||||
|
@ -81,6 +81,9 @@ impl ObjCommander for TypeTermEditor {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
return TreeNavResult::Continue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
self.send_child_cmd( co.clone() )
|
self.send_child_cmd( co.clone() )
|
||||||
|
|
|
@ -1,8 +1,15 @@
|
||||||
use {
|
use {
|
||||||
|
r3vi::{
|
||||||
|
view::{OuterViewPort, singleton::*}
|
||||||
|
},
|
||||||
crate::{
|
crate::{
|
||||||
type_system::{Context, TypeTerm, MorphismTypePattern},
|
type_system::{Context, TypeTerm, MorphismTypePattern},
|
||||||
terminal::{TerminalStyle, TerminalProjections},
|
terminal::{TerminalStyle, TerminalProjections},
|
||||||
editors::{list::{PTYListStyle, PTYListController}, typeterm::{State, TypeTermEditor}}
|
editors::{
|
||||||
|
list::{PTYListStyle, PTYListController, ListEditor, ListSegmentSequence},
|
||||||
|
typeterm::{State, TypeTermEditor}
|
||||||
|
},
|
||||||
|
PtySegment
|
||||||
},
|
},
|
||||||
std::{sync::{Arc, RwLock}},
|
std::{sync::{Arc, RwLock}},
|
||||||
cgmath::{Point2}
|
cgmath::{Point2}
|
||||||
|
@ -25,7 +32,7 @@ pub fn init_ctx(ctx: &mut Context) {
|
||||||
let ctx : Arc<RwLock<Context>> = Arc::new(RwLock::new(Context::with_parent(Some(node.ctx.clone()))));
|
let ctx : Arc<RwLock<Context>> = Arc::new(RwLock::new(Context::with_parent(Some(node.ctx.clone()))));
|
||||||
ctx.write().unwrap().meta_chars.push('~');
|
ctx.write().unwrap().meta_chars.push('~');
|
||||||
|
|
||||||
let new_node = TypeTermEditor::with_node( ctx, node.depth.get(), node.clone(), State::Any );
|
let new_node = TypeTermEditor::with_node( ctx, node.clone(), State::Any );
|
||||||
Some(new_node)
|
Some(new_node)
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
@ -38,7 +45,7 @@ pub fn init_ctx(ctx: &mut Context) {
|
||||||
if vertical_view {
|
if vertical_view {
|
||||||
let editor = node.get_edit::<crate::editors::list::ListEditor>().unwrap();
|
let editor = node.get_edit::<crate::editors::list::ListEditor>().unwrap();
|
||||||
let mut e = editor.write().unwrap();
|
let mut e = editor.write().unwrap();
|
||||||
let seg_view = PTYListStyle::new( ("","~",""), node.depth.get() ).get_seg_seq_view( &mut e );
|
let seg_view = PTYListStyle::new( ("","~","") ).get_seg_seq_view( &mut e );
|
||||||
|
|
||||||
node = node.set_view(
|
node = node.set_view(
|
||||||
seg_view.to_grid_vertical().flatten()
|
seg_view.to_grid_vertical().flatten()
|
||||||
|
@ -71,6 +78,7 @@ pub fn init_ctx(ctx: &mut Context) {
|
||||||
Arc::new(|mut node, _dst_type:_| {
|
Arc::new(|mut node, _dst_type:_| {
|
||||||
PTYListController::for_node( &mut node, Some(' '), None );
|
PTYListController::for_node( &mut node, Some(' '), None );
|
||||||
PTYListStyle::for_node( &mut node, ("","","") );
|
PTYListStyle::for_node( &mut node, ("","","") );
|
||||||
|
|
||||||
Some(node)
|
Some(node)
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
@ -80,11 +88,6 @@ pub fn init_ctx(ctx: &mut Context) {
|
||||||
PTYListController::for_node( &mut node, Some(' '), None );
|
PTYListController::for_node( &mut node, Some(' '), None );
|
||||||
PTYListStyle::for_node( &mut node, ("","","") );
|
PTYListStyle::for_node( &mut node, ("","","") );
|
||||||
|
|
||||||
// display variables blue color
|
|
||||||
if let Some(v) = node.view {
|
|
||||||
node.view = Some(
|
|
||||||
v.map_item(|_i,p| p.add_style_front(TerminalStyle::fg_color((5, 120, 240)))));
|
|
||||||
}
|
|
||||||
Some(node)
|
Some(node)
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
@ -117,7 +120,7 @@ pub fn init_ctx(ctx: &mut Context) {
|
||||||
}));
|
}));
|
||||||
|
|
||||||
ctx.add_node_ctor("Type", Arc::new(
|
ctx.add_node_ctor("Type", Arc::new(
|
||||||
|ctx: Arc<RwLock<Context>>, _ty: TypeTerm, depth: usize| {
|
|ctx: Arc<RwLock<Context>>, _ty: TypeTerm, depth: OuterViewPort<dyn SingletonView<Item = usize>>| {
|
||||||
Some(TypeTermEditor::new_node(ctx, depth))
|
Some(TypeTermEditor::new_node(ctx, depth))
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@ pub use ctx::init_ctx;
|
||||||
|
|
||||||
use {
|
use {
|
||||||
r3vi::{
|
r3vi::{
|
||||||
|
view::{OuterViewPort, singleton::*},
|
||||||
buffer::{singleton::*}
|
buffer::{singleton::*}
|
||||||
},
|
},
|
||||||
crate::{
|
crate::{
|
||||||
|
@ -36,9 +37,10 @@ pub struct TypeTermEditor {
|
||||||
data: Arc<RwLock<ReprTree>>,
|
data: Arc<RwLock<ReprTree>>,
|
||||||
close_char: SingletonBuffer<Option<char>>,
|
close_char: SingletonBuffer<Option<char>>,
|
||||||
spillbuf: Arc<RwLock<Vec<Arc<RwLock<NestedNode>>>>>,
|
spillbuf: Arc<RwLock<Vec<Arc<RwLock<NestedNode>>>>>,
|
||||||
|
depth: OuterViewPort<dyn SingletonView<Item = usize>>,
|
||||||
|
|
||||||
depth: usize,
|
buf: SingletonBuffer< TypeTerm >,
|
||||||
|
|
||||||
// editing/parsing state
|
// editing/parsing state
|
||||||
state: State,
|
state: State,
|
||||||
|
|
||||||
|
@ -47,8 +49,8 @@ pub struct TypeTermEditor {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TypeTermEditor {
|
impl TypeTermEditor {
|
||||||
pub fn from_type_term(ctx: Arc<RwLock<Context>>, depth: usize, term: &TypeTerm) -> NestedNode {
|
pub fn from_type_term(ctx: Arc<RwLock<Context>>, depth: OuterViewPort<dyn SingletonView<Item = usize>>, term: &TypeTerm) -> NestedNode {
|
||||||
let mut node = TypeTermEditor::new_node(ctx.clone(), depth);
|
let mut node = TypeTermEditor::new_node(ctx.clone(), depth.clone());
|
||||||
node.goto(TreeCursor::home());
|
node.goto(TreeCursor::home());
|
||||||
|
|
||||||
match term {
|
match term {
|
||||||
|
@ -74,7 +76,7 @@ impl TypeTermEditor {
|
||||||
let parent_ctx = editor.read().unwrap().cur_node.get().ctx.clone();
|
let parent_ctx = editor.read().unwrap().cur_node.get().ctx.clone();
|
||||||
|
|
||||||
for x in args.iter() {
|
for x in args.iter() {
|
||||||
let arg_node = TypeTermEditor::from_type_term( parent_ctx.clone(), depth+1, x );
|
let arg_node = TypeTermEditor::from_type_term( parent_ctx.clone(), depth.map(|d| d+1), x );
|
||||||
|
|
||||||
node.send_cmd_obj(
|
node.send_cmd_obj(
|
||||||
ReprTree::new_leaf(
|
ReprTree::new_leaf(
|
||||||
|
@ -92,7 +94,7 @@ impl TypeTermEditor {
|
||||||
let parent_ctx = editor.read().unwrap().cur_node.get().ctx.clone();
|
let parent_ctx = editor.read().unwrap().cur_node.get().ctx.clone();
|
||||||
|
|
||||||
for x in args.iter() {
|
for x in args.iter() {
|
||||||
let arg_node = TypeTermEditor::from_type_term( parent_ctx.clone(), depth+1, x );
|
let arg_node = TypeTermEditor::from_type_term( parent_ctx.clone(), depth.map(|d| d+1), x );
|
||||||
|
|
||||||
node.send_cmd_obj(
|
node.send_cmd_obj(
|
||||||
ReprTree::new_leaf(
|
ReprTree::new_leaf(
|
||||||
|
@ -130,28 +132,27 @@ impl TypeTermEditor {
|
||||||
fn set_state(&mut self, new_state: State) {
|
fn set_state(&mut self, new_state: State) {
|
||||||
let mut node = match new_state {
|
let mut node = match new_state {
|
||||||
State::Any => {
|
State::Any => {
|
||||||
Context::make_node( &self.ctx, (&self.ctx, "( List Char )").into(), self.depth ).unwrap()
|
Context::make_node( &self.ctx, (&self.ctx, "( List Char )").into(), self.depth.map(|x| x) ).unwrap()
|
||||||
.morph( (&self.ctx, "( Type::Sym )").into() )
|
.morph( (&self.ctx, "( Type::Sym )").into() )
|
||||||
|
|
||||||
}
|
}
|
||||||
State::App => {
|
State::App => {
|
||||||
Context::make_node( &self.ctx, (&self.ctx, "( List Type )").into(), self.depth ).unwrap()
|
Context::make_node( &self.ctx, (&self.ctx, "( List Type )").into(), self.depth.map(|x| x) ).unwrap()
|
||||||
.morph( (&self.ctx, "( Type::App )").into() )
|
.morph( (&self.ctx, "( Type::App )").into() )
|
||||||
}
|
}
|
||||||
State::Ladder => {
|
State::Ladder => {
|
||||||
Context::make_node( &self.ctx, (&self.ctx, "( List Type )").into(), self.depth ).unwrap()
|
Context::make_node( &self.ctx, (&self.ctx, "( List Type )").into(), self.depth.map(|x| x) ).unwrap()
|
||||||
.morph( (&self.ctx, "( Type::Ladder )").into() )
|
.morph( (&self.ctx, "( Type::Ladder )").into() )
|
||||||
}
|
}
|
||||||
State::AnySymbol => {
|
State::AnySymbol => {
|
||||||
Context::make_node( &self.ctx, (&self.ctx, "( List Char )").into(), self.depth ).unwrap()
|
Context::make_node( &self.ctx, (&self.ctx, "( List Char )").into(), self.depth.map(|x| x) ).unwrap()
|
||||||
.morph( (&self.ctx, "( Type::Sym )").into() )
|
.morph( (&self.ctx, "( Type::Sym )").into() )
|
||||||
},
|
},
|
||||||
State::FunSymbol => {
|
State::FunSymbol => {
|
||||||
Context::make_node( &self.ctx, (&self.ctx, "( List Char )").into(), self.depth ).unwrap()
|
Context::make_node( &self.ctx, (&self.ctx, "( List Char )").into(), self.depth.map(|x| x) ).unwrap()
|
||||||
.morph( (&self.ctx, "( Type::Sym::Fun )").into() )
|
.morph( (&self.ctx, "( Type::Sym::Fun )").into() )
|
||||||
},
|
},
|
||||||
State::VarSymbol => {
|
State::VarSymbol => {
|
||||||
Context::make_node( &self.ctx, (&self.ctx, "( List Char )").into(), self.depth ).unwrap()
|
Context::make_node( &self.ctx, (&self.ctx, "( List Char )").into(), self.depth.map(|x| x) ).unwrap()
|
||||||
.morph( (&self.ctx, "( Type::Sym::Var )").into() )
|
.morph( (&self.ctx, "( Type::Sym::Var )").into() )
|
||||||
}
|
}
|
||||||
State::Num => {
|
State::Num => {
|
||||||
|
@ -160,7 +161,7 @@ impl TypeTermEditor {
|
||||||
.morph( (&self.ctx, "( Type::Lit::Num )").into() )
|
.morph( (&self.ctx, "( Type::Lit::Num )").into() )
|
||||||
}
|
}
|
||||||
State::Char => {
|
State::Char => {
|
||||||
Context::make_node( &self.ctx, (&self.ctx, "( Char )").into(), self.depth ).unwrap()
|
Context::make_node( &self.ctx, (&self.ctx, "( Char )").into(), self.depth.map(|x| x) ).unwrap()
|
||||||
.morph( (&self.ctx, "( Type::Lit::Char )").into() )
|
.morph( (&self.ctx, "( Type::Lit::Char )").into() )
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -173,7 +174,7 @@ impl TypeTermEditor {
|
||||||
self.state = new_state;
|
self.state = new_state;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new_node(ctx: Arc<RwLock<Context>>, depth: usize) -> NestedNode {
|
pub fn new_node(ctx: Arc<RwLock<Context>>, depth: OuterViewPort<dyn SingletonView<Item = usize>>) -> NestedNode {
|
||||||
let ctx : Arc<RwLock<Context>> = Arc::new(RwLock::new(Context::with_parent(Some(ctx))));
|
let ctx : Arc<RwLock<Context>> = Arc::new(RwLock::new(Context::with_parent(Some(ctx))));
|
||||||
ctx.write().unwrap().meta_chars.push('~');
|
ctx.write().unwrap().meta_chars.push('~');
|
||||||
|
|
||||||
|
@ -182,14 +183,13 @@ impl TypeTermEditor {
|
||||||
|
|
||||||
Self::with_node(
|
Self::with_node(
|
||||||
ctx.clone(),
|
ctx.clone(),
|
||||||
depth,
|
|
||||||
symb_node,
|
symb_node,
|
||||||
State::Any
|
State::Any
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn with_node(ctx: Arc<RwLock<Context>>, depth: usize, node: NestedNode, state: State) -> NestedNode {
|
fn with_node(ctx: Arc<RwLock<Context>>, cur_node: NestedNode, state: State) -> NestedNode {
|
||||||
let _buffer = SingletonBuffer::<Option<TypeTerm>>::new( None );
|
let buf = SingletonBuffer::<TypeTerm>::new( TypeTerm::unit() );
|
||||||
|
|
||||||
let data = Arc::new(RwLock::new(ReprTree::new(
|
let data = Arc::new(RwLock::new(ReprTree::new(
|
||||||
(&ctx, "( Type )")
|
(&ctx, "( Type )")
|
||||||
|
@ -199,10 +199,11 @@ impl TypeTermEditor {
|
||||||
ctx: ctx.clone(),
|
ctx: ctx.clone(),
|
||||||
data: data.clone(),
|
data: data.clone(),
|
||||||
state,
|
state,
|
||||||
cur_node: SingletonBuffer::new(node),
|
buf,
|
||||||
|
cur_node: SingletonBuffer::new(cur_node.clone()),
|
||||||
close_char: SingletonBuffer::new(None),
|
close_char: SingletonBuffer::new(None),
|
||||||
spillbuf: Arc::new(RwLock::new(Vec::new())),
|
spillbuf: Arc::new(RwLock::new(Vec::new())),
|
||||||
depth
|
depth: cur_node.depth.clone()
|
||||||
};
|
};
|
||||||
|
|
||||||
let view = editor.cur_node
|
let view = editor.cur_node
|
||||||
|
@ -215,16 +216,16 @@ impl TypeTermEditor {
|
||||||
let _cc = editor.cur_node.get().close_char;
|
let _cc = editor.cur_node.get().close_char;
|
||||||
let editor = Arc::new(RwLock::new(editor));
|
let editor = Arc::new(RwLock::new(editor));
|
||||||
|
|
||||||
let mut node = NestedNode::new(ctx, data, depth)
|
let mut super_node = NestedNode::new(ctx, data, cur_node.depth)
|
||||||
.set_view(view)
|
.set_view(view)
|
||||||
.set_nav(editor.clone())
|
.set_nav(editor.clone())
|
||||||
.set_cmd(editor.clone())
|
.set_cmd(editor.clone())
|
||||||
.set_editor(editor.clone());
|
.set_editor(editor.clone());
|
||||||
|
|
||||||
editor.write().unwrap().close_char = node.close_char.clone();
|
editor.write().unwrap().close_char = super_node.close_char.clone();
|
||||||
node.spillbuf = editor.read().unwrap().spillbuf.clone();
|
super_node.spillbuf = editor.read().unwrap().spillbuf.clone();
|
||||||
|
|
||||||
node
|
super_node
|
||||||
}
|
}
|
||||||
|
|
||||||
fn forward_spill(&mut self) {
|
fn forward_spill(&mut self) {
|
||||||
|
@ -288,16 +289,17 @@ impl TypeTermEditor {
|
||||||
|
|
||||||
let subladder_list_edit = subladder_list_edit.read().unwrap();
|
let subladder_list_edit = subladder_list_edit.read().unwrap();
|
||||||
if subladder_list_edit.data.len() == 0 {
|
if subladder_list_edit.data.len() == 0 {
|
||||||
|
|
||||||
self.set_state( State::Any );
|
self.set_state( State::Any );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* unwrap a ladder if it only contains one element
|
/* unwrap a ladder if it only contains one element
|
||||||
*/
|
*/
|
||||||
pub fn normalize_singleton(&mut self) {
|
pub fn normalize_singleton(&mut self) {
|
||||||
eprintln!("normalize singleton");
|
eprintln!("normalize singleton");
|
||||||
|
|
||||||
|
if self.state == State::Ladder{
|
||||||
|
|
||||||
let subladder_list_node = self.cur_node.get().clone();
|
let subladder_list_node = self.cur_node.get().clone();
|
||||||
let subladder_list_edit = subladder_list_node.get_edit::<ListEditor>().unwrap();
|
let subladder_list_edit = subladder_list_node.get_edit::<ListEditor>().unwrap();
|
||||||
|
|
||||||
|
@ -312,11 +314,15 @@ impl TypeTermEditor {
|
||||||
|
|
||||||
other_tt.normalize_singleton();
|
other_tt.normalize_singleton();
|
||||||
|
|
||||||
|
other_tt.depth.0.set_view( self.depth.map(|x| x).get_view() );
|
||||||
|
|
||||||
self.close_char.set(other_tt.close_char.get());
|
self.close_char.set(other_tt.close_char.get());
|
||||||
self.cur_node.set(other_tt.cur_node.get());
|
self.cur_node.set(other_tt.cur_node.get());
|
||||||
self.state = other_tt.state;
|
self.state = other_tt.state;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* in insert mode, morph the previous element into a ladder and continue there
|
/* in insert mode, morph the previous element into a ladder and continue there
|
||||||
|
@ -352,14 +358,13 @@ impl TypeTermEditor {
|
||||||
_ => {
|
_ => {
|
||||||
item_typterm.goto(TreeCursor::none());
|
item_typterm.goto(TreeCursor::none());
|
||||||
drop(item_typterm);
|
drop(item_typterm);
|
||||||
|
|
||||||
// else create new ladder
|
// else create new ladder
|
||||||
let mut list_node = Context::make_node( &self.ctx, (&self.ctx, "( List Type )").into(), self.depth ).unwrap();
|
let mut list_node = Context::make_node( &self.ctx, (&self.ctx, "( List Type )").into(), self.depth.map(|d| d+1) ).unwrap();
|
||||||
list_node = list_node.morph( (&self.ctx, "( Type::Ladder )").into() );
|
list_node = list_node.morph( (&self.ctx, "( Type::Ladder )").into() );
|
||||||
|
|
||||||
let mut new_node = TypeTermEditor::with_node(
|
let mut new_node = TypeTermEditor::with_node(
|
||||||
self.ctx.clone(),
|
self.ctx.clone(),
|
||||||
self.depth,
|
|
||||||
list_node,
|
list_node,
|
||||||
State::Ladder
|
State::Ladder
|
||||||
);
|
);
|
||||||
|
@ -382,18 +387,20 @@ impl TypeTermEditor {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: morph_to_app() / morph_to_list(state)
|
||||||
|
|
||||||
/* replace with new ladder node with self as first element
|
/* replace with new ladder node with self as first element
|
||||||
*/
|
*/
|
||||||
pub fn morph_to_ladder(&mut self) {
|
pub fn morph_to_ladder(&mut self) {
|
||||||
eprintln!("morph into ladder");
|
eprintln!("morph into ladder");
|
||||||
|
|
||||||
let old_node = self.cur_node.get().clone();
|
let old_node = self.cur_node.get().clone();
|
||||||
|
|
||||||
*old_node.depth.get_mut() += 1;
|
|
||||||
|
|
||||||
/* create a new NestedNode with TerminaltypeEditor,
|
/* create a new NestedNode with TerminaltypeEditor,
|
||||||
* that has same state & child-node as current node.
|
* that has same state & child-node as current node.
|
||||||
*/
|
*/
|
||||||
let old_edit_node = TypeTermEditor::new_node( self.ctx.clone(), self.depth );
|
let old_edit_node = TypeTermEditor::new_node( self.ctx.clone(), self.depth.map(|d| d + 1));
|
||||||
|
old_node.depth.0.set_view( self.depth.map(|d| d + 1).get_view() );
|
||||||
let old_edit_clone = old_edit_node.get_edit::<TypeTermEditor>().unwrap();
|
let old_edit_clone = old_edit_node.get_edit::<TypeTermEditor>().unwrap();
|
||||||
old_edit_clone.write().unwrap().set_state( self.state );
|
old_edit_clone.write().unwrap().set_state( self.state );
|
||||||
old_edit_clone.write().unwrap().close_char.set( old_node.close_char.get() );
|
old_edit_clone.write().unwrap().close_char.set( old_node.close_char.get() );
|
||||||
|
@ -401,7 +408,7 @@ impl TypeTermEditor {
|
||||||
|
|
||||||
/* create new list-edit node for the ladder
|
/* create new list-edit node for the ladder
|
||||||
*/
|
*/
|
||||||
let mut new_node = Context::make_node( &self.ctx, (&self.ctx, "( List Type )").into(), self.depth ).unwrap();
|
let mut new_node = Context::make_node( &self.ctx, (&self.ctx, "( List Type )").into(), self.depth.map(|x| x) ).unwrap();
|
||||||
new_node = new_node.morph( (&self.ctx, "( Type::Ladder )").into() );
|
new_node = new_node.morph( (&self.ctx, "( Type::Ladder )").into() );
|
||||||
|
|
||||||
/* reconfigure current node to display new_node list-editor
|
/* reconfigure current node to display new_node list-editor
|
||||||
|
|
|
@ -82,16 +82,13 @@ pub struct NestedNode {
|
||||||
pub diag: Option< OuterViewPort<dyn SequenceView<Item = Message>> >,
|
pub diag: Option< OuterViewPort<dyn SequenceView<Item = Message>> >,
|
||||||
|
|
||||||
/// depth
|
/// depth
|
||||||
pub depth: SingletonBuffer< usize >,
|
pub depth: OuterViewPort< dyn SingletonView<Item = usize> >,
|
||||||
|
|
||||||
/// abstract editor
|
/// abstract editor
|
||||||
pub editor: SingletonBuffer<
|
pub editor: SingletonBuffer<
|
||||||
Option< Arc<dyn Any + Send + Sync> >
|
Option< Arc<dyn Any + Send + Sync> >
|
||||||
>,
|
>,
|
||||||
|
|
||||||
/* TODO:
|
|
||||||
* - spill buffer (contains overflowing elements as well as 'split-off' parts)
|
|
||||||
*/
|
|
||||||
pub spillbuf: Arc<RwLock<Vec<Arc<RwLock<NestedNode>>>>>,
|
pub spillbuf: Arc<RwLock<Vec<Arc<RwLock<NestedNode>>>>>,
|
||||||
|
|
||||||
/// commander & navigation
|
/// commander & navigation
|
||||||
|
@ -107,13 +104,13 @@ pub struct NestedNode {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl NestedNode {
|
impl NestedNode {
|
||||||
pub fn new(ctx: Arc<RwLock<Context>>, data: Arc<RwLock<ReprTree>>, depth: usize) -> Self {
|
pub fn new(ctx: Arc<RwLock<Context>>, data: Arc<RwLock<ReprTree>>, depth: OuterViewPort<dyn SingletonView<Item = usize>>) -> Self {
|
||||||
NestedNode {
|
NestedNode {
|
||||||
ctx,
|
ctx,
|
||||||
data,
|
data,
|
||||||
view: None,
|
view: None,
|
||||||
diag: None,
|
diag: None,
|
||||||
depth: SingletonBuffer::new(depth),
|
depth,
|
||||||
editor: SingletonBuffer::new(None),
|
editor: SingletonBuffer::new(None),
|
||||||
spillbuf: Arc::new(RwLock::new(Vec::new())),
|
spillbuf: Arc::new(RwLock::new(Vec::new())),
|
||||||
cmd: SingletonBuffer::new(None),
|
cmd: SingletonBuffer::new(None),
|
||||||
|
@ -133,7 +130,7 @@ impl NestedNode {
|
||||||
(&ctx, "( Char )"),
|
(&ctx, "( Char )"),
|
||||||
buf.get_port().into()
|
buf.get_port().into()
|
||||||
),
|
),
|
||||||
0
|
SingletonBuffer::new(0).get_port()
|
||||||
)
|
)
|
||||||
.set_view(buf.get_port()
|
.set_view(buf.get_port()
|
||||||
.map(|c| TerminalAtom::from(c))
|
.map(|c| TerminalAtom::from(c))
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
use {
|
use {
|
||||||
|
r3vi::{view::{OuterViewPort, singleton::*}, buffer::{singleton::*}},
|
||||||
crate::{
|
crate::{
|
||||||
type_system::{TypeDict, TypeTerm, TypeID, ReprTree},
|
type_system::{TypeDict, TypeTerm, TypeID, ReprTree},
|
||||||
tree::NestedNode
|
tree::NestedNode
|
||||||
|
@ -229,7 +230,7 @@ impl Context {
|
||||||
self.type_dict.read().unwrap().type_term_to_str(&t)
|
self.type_dict.read().unwrap().type_term_to_str(&t)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add_node_ctor(&mut self, tn: &str, mk_editor: Arc<dyn Fn(Arc<RwLock<Self>>, TypeTerm, usize) -> Option<NestedNode> + Send + Sync>) {
|
pub fn add_node_ctor(&mut self, tn: &str, mk_editor: Arc<dyn Fn(Arc<RwLock<Self>>, TypeTerm, OuterViewPort<dyn SingletonView<Item = usize>>) -> Option<NestedNode> + Send + Sync>) {
|
||||||
let dict = self.type_dict.clone();
|
let dict = self.type_dict.clone();
|
||||||
let mut dict = dict.write().unwrap();
|
let mut dict = dict.write().unwrap();
|
||||||
|
|
||||||
|
@ -248,7 +249,7 @@ impl Context {
|
||||||
drop(dict);
|
drop(dict);
|
||||||
|
|
||||||
self.add_morphism(morphism_pattern, Arc::new(move |node, dst_type| {
|
self.add_morphism(morphism_pattern, Arc::new(move |node, dst_type| {
|
||||||
mk_editor(node.ctx.clone(), dst_type, node.depth.get())
|
mk_editor(node.ctx.clone(), dst_type, node.depth)
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -275,7 +276,7 @@ impl Context {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn make_node(ctx: &Arc<RwLock<Self>>, type_term: TypeTerm, depth: usize) -> Option<NestedNode> {
|
pub fn make_node(ctx: &Arc<RwLock<Self>>, type_term: TypeTerm, depth: OuterViewPort<dyn SingletonView<Item = usize>>) -> Option<NestedNode> {
|
||||||
let mk_node = ctx.read().unwrap().get_morphism(MorphismType {
|
let mk_node = ctx.read().unwrap().get_morphism(MorphismType {
|
||||||
src_type: None,
|
src_type: None,
|
||||||
dst_type: type_term.clone()
|
dst_type: type_term.clone()
|
||||||
|
@ -284,7 +285,6 @@ impl Context {
|
||||||
/* create new context per node ?? too heavy.. whats the reason? TODO */
|
/* create new context per node ?? too heavy.. whats the reason? TODO */
|
||||||
|
|
||||||
let new_ctx = Arc::new(RwLock::new(Context::with_parent(Some(ctx.clone()))));
|
let new_ctx = Arc::new(RwLock::new(Context::with_parent(Some(ctx.clone()))));
|
||||||
let _new_depth = depth;
|
|
||||||
|
|
||||||
mk_node(
|
mk_node(
|
||||||
NestedNode::new(new_ctx, ReprTree::new_arc(type_term.clone()), depth),
|
NestedNode::new(new_ctx, ReprTree::new_arc(type_term.clone()), depth),
|
||||||
|
@ -323,7 +323,7 @@ impl Context {
|
||||||
.type_dict.read().unwrap()
|
.type_dict.read().unwrap()
|
||||||
.type_term_from_str(typename).unwrap();
|
.type_term_from_str(typename).unwrap();
|
||||||
|
|
||||||
if let Some(node) = Context::make_node(&ctx, type_tag, 0) {
|
if let Some(node) = Context::make_node(&ctx, type_tag, SingletonBuffer::new(0).get_port()) {
|
||||||
ctx.write().unwrap().nodes.insert(name, node);
|
ctx.write().unwrap().nodes.insert(name, node);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,23 +5,27 @@ use {
|
||||||
pub fn bg_style_from_depth(depth: usize) -> TerminalStyle {
|
pub fn bg_style_from_depth(depth: usize) -> TerminalStyle {
|
||||||
match depth {
|
match depth {
|
||||||
0 => TerminalStyle::bg_color((150,80,230)),
|
0 => TerminalStyle::bg_color((150,80,230)),
|
||||||
1 => TerminalStyle::bg_color((75,75,75)),
|
1 => TerminalStyle::bg_color((66,66,66)),
|
||||||
2 => TerminalStyle::bg_color((40,40,40)),
|
2 => TerminalStyle::bg_color((44,44,44)),
|
||||||
3 => TerminalStyle::bg_color((30,30,30)),
|
3 => TerminalStyle::bg_color((33,33,33)),
|
||||||
4 => TerminalStyle::bg_color((25,25,25)),
|
4 => TerminalStyle::bg_color((28,28,28)),
|
||||||
5 => TerminalStyle::bg_color((20,20,20)),
|
5 => TerminalStyle::bg_color((21,21,21)),
|
||||||
_ => TerminalStyle::default(),
|
_ => TerminalStyle::default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn fg_style_from_depth(depth: usize) -> TerminalStyle {
|
pub fn fg_style_from_depth(depth: usize) -> TerminalStyle {
|
||||||
match depth % 6 {
|
if depth == 0 {
|
||||||
0 => TerminalStyle::fg_color((120, 120, 0)),
|
TerminalStyle::fg_color((200, 200, 200))
|
||||||
1 => TerminalStyle::fg_color((250, 165, 40)),
|
} else {
|
||||||
2 => TerminalStyle::fg_color((80, 180, 180)),
|
match depth % 5 {
|
||||||
3 => TerminalStyle::fg_color((180, 240, 85)),
|
0 => TerminalStyle::fg_color((128, 106, 97)),
|
||||||
4 => TerminalStyle::fg_color((200, 190, 70)),
|
1 => TerminalStyle::fg_color((100, 120, 232)),
|
||||||
_ => TerminalStyle::default()
|
2 => TerminalStyle::fg_color((180, 100, 96)),
|
||||||
}
|
3 => TerminalStyle::fg_color((188, 155, 18)),
|
||||||
|
4 => TerminalStyle::fg_color((135, 182, 134)),
|
||||||
|
_ => TerminalStyle::default()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue