wip
This commit is contained in:
parent
41c02465be
commit
32b2cb5d1f
16 changed files with 648 additions and 269 deletions
|
@ -48,6 +48,29 @@ async fn main() {
|
||||||
"hello world"
|
"hello world"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
let mut ldata = VecBuffer::new();
|
||||||
|
for c in "Hello World".chars() {
|
||||||
|
let rt = ReprTree::from_singleton_buffer(
|
||||||
|
Context::parse(&ctx, "Char"),
|
||||||
|
SingletonBuffer::new(c));
|
||||||
|
|
||||||
|
ldata.push(rt);
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut ledit = nested::editors::list::ListEditor::with_data(
|
||||||
|
ctx.clone(),
|
||||||
|
Context::parse(&ctx, "Char"),
|
||||||
|
ldata
|
||||||
|
).into_node(
|
||||||
|
SingletonBuffer::new(0).get_port()
|
||||||
|
);
|
||||||
|
|
||||||
|
nested_tty::editors::list::PTYListStyle::for_node(&mut ledit, ("<", "", ">"));
|
||||||
|
nested_tty::editors::list::PTYListController::for_node(&mut ledit, None, None);
|
||||||
|
let ledittree = SingletonBuffer::new(Arc::new(RwLock::new(ledit)));
|
||||||
|
|
||||||
|
/*
|
||||||
|
|
||||||
/* create EditTree
|
/* create EditTree
|
||||||
*/
|
*/
|
||||||
ctx.read().unwrap().apply_morphism(
|
ctx.read().unwrap().apply_morphism(
|
||||||
|
@ -105,11 +128,11 @@ async fn main() {
|
||||||
.to_sequence()
|
.to_sequence()
|
||||||
.to_grid_vertical()
|
.to_grid_vertical()
|
||||||
.map_item(|_pt,c| TerminalAtom::new(*c, TerminalStyle::fg_color((200,10,60))));
|
.map_item(|_pt,c| TerminalAtom::new(*c, TerminalStyle::fg_color((200,10,60))));
|
||||||
|
*/
|
||||||
/* setup terminal
|
/* setup terminal
|
||||||
*/
|
*/
|
||||||
let app = TTYApplication::new({
|
let app = TTYApplication::new({
|
||||||
let edittree_list = rt_string.edittree(&ctx).clone();
|
let edittree_list = ledittree.clone();//rt_string.edittree(&ctx).clone();
|
||||||
|
|
||||||
/* event handler
|
/* event handler
|
||||||
*/
|
*/
|
||||||
|
@ -135,22 +158,23 @@ async fn main() {
|
||||||
nested_tty::make_label(&label_str)
|
nested_tty::make_label(&label_str)
|
||||||
.map_item(|_pt, atom| atom.add_style_front(TerminalStyle::fg_color((90,90,90))))
|
.map_item(|_pt, atom| atom.add_style_front(TerminalStyle::fg_color((90,90,90))))
|
||||||
.offset(Vector2::new(1,1)));
|
.offset(Vector2::new(1,1)));
|
||||||
|
/*comp.push(
|
||||||
comp.push(
|
//rt_string.edittree(&ctx).get()
|
||||||
rt_string.edittree(&ctx).get()
|
ledittree.get()
|
||||||
.read().unwrap()
|
.read().unwrap()
|
||||||
.display_view()
|
.display_view()
|
||||||
.offset(Vector2::new(3,2)));
|
.offset(Vector2::new(3,2)));*/
|
||||||
|
/*
|
||||||
comp.push(
|
comp.push(
|
||||||
string_view_tty
|
string_view_tty
|
||||||
.offset(Vector2::new(5,3)));
|
.offset(Vector2::new(5,3)));
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
/* write the changes in the view of `term_port` to the terminal
|
/* write the changes in the view of `term_port` to the terminal
|
||||||
*/
|
*/
|
||||||
app.show().await.expect("output error!");
|
app.show().await.expect("output error!");
|
||||||
|
/*
|
||||||
/* need to call update because changes are applied lazily
|
/* need to call update because changes are applied lazily
|
||||||
*/
|
*/
|
||||||
chars_vec.get_port().0.update();
|
chars_vec.get_port().0.update();
|
||||||
|
@ -165,4 +189,5 @@ async fn main() {
|
||||||
.iter().collect::<String>();
|
.iter().collect::<String>();
|
||||||
|
|
||||||
eprintln!("value of the editor was: {}\n\n", string);
|
eprintln!("value of the editor was: {}\n\n", string);
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,16 +32,20 @@ struct LineDiagnostic {
|
||||||
msg: String
|
msg: String
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct LineEditor {
|
||||||
|
num_buf: SingletonBuffer< u64 >,
|
||||||
|
diag_buf: VecBuffer< LineDiagnostic >,
|
||||||
|
chars_edit: Arc<RwLock<ListEditor>>,
|
||||||
|
out_port: ViewPort< dyn TerminalView >,
|
||||||
|
view: Arc<RwLock< LineView >>,
|
||||||
|
cast: Arc<RwLock<ObserverBroadcast<dyn TerminalView>>>,
|
||||||
|
}
|
||||||
|
|
||||||
struct LineView {
|
struct LineView {
|
||||||
line_num: Arc< dyn SingletonView<Item = u64> >,
|
line_num: Arc< dyn SingletonView<Item = u64> >,
|
||||||
segments: Arc< dyn SequenceView<Item = ListSegment> >,
|
segments: Arc< dyn SequenceView<Item = ListSegment> >,
|
||||||
diagnostics: Arc< dyn SequenceView<Item = LineDiagnostic> >,
|
diagnostics: Arc< dyn SequenceView<Item = LineDiagnostic> >,
|
||||||
|
proj_helper: ProjectionHelper<usize, LineEditor>
|
||||||
diag_buf: VecBuffer< LineDiagnostic >,
|
|
||||||
|
|
||||||
cast: Arc<RwLock<ObserverBroadcast<dyn TerminalView>>>,
|
|
||||||
out_port: OuterViewPort<dyn TerminalView>,
|
|
||||||
proj_helper: ProjectionHelper<usize, Self>
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl View for LineView {
|
impl View for LineView {
|
||||||
|
@ -121,10 +125,9 @@ impl IndexView<Point2<i16>> for LineView {
|
||||||
while n > 0 { n_digits += 1; n /= 10; }
|
while n > 0 { n_digits += 1; n /= 10; }
|
||||||
let diag_len = self.diagnostics.iter().map(|d| d.msg.chars().count() as i16).max().unwrap_or(0);
|
let diag_len = self.diagnostics.iter().map(|d| d.msg.chars().count() as i16).max().unwrap_or(0);
|
||||||
IndexArea::Range(
|
IndexArea::Range(
|
||||||
Point2::new( xoff -1-n_digits , 0) ..=
|
Point2::new( xoff - n_digits - 1 , 0) ..=
|
||||||
Point2::new(
|
Point2::new(
|
||||||
xoff+
|
xoff + i16::max(
|
||||||
i16::max(
|
|
||||||
self.segments.len().unwrap_or(i16::MAX as usize) as i16,
|
self.segments.len().unwrap_or(i16::MAX as usize) as i16,
|
||||||
diag_len
|
diag_len
|
||||||
),
|
),
|
||||||
|
@ -134,57 +137,72 @@ impl IndexView<Point2<i16>> for LineView {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl LineView {
|
impl LineEditor {
|
||||||
pub fn new(
|
pub fn new(
|
||||||
|
ctx: &Arc<RwLock<Context>>,
|
||||||
n: u64,
|
n: u64,
|
||||||
le: &ListEditor,
|
|
||||||
) -> Arc<RwLock<Self>> {
|
) -> Arc<RwLock<Self>> {
|
||||||
let line_num_buf = SingletonBuffer::new(n);
|
let num_buf = SingletonBuffer::new(n);
|
||||||
let diag_buf = VecBuffer::new();
|
let diag_buf = VecBuffer::new();
|
||||||
let seg_seq = ListSegmentSequence::new(le.get_cursor_port(), le.get_data_port())
|
let chars_edit = ListEditor::new(
|
||||||
|
ctx.clone(),
|
||||||
|
Context::parse(&ctx, "<List Char>")
|
||||||
|
);
|
||||||
|
let chars_seg_seq = ListSegmentSequence::new(chars_edit.get_cursor_port(), chars_edit.get_data_port())
|
||||||
.read().unwrap().get_view();
|
.read().unwrap().get_view();
|
||||||
|
|
||||||
let out_port = ViewPort::new();
|
let out_port = ViewPort::new();
|
||||||
let mut proj_helper = ProjectionHelper::new(out_port.update_hooks.clone());
|
|
||||||
|
|
||||||
let lv = Arc::new(RwLock::new(LineView{
|
let mut proj_helper = ProjectionHelper::new(out_port.update_hooks.clone());
|
||||||
line_num: proj_helper.new_singleton_arg(0, line_num_buf.get_port(),
|
let line_view = Arc::new(RwLock::new(LineView {
|
||||||
|s: &mut LineView, _msg|{
|
line_num: proj_helper.new_singleton_arg(0, num_buf.get_port(),
|
||||||
s.cast.write().unwrap()
|
|e: &mut LineEditor, _msg|{
|
||||||
|
e.cast.write().unwrap()
|
||||||
.notify(&IndexArea::Range(
|
.notify(&IndexArea::Range(
|
||||||
(Point2::new(-100, 0) ..= Point2::new(0, 0))
|
(Point2::new(-100, 0) ..= Point2::new(0, 0))
|
||||||
));
|
));
|
||||||
}),
|
}),
|
||||||
segments: proj_helper.new_sequence_arg(1, seg_seq,
|
segments: proj_helper.new_sequence_arg(1, chars_seg_seq,
|
||||||
|s: &mut LineView, idx| {
|
|e: &mut LineEditor, idx| {
|
||||||
s.cast.write().unwrap()
|
e.cast.write().unwrap()
|
||||||
.notify(&IndexArea::Range(
|
.notify(&IndexArea::Range(
|
||||||
(Point2::new(0, *idx as i16 - 1) ..= Point2::new(100, *idx as i16))
|
(Point2::new(*idx as i16, 0) ..= Point2::new(*idx as i16, 0))
|
||||||
));
|
));
|
||||||
}),
|
}),
|
||||||
diagnostics: proj_helper.new_sequence_arg(2, diag_buf.get_port().to_sequence(),
|
diagnostics: proj_helper.new_sequence_arg(2, diag_buf.get_port().to_sequence(),
|
||||||
|s: &mut LineView, idx| {
|
|e: &mut LineEditor, idx| {
|
||||||
s.cast.write().unwrap()
|
e.cast.write().unwrap()
|
||||||
.notify(&IndexArea::Range(
|
.notify(&IndexArea::Range(
|
||||||
(Point2::new(-100, 1+*idx as i16) ..= Point2::new(100, 1+*idx as i16))
|
(Point2::new(-100, 1+*idx as i16) ..= Point2::new(100, 1+*idx as i16))
|
||||||
));
|
));
|
||||||
}),
|
}),
|
||||||
|
|
||||||
diag_buf,
|
|
||||||
|
|
||||||
cast: out_port.inner().get_broadcast(),
|
|
||||||
proj_helper,
|
proj_helper,
|
||||||
out_port: out_port.outer()
|
|
||||||
}));
|
}));
|
||||||
|
|
||||||
lv.write().unwrap().proj_helper.set_proj(&lv);
|
let line_edit = Arc::new(RwLock::new(LineEditor {
|
||||||
out_port.inner().set_view(Some(lv.clone()));
|
num_buf,
|
||||||
|
diag_buf,
|
||||||
|
chars_edit: Arc::new(RwLock::new(chars_edit)),
|
||||||
|
cast: out_port.inner().get_broadcast(),
|
||||||
|
view: line_view.clone(),
|
||||||
|
out_port,
|
||||||
|
}));
|
||||||
|
|
||||||
lv
|
line_view.write().unwrap().proj_helper.set_proj(&line_edit);
|
||||||
|
line_edit
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn set_linum(&mut self, n: u64) {
|
||||||
|
self.num_buf.set(n);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn add_diag(&mut self, diag: LineDiagnostic) {
|
||||||
|
self.diag_buf.push(diag);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_port(&self) -> OuterViewPort<dyn TerminalView> {
|
pub fn get_port(&self) -> OuterViewPort<dyn TerminalView> {
|
||||||
self.out_port.clone()
|
self.out_port.outer()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -205,6 +223,11 @@ impl LinesEditor {
|
||||||
Context::parse(&ctx, "Line ~ EditTree"),
|
Context::parse(&ctx, "Line ~ EditTree"),
|
||||||
|rt, σ| {
|
|rt, σ| {
|
||||||
eprintln!("LINE EDITOR CONSTRUCT");
|
eprintln!("LINE EDITOR CONSTRUCT");
|
||||||
|
/*
|
||||||
|
rt.insert_branch(
|
||||||
|
Context::parse(&ctx, "EditTree"),
|
||||||
|
|
||||||
|
)*/
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
ctx.write().unwrap().morphisms.add_morphism( line_to_edittree );
|
ctx.write().unwrap().morphisms.add_morphism( line_to_edittree );
|
||||||
|
@ -238,12 +261,11 @@ impl LinesEditor {
|
||||||
|
|
||||||
let mut list_edit = list_edit.into_node( depth_port );
|
let mut list_edit = list_edit.into_node( depth_port );
|
||||||
nested_tty::editors::list::PTYListController::for_node( &mut list_edit, Some('\n'), None );
|
nested_tty::editors::list::PTYListController::for_node( &mut list_edit, Some('\n'), None );
|
||||||
list_edit.disp.view
|
list_edit.disp.view.write().unwrap()
|
||||||
.write().unwrap()
|
.insert_branch(ReprTree::from_view(
|
||||||
.insert_branch(ReprTree::from_view(
|
Context::parse(&ctx, "TerminalView"),
|
||||||
Context::parse(&ctx, "TerminalView"),
|
lines_view
|
||||||
lines_view
|
));
|
||||||
));
|
|
||||||
|
|
||||||
LinesEditor {
|
LinesEditor {
|
||||||
// lines,
|
// lines,
|
||||||
|
@ -258,26 +280,34 @@ impl LinesEditor {
|
||||||
.read().unwrap()
|
.read().unwrap()
|
||||||
.data.len() as u64;
|
.data.len() as u64;
|
||||||
|
|
||||||
let line =
|
let depth = SingletonBuffer::new(0).get_port();
|
||||||
self.make_line(line_value)
|
|
||||||
.descend(Context::parse(&self.ctx, "EditTree")).unwrap()
|
|
||||||
.edittree(&self.ctx).get();
|
|
||||||
|
|
||||||
let le = line.read().unwrap().get_edit::<ListEditor>().unwrap();
|
let chars_rt = self.make_line(line_value);
|
||||||
le.write().unwrap().goto(TreeCursor::none());
|
let chars_edittree = chars_rt
|
||||||
|
.descend(Context::parse(&self.ctx, "EditTree")).unwrap()
|
||||||
|
.edittree(&self.ctx).get()
|
||||||
|
.read().unwrap().clone();
|
||||||
|
|
||||||
let lvport = LineView::new( n, &*le.read().unwrap() ).read().unwrap().get_port();
|
let line = LineEditor::new(&self.ctx, n);
|
||||||
line.write().unwrap().disp.view
|
line.write().unwrap().chars_edit = chars_edittree.get_edit::<ListEditor>().unwrap();
|
||||||
|
let line_port = line.read().unwrap().get_port();
|
||||||
|
|
||||||
|
let mut line_edittree = EditTree::new(self.ctx.clone(), depth)
|
||||||
|
.set_nav( line.read().unwrap().chars_edit.clone() )
|
||||||
|
.set_cmd( line.read().unwrap().chars_edit.clone() )
|
||||||
|
.set_editor( line.clone() );
|
||||||
|
|
||||||
|
line_edittree.disp.view
|
||||||
.insert_leaf(
|
.insert_leaf(
|
||||||
Context::parse(&self.ctx, "TerminalView"),
|
Context::parse(&self.ctx, "TerminalView"),
|
||||||
ReprLeaf::from_view( lvport )
|
ReprLeaf::from_view( line_port )
|
||||||
);
|
);
|
||||||
|
|
||||||
self.edit.write().unwrap()
|
self.edit.write().unwrap()
|
||||||
.get_edit::< ListEditor >().unwrap()
|
.get_edit::< ListEditor >().unwrap()
|
||||||
.write().unwrap()
|
.write().unwrap()
|
||||||
.data
|
.data
|
||||||
.push(line);
|
.push( Arc::new(RwLock::new(line_edittree)) );
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn make_line(&self, line_value: &str) -> Arc<RwLock<ReprTree>> {
|
pub fn make_line(&self, line_value: &str) -> Arc<RwLock<ReprTree>> {
|
||||||
|
@ -287,6 +317,7 @@ impl LinesEditor {
|
||||||
line_value
|
line_value
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// create Editor & transfer data to Editor
|
||||||
ctx.read().unwrap().apply_morphism(
|
ctx.read().unwrap().apply_morphism(
|
||||||
&rt_line,
|
&rt_line,
|
||||||
&laddertypes::MorphismType {
|
&laddertypes::MorphismType {
|
||||||
|
|
19
examples/tty-07-color/Cargo.toml
Normal file
19
examples/tty-07-color/Cargo.toml
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
[package]
|
||||||
|
name = "tty-06-color"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
laddertypes = { path = "../../../lib-laddertypes" }
|
||||||
|
r3vi = { path = "../../../lib-r3vi" }
|
||||||
|
nested = { path = "../../lib-nested-core" }
|
||||||
|
nested-tty = { path = "../../lib-nested-tty" }
|
||||||
|
termion = "*"
|
||||||
|
cgmath = "*"
|
||||||
|
|
||||||
|
[dependencies.async-std]
|
||||||
|
version = "1.9.0"
|
||||||
|
features = ["unstable", "attributes"]
|
||||||
|
|
232
examples/tty-07-color/src/main.rs
Normal file
232
examples/tty-07-color/src/main.rs
Normal file
|
@ -0,0 +1,232 @@
|
||||||
|
extern crate cgmath;
|
||||||
|
extern crate nested;
|
||||||
|
extern crate nested_tty;
|
||||||
|
extern crate r3vi;
|
||||||
|
extern crate termion;
|
||||||
|
|
||||||
|
use {
|
||||||
|
cgmath::Vector2,
|
||||||
|
nested::{
|
||||||
|
editors::{
|
||||||
|
ObjCommander
|
||||||
|
},
|
||||||
|
repr_tree::{Context, ReprTree, ReprTreeExt, ReprLeaf},
|
||||||
|
edit_tree::{EditTree, TreeNav, TreeCursor}
|
||||||
|
},
|
||||||
|
nested_tty::{
|
||||||
|
DisplaySegment, TTYApplication,
|
||||||
|
TerminalCompositor, TerminalStyle, TerminalView,
|
||||||
|
TerminalAtom, TerminalEvent
|
||||||
|
},
|
||||||
|
r3vi::{
|
||||||
|
buffer::{singleton::*, vec::*},
|
||||||
|
view::{port::UpdateTask, singleton::*, list::*, sequence::*},
|
||||||
|
projection::*
|
||||||
|
},
|
||||||
|
std::sync::{Arc, RwLock},
|
||||||
|
};
|
||||||
|
|
||||||
|
#[async_std::main]
|
||||||
|
async fn main() {
|
||||||
|
|
||||||
|
/* setup context
|
||||||
|
*/
|
||||||
|
let ctx = Arc::new(RwLock::new(Context::new()));
|
||||||
|
nested::editors::char::init_ctx( ctx.clone() );
|
||||||
|
nested::editors::digit::init_ctx( ctx.clone() );
|
||||||
|
nested::editors::integer::init_ctx( ctx.clone() );
|
||||||
|
nested::editors::list::init_ctx( ctx.clone() );
|
||||||
|
nested_tty::setup_edittree_hook(&ctx);
|
||||||
|
|
||||||
|
eprintln!(
|
||||||
|
"Char = {:?}\nu64 = {:?}\nEditTree = {:?}, <Vec EditTree> = {:?}",
|
||||||
|
Context::parse(&ctx, "Char"),
|
||||||
|
Context::parse(&ctx, "machine.UInt64"),
|
||||||
|
Context::parse(&ctx, "EditTree"),
|
||||||
|
Context::parse(&ctx, "<Vec EditTree>")
|
||||||
|
);
|
||||||
|
|
||||||
|
let mut red = nested::repr_tree::ReprTree::from_str(Context::parse(&ctx, "
|
||||||
|
ℕ ~ <PosInt 10 BigEndian> ~ <Seq <Digit 10>> ~ <List <Digit 10> ~ Char> ~ <Vec Char>
|
||||||
|
"),
|
||||||
|
"221"
|
||||||
|
);
|
||||||
|
ctx.read().unwrap().apply_morphism( &red,
|
||||||
|
&laddertypes::MorphismType {
|
||||||
|
src_type: Context::parse(&ctx, "ℕ ~ <PosInt 10 BigEndian> ~ <Seq~List <Digit 10> ~ Char > ~ <Vec Char>"),
|
||||||
|
dst_type: Context::parse(&ctx, "ℕ ~ <PosInt 16 BigEndian> ~ <Seq~List <Digit 16> ~ Char > ~ EditTree")
|
||||||
|
});
|
||||||
|
let red_edit = ctx.read().unwrap().setup_edittree(
|
||||||
|
red.descend(Context::parse(&ctx, "
|
||||||
|
ℕ ~ <PosInt 16 BigEndian> ~ <Seq~List <Digit 16>~Char>
|
||||||
|
")).unwrap(),
|
||||||
|
SingletonBuffer::new(0).get_port()
|
||||||
|
).unwrap();
|
||||||
|
|
||||||
|
let mut green = nested::repr_tree::ReprTree::from_str(Context::parse(&ctx, "
|
||||||
|
ℕ ~ <PosInt 10 BigEndian> ~ <Seq <Digit 10>> ~ <List <Digit 10> ~ Char> ~ <Vec Char>
|
||||||
|
"),
|
||||||
|
"220"
|
||||||
|
);
|
||||||
|
ctx.read().unwrap().apply_morphism( &green,
|
||||||
|
&laddertypes::MorphismType {
|
||||||
|
src_type: Context::parse(&ctx, "ℕ ~ <PosInt 10 BigEndian> ~ <Seq~List <Digit 10> ~ Char > ~ <Vec Char>"),
|
||||||
|
dst_type: Context::parse(&ctx, "ℕ ~ <PosInt 16 BigEndian> ~ <Seq~List <Digit 16> ~ Char > ~ EditTree")
|
||||||
|
});
|
||||||
|
let green_edit = ctx.read().unwrap().setup_edittree(green.descend(Context::parse(&ctx, "
|
||||||
|
ℕ ~ <PosInt 16 BigEndian> ~ <Seq~List <Digit 16>~Char>
|
||||||
|
")).unwrap(),
|
||||||
|
SingletonBuffer::new(0).get_port()
|
||||||
|
).unwrap();
|
||||||
|
|
||||||
|
|
||||||
|
let mut blue = nested::repr_tree::ReprTree::from_str(Context::parse(&ctx, "
|
||||||
|
ℕ ~ <PosInt 10 BigEndian> ~ <Seq <Digit 10>> ~ <List <Digit 10> ~ Char> ~ <Vec Char>
|
||||||
|
"),
|
||||||
|
"5"
|
||||||
|
);
|
||||||
|
ctx.read().unwrap().apply_morphism( &blue,
|
||||||
|
&laddertypes::MorphismType {
|
||||||
|
src_type: Context::parse(&ctx, "ℕ ~ <PosInt 10 BigEndian> ~ <Seq~List <Digit 10> ~ Char > ~ <Vec Char>"),
|
||||||
|
dst_type: Context::parse(&ctx, "ℕ ~ <PosInt 16 BigEndian> ~ <Seq~List <Digit 16> ~ Char > ~ EditTree")
|
||||||
|
});
|
||||||
|
let blue_edit = ctx.read().unwrap().setup_edittree(
|
||||||
|
blue.descend(Context::parse(&ctx, "
|
||||||
|
ℕ ~ <PosInt 16 BigEndian> ~ <Seq~List <Digit 16>~Char>
|
||||||
|
")).unwrap(),
|
||||||
|
SingletonBuffer::new(0).get_port()
|
||||||
|
).unwrap();
|
||||||
|
|
||||||
|
|
||||||
|
eprintln!("======\n M A K E L I S T E D I T O R\n======\n");
|
||||||
|
|
||||||
|
let mut color = nested::repr_tree::ReprTree::new_arc(
|
||||||
|
Context::parse(&ctx, "<List ℕ>")
|
||||||
|
);
|
||||||
|
|
||||||
|
color.insert_leaf(
|
||||||
|
Context::parse(&ctx, "
|
||||||
|
<List ℕ
|
||||||
|
~ <PosInt 16 BigEndian>
|
||||||
|
~ <Seq <Digit 16>>
|
||||||
|
~ <List <Digit 16>
|
||||||
|
~ Char >
|
||||||
|
>
|
||||||
|
~ <List EditTree>
|
||||||
|
~ <Vec EditTree>
|
||||||
|
"),
|
||||||
|
|
||||||
|
ReprLeaf::from_vec_buffer(VecBuffer::<
|
||||||
|
Arc<RwLock< EditTree >>
|
||||||
|
>::with_data(vec![
|
||||||
|
red_edit.get(),
|
||||||
|
green_edit.get(),
|
||||||
|
blue_edit.get()
|
||||||
|
]))
|
||||||
|
);
|
||||||
|
ctx.read().unwrap().apply_morphism(
|
||||||
|
&color,
|
||||||
|
&laddertypes::MorphismType {
|
||||||
|
src_type: Context::parse(&ctx, "<List ℕ ~ <PosInt 16 BigEndian> ~ <Seq~List <Digit 16> ~ Char > ~ EditTree > ~ <Vec EditTree>"),
|
||||||
|
dst_type: Context::parse(&ctx, "<List ℕ ~ <PosInt 16 BigEndian> ~ <Seq~List <Digit 16> ~ Char > > ~ EditTree")
|
||||||
|
});
|
||||||
|
let edit = ctx.read().unwrap().setup_edittree(
|
||||||
|
color.descend(Context::parse(&ctx, "
|
||||||
|
<List ℕ
|
||||||
|
~ < PosInt 16 BigEndian >
|
||||||
|
~ < Seq~List <Digit 16>
|
||||||
|
~ Char >
|
||||||
|
>
|
||||||
|
")).unwrap(),
|
||||||
|
SingletonBuffer::new(0).get_port()
|
||||||
|
).unwrap();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
eprintln!(" edittree => list list char ");
|
||||||
|
ctx.read().unwrap().apply_morphism(
|
||||||
|
&color,
|
||||||
|
&laddertypes::MorphismType {
|
||||||
|
src_type: Context::parse(&ctx, "<List ℕ ~ <PosInt 16 BigEndian> ~ <Seq~List <Digit 16> ~ Char > > ~ EditTree"),
|
||||||
|
dst_type: Context::parse(&ctx, "<List ℕ ~ <PosInt 16 BigEndian> ~ <Seq~List <Digit 16> ~ Char > >")
|
||||||
|
});
|
||||||
|
|
||||||
|
eprintln!("list char ==> list u64");
|
||||||
|
ctx.read().unwrap().apply_morphism(
|
||||||
|
&color,
|
||||||
|
&laddertypes::MorphismType {
|
||||||
|
src_type: Context::parse(&ctx, "<List ℕ ~ <PosInt 16 BigEndian> ~ <Seq~List <Digit 16> ~ Char>>"),
|
||||||
|
dst_type: Context::parse(&ctx, "<List ℕ ~ <PosInt 16 BigEndian> ~ <Seq~List <Digit 16> ~ ℤ_2^64 ~ machine.UInt64>>")
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
|
||||||
|
ctx.read().unwrap().apply_morphism(
|
||||||
|
&color,
|
||||||
|
&laddertypes::MorphismType {
|
||||||
|
src_type: Context::parse(&ctx, "<List ℕ ~ <PosInt 16 BigEndian> ~ <Seq~List <Digit 16> ~ ℤ_2^64 ~ machine.UInt64 > >"),
|
||||||
|
dst_type: Context::parse(&ctx, "<List ℕ ~ <PosInt 10 BigEndian> ~ <Seq~List <Digit 10> ~ Char > >")
|
||||||
|
});
|
||||||
|
/*
|
||||||
|
let edit2 = ctx.read().unwrap().setup_edittree(
|
||||||
|
color.descend(Context::parse(&ctx, "
|
||||||
|
<List ℕ
|
||||||
|
~ < PosInt 10 BigEndian >
|
||||||
|
~ < Seq~List <Digit 10>
|
||||||
|
~ Char >
|
||||||
|
>
|
||||||
|
")).unwrap(),
|
||||||
|
SingletonBuffer::new(0).get_port()
|
||||||
|
).unwrap();
|
||||||
|
*/
|
||||||
|
|
||||||
|
return;
|
||||||
|
|
||||||
|
/* setup terminal
|
||||||
|
*/
|
||||||
|
let app = TTYApplication::new({
|
||||||
|
/* event handler
|
||||||
|
*/
|
||||||
|
let ctx = ctx.clone();
|
||||||
|
let edit = edit.get().clone();
|
||||||
|
|
||||||
|
edit.write().unwrap().goto(TreeCursor::home());
|
||||||
|
|
||||||
|
move |ev| {
|
||||||
|
edit.write().unwrap().send_cmd_obj( ev.to_repr_tree(&ctx) );
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
/* Setup the compositor to serve as root-view
|
||||||
|
* by routing it to the `app.port` Viewport,
|
||||||
|
* so it will be displayed on TTY-output.
|
||||||
|
*/
|
||||||
|
let compositor = TerminalCompositor::new(app.port.inner());
|
||||||
|
|
||||||
|
/* Now add some views to our compositor
|
||||||
|
*/
|
||||||
|
{
|
||||||
|
let mut comp = compositor.write().unwrap();
|
||||||
|
|
||||||
|
fn show_edit_tree( ctx: &Arc<RwLock<Context>>, comp: &mut TerminalCompositor, rt: &Arc<RwLock<ReprTree>>, y: i16 )
|
||||||
|
{
|
||||||
|
let rt_edittree = rt.descend(Context::parse(&ctx, "EditTree")).expect("descend");
|
||||||
|
let halo_type = rt_edittree.read().unwrap().get_halo_type().clone();
|
||||||
|
let edittree = rt_edittree.read().unwrap().get_view::<dyn r3vi::view::singleton::SingletonView<Item = Arc<RwLock<EditTree>>>>().unwrap().get().read().unwrap().clone();
|
||||||
|
|
||||||
|
comp.push( nested_tty::make_label( &ctx.read().unwrap().type_term_to_str(&halo_type) )
|
||||||
|
.map_item(|_pt, atom| atom.add_style_front(TerminalStyle::fg_color((90,90,90))))
|
||||||
|
.offset(Vector2::new(1,y)));
|
||||||
|
|
||||||
|
comp.push( edittree.display_view()
|
||||||
|
.offset(Vector2::new(1,y+1)));
|
||||||
|
}
|
||||||
|
|
||||||
|
show_edit_tree( &ctx, &mut comp, &color.descend(Context::parse(&ctx, "<List ℕ ~ <PosInt 16 BigEndian> ~ <Seq~List <Digit 16>~Char>>")).unwrap(), 1 );
|
||||||
|
show_edit_tree( &ctx, &mut comp, &color.descend(Context::parse(&ctx, "<List ℕ ~ <PosInt 10 BigEndian> ~ <Seq~List <Digit 10>~Char>>")).unwrap(), 3 );
|
||||||
|
}
|
||||||
|
|
||||||
|
/* write the changes in the view of `term_port` to the terminal
|
||||||
|
*/
|
||||||
|
app.show().await.expect("output error!");
|
||||||
|
}
|
||||||
|
|
|
@ -7,7 +7,7 @@ use {
|
||||||
},
|
},
|
||||||
laddertypes::{TypeTerm},
|
laddertypes::{TypeTerm},
|
||||||
crate::{
|
crate::{
|
||||||
repr_tree::{ReprTree, Context},
|
repr_tree::{ReprTree, ReprTreeArc, Context},
|
||||||
edit_tree::{TreeNav, TreeCursor, TreeNavResult, TreeHeightOp, diagnostics::{Diagnostics, Message}},
|
edit_tree::{TreeNav, TreeCursor, TreeNavResult, TreeHeightOp, diagnostics::{Diagnostics, Message}},
|
||||||
editors::{list::{ListCursorMode}, ObjCommander}
|
editors::{list::{ListCursorMode}, ObjCommander}
|
||||||
}
|
}
|
||||||
|
@ -32,9 +32,7 @@ pub struct EdittreeControl {
|
||||||
Option< Arc<dyn Any + Send + Sync> >
|
Option< Arc<dyn Any + Send + Sync> >
|
||||||
>,
|
>,
|
||||||
|
|
||||||
pub spillbuf: Arc<RwLock<
|
pub spillbuf: Arc<RwLock< Vec< ReprTreeArc > >>,
|
||||||
Vec< Arc<RwLock< EditTree >> >
|
|
||||||
>>,
|
|
||||||
|
|
||||||
/// commander & navigation
|
/// commander & navigation
|
||||||
pub cmd: SingletonBuffer<
|
pub cmd: SingletonBuffer<
|
||||||
|
@ -225,4 +223,3 @@ impl Diagnostics for EditTree {
|
||||||
self.get_diag()
|
self.get_diag()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -35,28 +35,7 @@ impl ObjCommander for ListEditor {
|
||||||
fn send_cmd_obj(&mut self, cmd_obj: Arc<RwLock<ReprTree>>) -> TreeNavResult {
|
fn send_cmd_obj(&mut self, cmd_obj: Arc<RwLock<ReprTree>>) -> TreeNavResult {
|
||||||
let cmd_repr = cmd_obj.read().unwrap();
|
let cmd_repr = cmd_obj.read().unwrap();
|
||||||
|
|
||||||
if let Some(view) = cmd_repr.get_view::<dyn SingletonView<Item = EditTree>>() {
|
if let Some(cmd) = cmd_repr.get_view::<dyn SingletonView<Item = ListCmd>>() {
|
||||||
let node = view.get();
|
|
||||||
let cur = self.cursor.get();
|
|
||||||
|
|
||||||
if let Some(idx) = cur.idx {
|
|
||||||
match cur.mode {
|
|
||||||
ListCursorMode::Select => {
|
|
||||||
*self.data.get_mut(idx as usize) = Arc::new(RwLock::new(node));
|
|
||||||
TreeNavResult::Exit
|
|
||||||
}
|
|
||||||
ListCursorMode::Insert => {
|
|
||||||
self.insert(Arc::new(RwLock::new(node)));
|
|
||||||
self.cursor.set(ListCursor{ idx: Some(idx+1), mode: ListCursorMode::Insert });
|
|
||||||
TreeNavResult::Continue
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
TreeNavResult::Exit
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
else if let Some(cmd) = cmd_repr.get_view::<dyn SingletonView<Item = ListCmd>>() {
|
|
||||||
|
|
||||||
let cur = self.cursor.get();
|
let cur = self.cursor.get();
|
||||||
drop(cmd_repr);
|
drop(cmd_repr);
|
||||||
|
@ -70,7 +49,8 @@ impl ObjCommander for ListEditor {
|
||||||
if let Some(idx) = cur.idx {
|
if let Some(idx) = cur.idx {
|
||||||
match cur.mode {
|
match cur.mode {
|
||||||
ListCursorMode::Select => {
|
ListCursorMode::Select => {
|
||||||
if let Some(mut item) = self.get_item().clone() {
|
if let Some(mut item) = self.get_cur_edittree() {
|
||||||
|
let mut item = item.write().unwrap();
|
||||||
let item_cur = item.get_cursor();
|
let item_cur = item.get_cursor();
|
||||||
|
|
||||||
match cmd.get() {
|
match cmd.get() {
|
||||||
|
@ -151,14 +131,30 @@ impl ObjCommander for ListEditor {
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
if let Some(cur_item) = self.get_item_mut() {
|
let cur = self.cursor.get();
|
||||||
drop(cmd_repr);
|
|
||||||
cur_item.write().unwrap().send_cmd_obj(cmd_obj);
|
if let Some(idx) = cur.idx {
|
||||||
TreeNavResult::Continue
|
match cur.mode {
|
||||||
|
ListCursorMode::Select => {
|
||||||
|
// what ??
|
||||||
|
//*self.data.get_mut(idx as usize) = Arc::new(RwLock::new(node));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
TreeNavResult::Exit
|
||||||
|
}
|
||||||
|
ListCursorMode::Insert => {
|
||||||
|
self.insert( cmd_obj.clone() );
|
||||||
|
|
||||||
|
// todo: setup edittree
|
||||||
|
|
||||||
|
self.cursor.set(ListCursor{ idx: Some(idx+1), mode: ListCursorMode::Insert });
|
||||||
|
TreeNavResult::Continue
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
TreeNavResult::Exit
|
TreeNavResult::Exit
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,7 @@ use {
|
||||||
},
|
},
|
||||||
laddertypes::{TypeTerm},
|
laddertypes::{TypeTerm},
|
||||||
crate::{
|
crate::{
|
||||||
repr_tree::{Context, ReprTree, ReprLeaf, ReprTreeExt, GenericReprTreeMorphism},
|
repr_tree::{Context, ReprTree, ReprTreeArc, ReprLeaf, ReprTreeExt, GenericReprTreeMorphism},
|
||||||
edit_tree::{EditTree},
|
edit_tree::{EditTree},
|
||||||
editors::{
|
editors::{
|
||||||
char::{CharEditor},
|
char::{CharEditor},
|
||||||
|
@ -35,12 +35,12 @@ pub fn init_ctx(ctx: Arc<RwLock<Context>>) {
|
||||||
if let Some( item_type ) = σ.get( &item_id ) {
|
if let Some( item_type ) = σ.get( &item_id ) {
|
||||||
let mut item_vec_rt = src_rt
|
let mut item_vec_rt = src_rt
|
||||||
.descend(
|
.descend(
|
||||||
Context::parse(&ctx, "<List Item~EditTree>~<Vec EditTree>")
|
Context::parse(&ctx, "<List Item>~<Vec EditTree>")
|
||||||
.apply_substitution(&|id| σ.get(id).cloned()).clone()
|
.apply_substitution(&|id| σ.get(id).cloned()).clone()
|
||||||
)
|
)
|
||||||
.expect("cant descend src repr");
|
.expect("cant descend src repr");
|
||||||
|
|
||||||
let item_vec_buffer = item_vec_rt.vec_buffer::< Arc<RwLock<EditTree>> >();
|
let item_vec_buffer = item_vec_rt.vec_buffer::< ReprTreeArc >();
|
||||||
|
|
||||||
let mut list_editor = ListEditor::with_data(ctx.clone(), item_type.clone(), item_vec_buffer);
|
let mut list_editor = ListEditor::with_data(ctx.clone(), item_type.clone(), item_vec_buffer);
|
||||||
let edittree_list = list_editor.into_node(
|
let edittree_list = list_editor.into_node(
|
||||||
|
@ -177,4 +177,3 @@ pub fn init_ctx(ctx: Arc<RwLock<Context>>) {
|
||||||
ctx.write().unwrap().morphisms.add_morphism( list_morph_to_vec_u64 );
|
ctx.write().unwrap().morphisms.add_morphism( list_morph_to_vec_u64 );
|
||||||
ctx.write().unwrap().morphisms.add_morphism( list_morph_to_vec_edittree );
|
ctx.write().unwrap().morphisms.add_morphism( list_morph_to_vec_edittree );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
use {
|
use {
|
||||||
r3vi::{
|
r3vi::{
|
||||||
view::{OuterViewPort, singleton::*, sequence::*},
|
view::{OuterViewPort, singleton::*, sequence::*, list::*},
|
||||||
buffer::{singleton::*, vec::*},
|
buffer::{singleton::*, vec::*},
|
||||||
projection::*
|
projection::*
|
||||||
},
|
},
|
||||||
laddertypes::{TypeTerm},
|
laddertypes::{TypeTerm},
|
||||||
crate::{
|
crate::{
|
||||||
repr_tree::{Context, ReprTree},
|
repr_tree::{Context, ReprTree, ReprTreeExt, node::ReprTreeArc},
|
||||||
edit_tree::{EditTree, TreeNav, TreeCursor, diagnostics::Diagnostics},
|
edit_tree::{EditTree, TreeNav, TreeCursor, diagnostics::Diagnostics},
|
||||||
editors::{list::{ListCursor, ListCursorMode, ListCmd}, ObjCommander},
|
editors::{list::{ListCursor, ListCursorMode, ListCmd}, ObjCommander},
|
||||||
},
|
},
|
||||||
|
@ -17,11 +17,8 @@ use {
|
||||||
|
|
||||||
pub struct ListEditor {
|
pub struct ListEditor {
|
||||||
pub cursor: SingletonBuffer<ListCursor>,
|
pub cursor: SingletonBuffer<ListCursor>,
|
||||||
|
pub data: VecBuffer< ReprTreeArc >,
|
||||||
// todo: (?) remove RwLock<..> around NestedNode ??
|
pub spillbuf: Arc<RwLock< Vec< ReprTreeArc > >>,
|
||||||
pub data: VecBuffer< Arc<RwLock<EditTree>> >,
|
|
||||||
|
|
||||||
pub spillbuf: Arc<RwLock<Vec<Arc<RwLock<EditTree>>>>>,
|
|
||||||
|
|
||||||
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>>,
|
||||||
|
@ -49,7 +46,7 @@ impl ListEditor {
|
||||||
pub fn with_data(
|
pub fn with_data(
|
||||||
ctx: Arc<RwLock<Context>>,
|
ctx: Arc<RwLock<Context>>,
|
||||||
typ: TypeTerm,
|
typ: TypeTerm,
|
||||||
data: VecBuffer<Arc<RwLock<EditTree>>>
|
data: VecBuffer< ReprTreeArc >
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let cursor = SingletonBuffer::new(ListCursor::default());
|
let cursor = SingletonBuffer::new(ListCursor::default());
|
||||||
|
|
||||||
|
@ -58,6 +55,7 @@ impl ListEditor {
|
||||||
.get_port()
|
.get_port()
|
||||||
.map({
|
.map({
|
||||||
let data = data.clone();
|
let data = data.clone();
|
||||||
|
let ctx = ctx.clone();
|
||||||
move |c| {
|
move |c| {
|
||||||
let ip = SingletonBuffer::new(c.mode).get_port();
|
let ip = SingletonBuffer::new(c.mode).get_port();
|
||||||
match c.mode {
|
match c.mode {
|
||||||
|
@ -65,7 +63,10 @@ impl ListEditor {
|
||||||
ListCursorMode::Select => {
|
ListCursorMode::Select => {
|
||||||
if let Some(idx) = c.idx {
|
if let Some(idx) = c.idx {
|
||||||
if idx >= 0 && idx < data.len() as isize {
|
if idx >= 0 && idx < data.len() as isize {
|
||||||
data.get(idx as usize).read().unwrap().get_mode_view()
|
data.get(idx as usize)
|
||||||
|
.edittree(&ctx).get()
|
||||||
|
.read().unwrap()
|
||||||
|
.get_mode_view()
|
||||||
} else {
|
} else {
|
||||||
ip
|
ip
|
||||||
}
|
}
|
||||||
|
@ -86,11 +87,15 @@ impl ListEditor {
|
||||||
cursor.get_port()
|
cursor.get_port()
|
||||||
.map({
|
.map({
|
||||||
let data = data.clone();
|
let data = data.clone();
|
||||||
|
let ctx = ctx.clone();
|
||||||
move |cur| {
|
move |cur| {
|
||||||
if cur.mode == ListCursorMode::Select {
|
if cur.mode == ListCursorMode::Select {
|
||||||
if let Some(idx) = cur.idx {
|
if let Some(idx) = cur.idx {
|
||||||
if idx >= 0 && idx < data.len() as isize {
|
if idx >= 0 && idx < data.len() as isize {
|
||||||
return data.get(idx as usize).read().unwrap().get_addr_view();
|
return data.get(idx as usize)
|
||||||
|
.edittree(&ctx).get()
|
||||||
|
.read().unwrap()
|
||||||
|
.get_addr_view();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -124,7 +129,7 @@ impl ListEditor {
|
||||||
.set_editor(editor.clone())
|
.set_editor(editor.clone())
|
||||||
.set_nav(editor.clone())
|
.set_nav(editor.clone())
|
||||||
.set_cmd(editor.clone())
|
.set_cmd(editor.clone())
|
||||||
.set_diag(e.get_data_port()
|
.set_diag(e.get_edittree_seq()
|
||||||
.enumerate()
|
.enumerate()
|
||||||
.map(|(idx, item_editor)| {
|
.map(|(idx, item_editor)| {
|
||||||
let idx = *idx;
|
let idx = *idx;
|
||||||
|
@ -156,10 +161,21 @@ impl ListEditor {
|
||||||
self.cursor.get_port()
|
self.cursor.get_port()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_data_port(&self) -> OuterViewPort<dyn SequenceView<Item = EditTree>> {
|
pub fn get_reprtree_list(&self) -> OuterViewPort<dyn ListView<ReprTreeArc>> {
|
||||||
self.data.get_port().to_list().map(
|
self.data.get_port().to_list()
|
||||||
|x| x.read().unwrap().clone()
|
}
|
||||||
).to_sequence()
|
|
||||||
|
pub fn get_edittree_list(&self) -> OuterViewPort<dyn ListView<EditTree>> {
|
||||||
|
self.get_reprtree_list().map({
|
||||||
|
let ctx = self.ctx.clone();
|
||||||
|
move|rt| {
|
||||||
|
rt.edittree(&ctx).get().read().unwrap().clone()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_edittree_seq(&self) -> OuterViewPort<dyn SequenceView<Item = EditTree>> {
|
||||||
|
self.get_edittree_list().to_sequence()
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
pub fn get_data(&self) -> Arc<RwLock<ReprTree>> {
|
pub fn get_data(&self) -> Arc<RwLock<ReprTree>> {
|
||||||
|
@ -170,11 +186,11 @@ impl ListEditor {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
pub fn get_item(&self) -> Option<EditTree> {
|
pub fn get_item(&self) -> Option< ReprTreeArc > {
|
||||||
if let Some(idx) = self.cursor.get().idx {
|
if let Some(idx) = self.cursor.get().idx {
|
||||||
let idx = crate::utils::modulo(idx as isize, self.data.len() as isize) as usize;
|
let idx = crate::utils::modulo(idx as isize, self.data.len() as isize) as usize;
|
||||||
if idx < self.data.len() {
|
if idx < self.data.len() {
|
||||||
Some(self.data.get(idx).read().unwrap().clone())
|
Some( self.data.get(idx).clone() )
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
@ -183,7 +199,7 @@ impl ListEditor {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_item_mut(&mut self) -> Option<MutableVecAccess<Arc<RwLock<EditTree>>>> {
|
pub fn get_item_mut(&mut self) -> Option<MutableVecAccess< ReprTreeArc >> {
|
||||||
if let Some(idx) = self.cursor.get().idx {
|
if let Some(idx) = self.cursor.get().idx {
|
||||||
let idx = crate::utils::modulo(idx as isize, self.data.len() as isize) as usize;
|
let idx = crate::utils::modulo(idx as isize, self.data.len() as isize) as usize;
|
||||||
if idx < self.data.len() {
|
if idx < self.data.len() {
|
||||||
|
@ -196,6 +212,23 @@ impl ListEditor {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn get_edittree(&self, idx: usize) -> Arc<RwLock<EditTree>> {
|
||||||
|
self.data.get(idx).edittree(&self.ctx).get()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_cur_edittree(&self) -> Option< Arc<RwLock<EditTree>> > {
|
||||||
|
if let Some(idx) = self.cursor.get().idx {
|
||||||
|
let idx = crate::utils::modulo(idx as isize, self.data.len() as isize) as usize;
|
||||||
|
if idx < self.data.len() {
|
||||||
|
Some(self.get_edittree(idx))
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// is the element-type also a list-like editor (i.e. impls TreeNav)
|
/// is the element-type also a list-like editor (i.e. impls TreeNav)
|
||||||
pub fn is_listlist(&self) -> bool {
|
pub fn is_listlist(&self) -> bool {
|
||||||
self.ctx.read().unwrap().is_list_type(&self.typ)
|
self.ctx.read().unwrap().is_list_type(&self.typ)
|
||||||
|
@ -234,8 +267,9 @@ impl ListEditor {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// insert a new element
|
/// insert a new element
|
||||||
pub fn insert(&mut self, item: Arc<RwLock<EditTree>>) {
|
pub fn insert(&mut self, item: ReprTreeArc) {
|
||||||
item.read().unwrap().disp.depth.0.set_view(
|
let item_edit = item.edittree(&self.ctx).get();
|
||||||
|
item_edit.read().unwrap().disp.depth.0.set_view(
|
||||||
self.depth.map(|d| d+1).get_view()
|
self.depth.map(|d| d+1).get_view()
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -247,7 +281,7 @@ impl ListEditor {
|
||||||
if self.is_listlist() {
|
if self.is_listlist() {
|
||||||
cur.mode = ListCursorMode::Select;
|
cur.mode = ListCursorMode::Select;
|
||||||
} else {
|
} else {
|
||||||
item.write().unwrap().goto(TreeCursor::none());
|
item_edit.write().unwrap().goto(TreeCursor::none());
|
||||||
cur.idx = Some(idx + 1);
|
cur.idx = Some(idx + 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -304,51 +338,41 @@ impl ListEditor {
|
||||||
let cur = self.get_cursor();
|
let cur = self.get_cursor();
|
||||||
|
|
||||||
if let Some(mut item) = self.get_item().clone() {
|
if let Some(mut item) = self.get_item().clone() {
|
||||||
item.send_cmd_obj(ListCmd::Split.into_repr_tree(&self.ctx));
|
let item_edit = item.edittree(&self.ctx).get();
|
||||||
|
let mut ie = item_edit.write().unwrap();
|
||||||
|
ie.send_cmd_obj(ListCmd::Split.into_repr_tree(&self.ctx));
|
||||||
|
|
||||||
if cur.tree_addr.len() < 3 {
|
if cur.tree_addr.len() < 3 {
|
||||||
item.goto(TreeCursor::none());
|
ie.goto(TreeCursor::none());
|
||||||
|
|
||||||
self.set_leaf_mode(ListCursorMode::Insert);
|
self.set_leaf_mode(ListCursorMode::Insert);
|
||||||
self.nexd();
|
self.nexd();
|
||||||
|
|
||||||
let mut b = item.ctrl.spillbuf.write().unwrap();
|
let mut b = ie.ctrl.spillbuf.write().unwrap();
|
||||||
|
|
||||||
let rt = ReprTree::new_arc(self.typ.clone());
|
let rt = ReprTree::new_arc(self.typ.clone());
|
||||||
let mut et = self.ctx.read().unwrap().setup_edittree(&rt);
|
let mut et = self.ctx.read().unwrap().setup_edittree(&rt);
|
||||||
|
|
||||||
if let Some(edittree) = et.as_mut(){
|
if let Some(edittree) = et.as_mut(){
|
||||||
|
let mut tail_node = edittree.get();
|
||||||
|
let mut tail_node = tail_node.write().unwrap();
|
||||||
|
tail_node.goto(TreeCursor::home());
|
||||||
|
|
||||||
let mut tail_node = edittree.get();
|
for n in b.iter() {
|
||||||
let mut tail_node = tail_node.write().unwrap();
|
tail_node.send_cmd_obj(n.clone());
|
||||||
tail_node.goto(TreeCursor::home());
|
}
|
||||||
|
|
||||||
for node in b.iter() {
|
b.clear();
|
||||||
tail_node
|
drop(b);
|
||||||
.send_cmd_obj(
|
drop(item);
|
||||||
ReprTree::from_singleton_buffer(
|
|
||||||
Context::parse(&self.ctx, "EditTree"),
|
|
||||||
SingletonBuffer::<EditTree>::new(
|
|
||||||
node.read().unwrap().clone()
|
|
||||||
)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
b.clear();
|
tail_node.goto(TreeCursor::home());
|
||||||
drop(b);
|
if cur.tree_addr.len() > 1 {
|
||||||
drop(item);
|
tail_node.dn();
|
||||||
|
}
|
||||||
tail_node.goto(TreeCursor::home());
|
drop(tail_node);
|
||||||
if cur.tree_addr.len() > 1 {
|
|
||||||
tail_node.dn();
|
|
||||||
}
|
|
||||||
drop(tail_node);
|
|
||||||
|
|
||||||
self.insert(
|
|
||||||
edittree.value.read().unwrap().clone()
|
|
||||||
);
|
|
||||||
|
|
||||||
|
self.insert(rt);
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
@ -361,8 +385,8 @@ impl ListEditor {
|
||||||
|
|
||||||
pub fn listlist_join_pxev(&mut self, idx: isize) {
|
pub fn listlist_join_pxev(&mut self, idx: isize) {
|
||||||
{
|
{
|
||||||
let cur_editor = self.data.get(idx as usize);
|
let cur_editor = self.data.get(idx as usize).edittree(&self.ctx).get();
|
||||||
let pxv_editor = self.data.get(idx as usize-1);
|
let pxv_editor = self.data.get(idx as usize-1).edittree(&self.ctx).get();
|
||||||
let mut cur_editor = cur_editor.write().unwrap();
|
let mut cur_editor = cur_editor.write().unwrap();
|
||||||
let mut pxv_editor = pxv_editor.write().unwrap();
|
let mut pxv_editor = pxv_editor.write().unwrap();
|
||||||
|
|
||||||
|
@ -383,14 +407,7 @@ impl ListEditor {
|
||||||
|
|
||||||
let data = cur_editor.ctrl.spillbuf.read().unwrap();
|
let data = cur_editor.ctrl.spillbuf.read().unwrap();
|
||||||
for x in data.iter() {
|
for x in data.iter() {
|
||||||
pxv_editor.send_cmd_obj(
|
pxv_editor.send_cmd_obj(x.clone());
|
||||||
ReprTree::from_singleton_buffer(
|
|
||||||
Context::parse(&self.ctx, "EditTree"),
|
|
||||||
SingletonBuffer::<EditTree>::new(
|
|
||||||
x.read().unwrap().clone()
|
|
||||||
)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -420,8 +437,8 @@ impl ListEditor {
|
||||||
|
|
||||||
pub fn listlist_join_nexd(&mut self, idx: usize) {
|
pub fn listlist_join_nexd(&mut self, idx: usize) {
|
||||||
{
|
{
|
||||||
let cur_editor = self.data.get(idx);
|
let cur_editor = self.data.get(idx).edittree(&self.ctx).get();
|
||||||
let nxd_editor = self.data.get(idx + 1);
|
let nxd_editor = self.data.get(idx + 1).edittree(&self.ctx).get();
|
||||||
let mut cur_editor = cur_editor.write().unwrap();
|
let mut cur_editor = cur_editor.write().unwrap();
|
||||||
let mut nxd_editor = nxd_editor.write().unwrap();
|
let mut nxd_editor = nxd_editor.write().unwrap();
|
||||||
|
|
||||||
|
@ -442,14 +459,7 @@ impl ListEditor {
|
||||||
let data = nxd_editor.ctrl.spillbuf.read().unwrap();
|
let data = nxd_editor.ctrl.spillbuf.read().unwrap();
|
||||||
|
|
||||||
for x in data.iter() {
|
for x in data.iter() {
|
||||||
cur_editor.send_cmd_obj(
|
cur_editor.send_cmd_obj(x.clone());
|
||||||
ReprTree::from_singleton_buffer(
|
|
||||||
Context::parse(&self.ctx, "EditTree"),
|
|
||||||
SingletonBuffer::<EditTree>::new(
|
|
||||||
x.read().unwrap().clone()
|
|
||||||
)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// fixme: is it oc0 or old_cur ??
|
// fixme: is it oc0 or old_cur ??
|
||||||
|
@ -495,5 +505,3 @@ impl TreeType for ListEditor {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,7 @@ use {
|
||||||
ListCursor, ListCursorMode,
|
ListCursor, ListCursorMode,
|
||||||
editor::ListEditor
|
editor::ListEditor
|
||||||
},
|
},
|
||||||
|
repr_tree::{ReprTreeExt},
|
||||||
edit_tree::{TreeCursor, TreeNav, TreeNavResult, TreeHeightOp}
|
edit_tree::{TreeCursor, TreeNav, TreeNavResult, TreeHeightOp}
|
||||||
},
|
},
|
||||||
cgmath::Vector2
|
cgmath::Vector2
|
||||||
|
@ -35,7 +36,10 @@ impl TreeNav for ListEditor {
|
||||||
TreeHeightOp::P => 0,
|
TreeHeightOp::P => 0,
|
||||||
TreeHeightOp::Q => self.data.len() - 1,
|
TreeHeightOp::Q => self.data.len() - 1,
|
||||||
_ => 0
|
_ => 0
|
||||||
}).read().unwrap().get_height(op)
|
})
|
||||||
|
.edittree(&self.ctx).get()
|
||||||
|
.read().unwrap()
|
||||||
|
.get_height(op)
|
||||||
} else {
|
} else {
|
||||||
1
|
1
|
||||||
}
|
}
|
||||||
|
@ -43,7 +47,9 @@ impl TreeNav for ListEditor {
|
||||||
TreeHeightOp::Max => {
|
TreeHeightOp::Max => {
|
||||||
1 + (0..self.data.len() as usize)
|
1 + (0..self.data.len() as usize)
|
||||||
.map(|i| self.data
|
.map(|i| self.data
|
||||||
.get(i).read().unwrap()
|
.get(i)
|
||||||
|
.edittree(&self.ctx).get()
|
||||||
|
.read().unwrap()
|
||||||
.get_height(&TreeHeightOp::Max)
|
.get_height(&TreeHeightOp::Max)
|
||||||
)
|
)
|
||||||
.max()
|
.max()
|
||||||
|
@ -68,7 +74,9 @@ impl TreeNav for ListEditor {
|
||||||
ListCursorMode::Select => {
|
ListCursorMode::Select => {
|
||||||
if let Some(i) = cur.idx {
|
if let Some(i) = cur.idx {
|
||||||
if i < self.data.len() as isize {
|
if i < self.data.len() as isize {
|
||||||
let mut sub_cur = self.data.get(i as usize).read().unwrap().get_cursor_warp();
|
let mut sub_cur = self.get_edittree(i as usize)
|
||||||
|
.read().unwrap()
|
||||||
|
.get_cursor_warp();
|
||||||
sub_cur.tree_addr.insert(0, i as isize - self.data.len() as isize);
|
sub_cur.tree_addr.insert(0, i as isize - self.data.len() as isize);
|
||||||
return sub_cur;
|
return sub_cur;
|
||||||
} else {
|
} else {
|
||||||
|
@ -100,7 +108,7 @@ impl TreeNav for ListEditor {
|
||||||
ListCursorMode::Select => {
|
ListCursorMode::Select => {
|
||||||
if let Some(i) = cur.idx {
|
if let Some(i) = cur.idx {
|
||||||
if i < self.data.len() as isize {
|
if i < self.data.len() as isize {
|
||||||
let mut sub_cur = self.data.get(i as usize).read().unwrap().get_cursor();
|
let mut sub_cur = self.get_edittree(i as usize).read().unwrap().get_cursor();
|
||||||
if sub_cur.tree_addr.len() > 0 {
|
if sub_cur.tree_addr.len() > 0 {
|
||||||
sub_cur.tree_addr.insert(0, i as isize);
|
sub_cur.tree_addr.insert(0, i as isize);
|
||||||
return sub_cur;
|
return sub_cur;
|
||||||
|
@ -124,7 +132,7 @@ impl TreeNav for ListEditor {
|
||||||
let old_cur = self.cursor.get();
|
let old_cur = self.cursor.get();
|
||||||
if let Some(i) = old_cur.idx {
|
if let Some(i) = old_cur.idx {
|
||||||
if i < self.data.len() as isize {
|
if i < self.data.len() as isize {
|
||||||
self.data.get_mut(i as usize).write().unwrap().goto(TreeCursor::none());
|
self.get_edittree(i as usize).write().unwrap().goto(TreeCursor::none());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -145,8 +153,7 @@ impl TreeNav for ListEditor {
|
||||||
});
|
});
|
||||||
|
|
||||||
if new_cur.leaf_mode == ListCursorMode::Select && self.data.len() > 0 {
|
if new_cur.leaf_mode == ListCursorMode::Select && self.data.len() > 0 {
|
||||||
self.data
|
self.get_edittree(idx as usize)
|
||||||
.get_mut(idx as usize)
|
|
||||||
.write().unwrap()
|
.write().unwrap()
|
||||||
.goto(TreeCursor {
|
.goto(TreeCursor {
|
||||||
leaf_mode: ListCursorMode::Select,
|
leaf_mode: ListCursorMode::Select,
|
||||||
|
@ -165,8 +172,7 @@ impl TreeNav for ListEditor {
|
||||||
idx: Some(idx),
|
idx: Some(idx),
|
||||||
});
|
});
|
||||||
|
|
||||||
self.data
|
self.get_edittree(idx as usize)
|
||||||
.get_mut(idx as usize)
|
|
||||||
.write().unwrap()
|
.write().unwrap()
|
||||||
.goto(TreeCursor {
|
.goto(TreeCursor {
|
||||||
leaf_mode: new_cur.leaf_mode,
|
leaf_mode: new_cur.leaf_mode,
|
||||||
|
@ -212,8 +218,7 @@ impl TreeNav for ListEditor {
|
||||||
// dn
|
// dn
|
||||||
|
|
||||||
if cur.tree_addr[0] < self.data.len() as isize {
|
if cur.tree_addr[0] < self.data.len() as isize {
|
||||||
if self.data
|
if self.get_edittree(cur.tree_addr[0] as usize)
|
||||||
.get_mut(cur.tree_addr[0] as usize)
|
|
||||||
.write().unwrap()
|
.write().unwrap()
|
||||||
.goby(Vector2::new(direction.x, direction.y))
|
.goby(Vector2::new(direction.x, direction.y))
|
||||||
== TreeNavResult::Continue {
|
== TreeNavResult::Continue {
|
||||||
|
@ -247,11 +252,10 @@ impl TreeNav for ListEditor {
|
||||||
|
|
||||||
match cur.leaf_mode {
|
match cur.leaf_mode {
|
||||||
ListCursorMode::Select => {
|
ListCursorMode::Select => {
|
||||||
let cur_item = self.data.get(cur.tree_addr[0] as usize);
|
let cur_item = self.get_edittree(cur.tree_addr[0] as usize);
|
||||||
let cur_height = cur_item.read().unwrap().get_height(&TreeHeightOp::Max);
|
let cur_height = cur_item.read().unwrap().get_height(&TreeHeightOp::Max);
|
||||||
|
|
||||||
let new_item = self.data
|
let new_item = self.get_edittree(idx as usize);
|
||||||
.get_mut(idx as usize);
|
|
||||||
|
|
||||||
let height = new_item.read().unwrap().get_height(
|
let height = new_item.read().unwrap().get_height(
|
||||||
if direction.x < 0 {
|
if direction.x < 0 {
|
||||||
|
@ -277,7 +281,7 @@ impl TreeNav for ListEditor {
|
||||||
if direction.x > 0
|
if direction.x > 0
|
||||||
{
|
{
|
||||||
if (cur.tree_addr[0] as usize) < self.data.len() {
|
if (cur.tree_addr[0] as usize) < self.data.len() {
|
||||||
let cur_item = self.data.get(cur.tree_addr[0] as usize);
|
let cur_item = self.get_edittree(cur.tree_addr[0] as usize);
|
||||||
let cur_height = cur_item.read().unwrap().get_height(&TreeHeightOp::P);
|
let cur_height = cur_item.read().unwrap().get_height(&TreeHeightOp::P);
|
||||||
|
|
||||||
if gravity && cur_height > 1 {
|
if gravity && cur_height > 1 {
|
||||||
|
@ -289,7 +293,7 @@ impl TreeNav for ListEditor {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (idx as usize) < self.data.len() {
|
if (idx as usize) < self.data.len() {
|
||||||
let pxv_item = self.data.get(idx as usize);
|
let pxv_item = self.get_edittree(idx as usize);
|
||||||
let pxv_height = pxv_item.read().unwrap().get_height(&TreeHeightOp::P);
|
let pxv_height = pxv_item.read().unwrap().get_height(&TreeHeightOp::P);
|
||||||
|
|
||||||
if gravity && pxv_height > 1 {
|
if gravity && pxv_height > 1 {
|
||||||
|
@ -324,10 +328,7 @@ impl TreeNav for ListEditor {
|
||||||
// nested
|
// nested
|
||||||
|
|
||||||
if cur.tree_addr[0] < self.data.len() as isize {
|
if cur.tree_addr[0] < self.data.len() as isize {
|
||||||
|
let cur_item = self.get_edittree(cur.tree_addr[0] as usize);
|
||||||
let cur_item = self.data
|
|
||||||
.get_mut(cur.tree_addr[0] as usize);
|
|
||||||
|
|
||||||
let result = cur_item.write().unwrap().goby(direction);
|
let result = cur_item.write().unwrap().goby(direction);
|
||||||
|
|
||||||
match result
|
match result
|
||||||
|
@ -353,8 +354,7 @@ impl TreeNav for ListEditor {
|
||||||
let mut new_addr = Vec::new();
|
let mut new_addr = Vec::new();
|
||||||
|
|
||||||
if direction.x < 0 {
|
if direction.x < 0 {
|
||||||
let pxv_item = self.data
|
let pxv_item = self.get_edittree(cur.tree_addr[0] as usize - 1);
|
||||||
.get_mut(cur.tree_addr[0] as usize - 1);
|
|
||||||
|
|
||||||
let pxv_height = pxv_item.read().unwrap().get_height(&TreeHeightOp::Q) as isize;
|
let pxv_height = pxv_item.read().unwrap().get_height(&TreeHeightOp::Q) as isize;
|
||||||
let cur_height = cur_item.read().unwrap().get_height(&TreeHeightOp::P) as isize;
|
let cur_height = cur_item.read().unwrap().get_height(&TreeHeightOp::P) as isize;
|
||||||
|
@ -372,8 +372,7 @@ impl TreeNav for ListEditor {
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
let nxd_item = self.data
|
let nxd_item = self.get_edittree(cur.tree_addr[0] as usize + 1);
|
||||||
.get_mut(cur.tree_addr[0] as usize + 1);
|
|
||||||
|
|
||||||
let cur_height = cur_item.read().unwrap().get_height(&TreeHeightOp::Q) as isize;
|
let cur_height = cur_item.read().unwrap().get_height(&TreeHeightOp::Q) as isize;
|
||||||
let nxd_height = nxd_item.read().unwrap().get_height(&TreeHeightOp::P) as isize;
|
let nxd_height = nxd_item.read().unwrap().get_height(&TreeHeightOp::P) as isize;
|
||||||
|
@ -422,4 +421,3 @@ impl TreeNav for ListEditor {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -154,7 +154,7 @@ impl Context {
|
||||||
|
|
||||||
pub fn make_repr(ctx: &Arc<RwLock<Self>>, t: &TypeTerm) -> ReprTreeArc {
|
pub fn make_repr(ctx: &Arc<RwLock<Self>>, t: &TypeTerm) -> ReprTreeArc {
|
||||||
let rt = Arc::new(RwLock::new(ReprTree::new( TypeTerm::unit() )));
|
let rt = Arc::new(RwLock::new(ReprTree::new( TypeTerm::unit() )));
|
||||||
ctx.read().unwrap().apply_morphism( &rt, &MorphismType{ src_type: TypeTerm::unit(), dst_type: t.clone() } );
|
ctx.write().unwrap().apply_morphism( &rt, &MorphismType{ src_type: TypeTerm::unit(), dst_type: t.clone() } );
|
||||||
rt
|
rt
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -277,4 +277,3 @@ impl Context {
|
||||||
}
|
}
|
||||||
|
|
||||||
//<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>>
|
//<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>>
|
||||||
|
|
||||||
|
|
|
@ -43,6 +43,7 @@ pub trait ReprTreeExt {
|
||||||
fn insert_branch(&mut self, repr: Arc<RwLock<ReprTree>>);
|
fn insert_branch(&mut self, repr: Arc<RwLock<ReprTree>>);
|
||||||
fn create_branch(&mut self, rung: impl Into<TypeTerm>);
|
fn create_branch(&mut self, rung: impl Into<TypeTerm>);
|
||||||
fn descend(&self, target_type: impl Into<TypeTerm>) -> Option< ReprTreeArc >;
|
fn descend(&self, target_type: impl Into<TypeTerm>) -> Option< ReprTreeArc >;
|
||||||
|
fn descend_create(&self, ctx: &Arc<RwLock<Context>>, target_type: impl Into<TypeTerm>) -> Option< ReprTreeArc >;
|
||||||
|
|
||||||
fn attach_leaf_to<V: View + ?Sized + 'static>(&self, t: impl Into<TypeTerm>, v: OuterViewPort<V>) where V::Msg: Clone;
|
fn attach_leaf_to<V: View + ?Sized + 'static>(&self, t: impl Into<TypeTerm>, v: OuterViewPort<V>) where V::Msg: Clone;
|
||||||
fn get_port<V: View + ?Sized + 'static>(&self) -> Option<OuterViewPort<V>> where V::Msg: Clone;
|
fn get_port<V: View + ?Sized + 'static>(&self) -> Option<OuterViewPort<V>> where V::Msg: Clone;
|
||||||
|
@ -60,7 +61,8 @@ pub trait ReprTreeExt {
|
||||||
fn vec_buffer<T: Clone + Send + Sync + 'static>(&self) -> VecBuffer<T>;
|
fn vec_buffer<T: Clone + Send + Sync + 'static>(&self) -> VecBuffer<T>;
|
||||||
|
|
||||||
fn edittree(&self, ctx: &Arc<RwLock<Context>>) -> SingletonBuffer< Arc<RwLock<crate::edit_tree::EditTree>> > {
|
fn edittree(&self, ctx: &Arc<RwLock<Context>>) -> SingletonBuffer< Arc<RwLock<crate::edit_tree::EditTree>> > {
|
||||||
self.descend(Context::parse(&ctx, "EditTree")).unwrap()
|
self.descend_create(&ctx, Context::parse(&ctx, "EditTree"))
|
||||||
|
.expect("failed to get EditTree")
|
||||||
.singleton_buffer()
|
.singleton_buffer()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -104,6 +106,10 @@ impl ReprTreeExt for Arc<RwLock<ReprTree>> {
|
||||||
ReprTree::descend( self, target_type )
|
ReprTree::descend( self, target_type )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn descend_create(&self, ctx: &Arc<RwLock<Context>>, target_type: impl Into<TypeTerm>)-> Option< ReprTreeArc > {
|
||||||
|
ReprTree::descend_create( &ctx, &self, target_type )
|
||||||
|
}
|
||||||
|
|
||||||
fn view_char(&self) -> OuterViewPort<dyn SingletonView<Item = char>> {
|
fn view_char(&self) -> OuterViewPort<dyn SingletonView<Item = char>> {
|
||||||
self.read().unwrap().view_char()
|
self.read().unwrap().view_char()
|
||||||
}
|
}
|
||||||
|
@ -142,4 +148,3 @@ impl ReprTreeExt for Arc<RwLock<ReprTree>> {
|
||||||
}
|
}
|
||||||
|
|
||||||
//<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>>
|
//<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>>
|
||||||
|
|
||||||
|
|
|
@ -80,29 +80,44 @@ impl GenericReprTreeMorphism {
|
||||||
lst_map_type.src_type.apply_substitution( &|x| subst.get(x).cloned() );
|
lst_map_type.src_type.apply_substitution( &|x| subst.get(x).cloned() );
|
||||||
lst_map_type.dst_type.apply_substitution( &|x| subst.get(x).cloned() );
|
lst_map_type.dst_type.apply_substitution( &|x| subst.get(x).cloned() );
|
||||||
|
|
||||||
|
lst_map_type = lst_map_type.normalize();
|
||||||
|
|
||||||
eprintln!(
|
eprintln!(
|
||||||
"lst map type : {:?}", lst_map_type
|
"lst map type ::\n {:?}\n===> {:?}\n\n", lst_map_type.src_type, lst_map_type.dst_type
|
||||||
);
|
);
|
||||||
|
|
||||||
let src_port = repr_tree
|
|
||||||
.descend( lst_map_type.src_type.clone() )
|
|
||||||
.expect("descend src seq")
|
|
||||||
.view_list::<SrcItem>();
|
|
||||||
|
|
||||||
let subst = subst.clone();
|
let mut item_ladder = item_morph.morph_type.src_type.clone().get_lnf_vec();
|
||||||
let item_morph = item_morph.clone();
|
let top_type = item_ladder.remove( item_ladder.len() - 1 );
|
||||||
|
|
||||||
let dst_view = src_port.map(
|
if let Ok(item_sigma) = laddertypes::unify(
|
||||||
|
&top_type,
|
||||||
|
&TypeTerm::App(vec![
|
||||||
|
TypeTerm::TypeID( list_typeid ),
|
||||||
|
TypeTerm::TypeID( TypeID::Var( 200 ) )
|
||||||
|
])
|
||||||
|
) {
|
||||||
|
eprintln!("List OF List...");
|
||||||
|
} else {
|
||||||
|
let src_port = repr_tree
|
||||||
|
.descend( lst_map_type.src_type.clone() )
|
||||||
|
.expect("descend src seq")
|
||||||
|
.view_list::<SrcItem>();
|
||||||
|
|
||||||
|
let subst = subst.clone();
|
||||||
|
let item_morph = item_morph.clone();
|
||||||
|
|
||||||
|
let dst_view = src_port.map(
|
||||||
move |x| {
|
move |x| {
|
||||||
let mut item_ladder = item_morph.morph_type.src_type.clone().get_lnf_vec();
|
|
||||||
let mut item_rt = ReprTree::from_singleton_buffer(
|
let mut item_rt = ReprTree::from_singleton_buffer(
|
||||||
item_ladder.remove( item_ladder.len() - 1 ),
|
top_type.clone(),
|
||||||
r3vi::buffer::singleton::SingletonBuffer::new(x.clone())
|
r3vi::buffer::singleton::SingletonBuffer::new(x.clone())
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
// TODO: required?
|
// TODO: required?
|
||||||
while item_ladder.len() > 0 {
|
for t in item_ladder.iter().rev() {
|
||||||
let mut n = ReprTree::new_arc( item_ladder.remove( item_ladder.len() - 1) );
|
let mut n = ReprTree::new_arc( t.clone() );
|
||||||
n.insert_branch( item_rt );
|
n.insert_branch( item_rt );
|
||||||
item_rt = n;
|
item_rt = n;
|
||||||
}
|
}
|
||||||
|
@ -112,13 +127,14 @@ impl GenericReprTreeMorphism {
|
||||||
.view_singleton::< DstItem >()
|
.view_singleton::< DstItem >()
|
||||||
.get_view().unwrap()
|
.get_view().unwrap()
|
||||||
.get()
|
.get()
|
||||||
}
|
});
|
||||||
);
|
|
||||||
|
|
||||||
repr_tree.attach_leaf_to(
|
|
||||||
lst_map_type.dst_type.clone(),
|
repr_tree.attach_leaf_to(
|
||||||
dst_view as r3vi::view::OuterViewPort::< dyn r3vi::view::list::ListView<DstItem> >
|
lst_map_type.dst_type.clone(),
|
||||||
);
|
dst_view as r3vi::view::OuterViewPort::< dyn r3vi::view::list::ListView<DstItem> >
|
||||||
|
);
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -192,16 +208,4 @@ impl GenericReprTreeMorphism {
|
||||||
}
|
}
|
||||||
|
|
||||||
//<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>>
|
//<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>>
|
||||||
/*
|
|
||||||
impl MorphismType {
|
|
||||||
pub fn to_str(&self, ctx: &Context) -> String {
|
|
||||||
format!("{:?} -> {:?}",
|
|
||||||
if let Some(t) = self.src_type.as_ref() {
|
|
||||||
ctx.type_dict.read().unwrap().unparse(t)
|
|
||||||
} else {
|
|
||||||
"None".into()
|
|
||||||
},
|
|
||||||
ctx.type_dict.read().unwrap().unparse(&self.dst_type))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
|
@ -28,6 +28,7 @@ use {
|
||||||
pub struct ReprTree {
|
pub struct ReprTree {
|
||||||
halo: TypeTerm,
|
halo: TypeTerm,
|
||||||
type_tag: TypeTerm,
|
type_tag: TypeTerm,
|
||||||
|
required_branches: Vec< TypeTerm >,
|
||||||
branches: HashMap<TypeTerm, ReprTreeArc>,
|
branches: HashMap<TypeTerm, ReprTreeArc>,
|
||||||
leaf: Option< ReprLeaf >
|
leaf: Option< ReprLeaf >
|
||||||
}
|
}
|
||||||
|
@ -64,6 +65,7 @@ impl ReprTree {
|
||||||
ReprTree {
|
ReprTree {
|
||||||
halo: TypeTerm::unit(),
|
halo: TypeTerm::unit(),
|
||||||
type_tag: head_type,
|
type_tag: head_type,
|
||||||
|
required_branches: Vec::new(),
|
||||||
branches,
|
branches,
|
||||||
leaf: None
|
leaf: None
|
||||||
}
|
}
|
||||||
|
@ -319,6 +321,19 @@ impl ReprTree {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn rebuild_projections(&mut self, ctx: &Arc<RwLock<Context>>) {
|
||||||
|
self.detach(ctx);
|
||||||
|
|
||||||
|
for (btyp, brt) in self.branches.iter_mut() {
|
||||||
|
brt.write().unwrap().rebuild_projections(ctx);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn require_repr(&mut self, ctx: &Arc<RwLock<Context>>, typ: impl Into<TypeTerm>) {
|
||||||
|
self.required_branches.push( typ.into() );
|
||||||
|
self.rebuild_projections(ctx);
|
||||||
|
}
|
||||||
|
|
||||||
pub fn insert_leaf(
|
pub fn insert_leaf(
|
||||||
&mut self,
|
&mut self,
|
||||||
mut type_ladder: impl Iterator<Item = TypeTerm>,
|
mut type_ladder: impl Iterator<Item = TypeTerm>,
|
||||||
|
@ -371,13 +386,51 @@ impl ReprTree {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn ascend(rt: &Arc<RwLock<Self>>, type_term: impl Into<TypeTerm>) -> Arc<RwLock<ReprTree>> {
|
pub fn descend_create(
|
||||||
|
ctx: &Arc<RwLock<Context>>,
|
||||||
|
rt: &Arc<RwLock<Self>>,
|
||||||
|
dst_type: impl Into<TypeTerm>
|
||||||
|
) -> Option< ReprTreeArc > {
|
||||||
|
let dst_type = dst_type.into();
|
||||||
|
if let Some(branch) = ReprTree::descend(rt, dst_type.clone()) {
|
||||||
|
Some(branch)
|
||||||
|
} else {
|
||||||
|
/*
|
||||||
|
let mt =
|
||||||
|
laddertypes::MorphismType {
|
||||||
|
// todo: use halo type ?
|
||||||
|
src_type: laddertypes::TypeTerm::Ladder(vec![
|
||||||
|
rt.read().unwrap().get_halo_type().clone(),
|
||||||
|
rt.get_type()
|
||||||
|
]),
|
||||||
|
dst_type:laddertypes::TypeTerm::Ladder(vec![
|
||||||
|
rt.read().unwrap().get_halo_type().clone(),
|
||||||
|
rt.get_type(),
|
||||||
|
dst_type.clone()
|
||||||
|
]),
|
||||||
|
}.normalize();
|
||||||
|
|
||||||
|
// branch does not exist, try to create it
|
||||||
|
ctx.read().unwrap().apply_morphism(rt,
|
||||||
|
&mt
|
||||||
|
);
|
||||||
|
*/
|
||||||
|
rt.write().unwrap().require_repr(ctx, dst_type.clone());
|
||||||
|
ReprTree::descend(rt, dst_type)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn ascend(rt: &Arc<RwLock<Self>>, type_term: impl Into<TypeTerm>) -> ReprTreeArc {
|
||||||
let mut n = Self::new(type_term);
|
let mut n = Self::new(type_term);
|
||||||
n.insert_branch(rt.clone());
|
n.insert_branch(rt.clone());
|
||||||
Arc::new(RwLock::new(n))
|
Arc::new(RwLock::new(n))
|
||||||
}
|
}
|
||||||
|
|
||||||
//<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>>
|
|
||||||
|
|
||||||
|
//<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>>\\
|
||||||
|
// Buffer Access \\
|
||||||
|
//<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>>\\
|
||||||
|
|
||||||
pub fn singleton_buffer<T: Clone + Send + Sync + 'static>(&mut self) -> Option<SingletonBuffer<T>> {
|
pub fn singleton_buffer<T: Clone + Send + Sync + 'static>(&mut self) -> Option<SingletonBuffer<T>> {
|
||||||
if let Some(leaf) = self.leaf.as_mut() {
|
if let Some(leaf) = self.leaf.as_mut() {
|
||||||
|
@ -402,7 +455,11 @@ impl ReprTree {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>>
|
|
||||||
|
|
||||||
|
//<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>>\\
|
||||||
|
// View Access \\
|
||||||
|
//<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>>\\
|
||||||
|
|
||||||
pub fn get_port<V: View + ?Sized + 'static>(&self) -> Option<OuterViewPort<V>>
|
pub fn get_port<V: View + ?Sized + 'static>(&self) -> Option<OuterViewPort<V>>
|
||||||
where
|
where
|
||||||
|
@ -455,5 +512,3 @@ impl ReprTree {
|
||||||
}
|
}
|
||||||
|
|
||||||
//<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>>
|
//<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>>
|
||||||
|
|
||||||
|
|
||||||
|
|
10
lib-nested-softbuffer/Cargo.toml
Normal file
10
lib-nested-softbuffer/Cargo.toml
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
[package]
|
||||||
|
authors = ["Michael Sippel <micha@fragmental.art>"]
|
||||||
|
name = "lib-nested-softbuffer"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
r3vi = { path = "../../lib-r3vi" }
|
||||||
|
laddertypes = { path = "../../lib-laddertypes" }
|
||||||
|
nested = { path = "../lib-nested-core" }
|
||||||
|
softbuffer = "0.4.2"
|
||||||
|
|
|
@ -70,7 +70,7 @@ impl PTYListStyle {
|
||||||
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_edittree_seq()
|
||||||
);
|
);
|
||||||
let se = seg_seq.read().unwrap();
|
let se = seg_seq.read().unwrap();
|
||||||
se.get_view().map(move |segment| segment.display_view())
|
se.get_view().map(move |segment| segment.display_view())
|
||||||
|
@ -79,7 +79,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_edittree_seq()
|
||||||
);
|
);
|
||||||
|
|
||||||
let seg_seq0 = seg_seq.read().unwrap();
|
let seg_seq0 = seg_seq.read().unwrap();
|
||||||
|
@ -162,17 +162,17 @@ impl PTYListController {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_data_port(&self) -> OuterViewPort<dyn SequenceView<Item = EditTree>> {
|
pub fn get_data_port(&self) -> OuterViewPort<dyn SequenceView<Item = EditTree>> {
|
||||||
self.editor.read().unwrap().get_data_port()
|
self.editor.read().unwrap().get_edittree_seq()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn clear(&mut self) {
|
pub fn clear(&mut self) {
|
||||||
self.editor.write().unwrap().clear();
|
self.editor.write().unwrap().clear();
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
pub fn get_item(&self) -> Option<EditTree> {
|
pub fn get_item(&self) -> Option<EditTree> {
|
||||||
self.editor.read().unwrap().get_item()
|
self.editor.read().unwrap().get_item()
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
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 {
|
||||||
|
@ -247,7 +247,7 @@ impl PTYListController {
|
||||||
match ne.send_cmd_obj(cmd_obj.clone()) {
|
match ne.send_cmd_obj(cmd_obj.clone()) {
|
||||||
TreeNavResult::Continue => {
|
TreeNavResult::Continue => {
|
||||||
drop(ne);
|
drop(ne);
|
||||||
e.insert(new_edittree.value.read().unwrap().clone());
|
e.insert(rt);
|
||||||
TreeNavResult::Continue
|
TreeNavResult::Continue
|
||||||
}
|
}
|
||||||
TreeNavResult::Exit => {
|
TreeNavResult::Exit => {
|
||||||
|
@ -260,7 +260,7 @@ impl PTYListController {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
ListCursorMode::Select => {
|
ListCursorMode::Select => {
|
||||||
if let Some(item) = e.get_item_mut() {
|
if let Some(item) = e.get_cur_edittree() {
|
||||||
let res = item.write().unwrap().send_cmd_obj(cmd_obj.clone());
|
let res = item.write().unwrap().send_cmd_obj(cmd_obj.clone());
|
||||||
let child_close_char = item.read().unwrap().ctrl.close_char.get();
|
let child_close_char = item.read().unwrap().ctrl.close_char.get();
|
||||||
|
|
||||||
|
|
|
@ -127,9 +127,10 @@ pub fn setup_edittree_hook(ctx: &Arc<RwLock<Context>>) {
|
||||||
let posint_hex_type = Context::parse(&ctx, "<PosInt 16 BigEndian>");
|
let posint_hex_type = Context::parse(&ctx, "<PosInt 16 BigEndian>");
|
||||||
let item_tyid = ctx.read().unwrap().get_var_typeid("Item").unwrap();
|
let item_tyid = ctx.read().unwrap().get_var_typeid("Item").unwrap();
|
||||||
|
|
||||||
ctx.write().unwrap().meta_chars.push(',');
|
ctx.write().unwrap().meta_chars.push('\n');
|
||||||
ctx.write().unwrap().meta_chars.push('\"');
|
//ctx.write().unwrap().meta_chars.push(',');
|
||||||
ctx.write().unwrap().meta_chars.push('}');
|
//ctx.write().unwrap().meta_chars.push('\"');
|
||||||
|
//ctx.write().unwrap().meta_chars.push('}');
|
||||||
|
|
||||||
// Define a hook which is executed when a new editTree of type `t` is created.
|
// Define a hook which is executed when a new editTree of type `t` is created.
|
||||||
// this will setup the display and navigation elements of the editor.
|
// this will setup the display and navigation elements of the editor.
|
||||||
|
|
Loading…
Reference in a new issue