This commit is contained in:
Michael Sippel 2024-12-13 19:53:36 +01:00
parent 41c02465be
commit 32b2cb5d1f
Signed by: senvas
GPG key ID: F96CF119C34B64A6
16 changed files with 648 additions and 269 deletions

View file

@ -48,6 +48,29 @@ async fn main() {
"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
*/
ctx.read().unwrap().apply_morphism(
@ -105,11 +128,11 @@ async fn main() {
.to_sequence()
.to_grid_vertical()
.map_item(|_pt,c| TerminalAtom::new(*c, TerminalStyle::fg_color((200,10,60))));
*/
/* setup terminal
*/
let app = TTYApplication::new({
let edittree_list = rt_string.edittree(&ctx).clone();
let edittree_list = ledittree.clone();//rt_string.edittree(&ctx).clone();
/* event handler
*/
@ -135,22 +158,23 @@ async fn main() {
nested_tty::make_label(&label_str)
.map_item(|_pt, atom| atom.add_style_front(TerminalStyle::fg_color((90,90,90))))
.offset(Vector2::new(1,1)));
comp.push(
rt_string.edittree(&ctx).get()
/*comp.push(
//rt_string.edittree(&ctx).get()
ledittree.get()
.read().unwrap()
.display_view()
.offset(Vector2::new(3,2)));
.offset(Vector2::new(3,2)));*/
/*
comp.push(
string_view_tty
.offset(Vector2::new(5,3)));
*/
}
/* write the changes in the view of `term_port` to the terminal
*/
app.show().await.expect("output error!");
/*
/* need to call update because changes are applied lazily
*/
chars_vec.get_port().0.update();
@ -165,4 +189,5 @@ async fn main() {
.iter().collect::<String>();
eprintln!("value of the editor was: {}\n\n", string);
*/
}

View file

@ -32,16 +32,20 @@ struct LineDiagnostic {
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 {
line_num: Arc< dyn SingletonView<Item = u64> >,
segments: Arc< dyn SequenceView<Item = ListSegment> >,
diagnostics: Arc< dyn SequenceView<Item = LineDiagnostic> >,
diag_buf: VecBuffer< LineDiagnostic >,
cast: Arc<RwLock<ObserverBroadcast<dyn TerminalView>>>,
out_port: OuterViewPort<dyn TerminalView>,
proj_helper: ProjectionHelper<usize, Self>
proj_helper: ProjectionHelper<usize, LineEditor>
}
impl View for LineView {
@ -121,10 +125,9 @@ impl IndexView<Point2<i16>> for LineView {
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);
IndexArea::Range(
Point2::new( xoff -1-n_digits , 0) ..=
Point2::new( xoff - n_digits - 1 , 0) ..=
Point2::new(
xoff+
i16::max(
xoff + i16::max(
self.segments.len().unwrap_or(i16::MAX as usize) as i16,
diag_len
),
@ -134,57 +137,72 @@ impl IndexView<Point2<i16>> for LineView {
}
}
impl LineView {
impl LineEditor {
pub fn new(
ctx: &Arc<RwLock<Context>>,
n: u64,
le: &ListEditor,
) -> Arc<RwLock<Self>> {
let line_num_buf = SingletonBuffer::new(n);
let num_buf = SingletonBuffer::new(n);
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();
let out_port = ViewPort::new();
let mut proj_helper = ProjectionHelper::new(out_port.update_hooks.clone());
let lv = Arc::new(RwLock::new(LineView{
line_num: proj_helper.new_singleton_arg(0, line_num_buf.get_port(),
|s: &mut LineView, _msg|{
s.cast.write().unwrap()
let mut proj_helper = ProjectionHelper::new(out_port.update_hooks.clone());
let line_view = Arc::new(RwLock::new(LineView {
line_num: proj_helper.new_singleton_arg(0, num_buf.get_port(),
|e: &mut LineEditor, _msg|{
e.cast.write().unwrap()
.notify(&IndexArea::Range(
(Point2::new(-100, 0) ..= Point2::new(0, 0))
));
}),
segments: proj_helper.new_sequence_arg(1, seg_seq,
|s: &mut LineView, idx| {
s.cast.write().unwrap()
segments: proj_helper.new_sequence_arg(1, chars_seg_seq,
|e: &mut LineEditor, idx| {
e.cast.write().unwrap()
.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(),
|s: &mut LineView, idx| {
s.cast.write().unwrap()
|e: &mut LineEditor, idx| {
e.cast.write().unwrap()
.notify(&IndexArea::Range(
(Point2::new(-100, 1+*idx as i16) ..= Point2::new(100, 1+*idx as i16))
));
}),
diag_buf,
cast: out_port.inner().get_broadcast(),
proj_helper,
out_port: out_port.outer()
}));
lv.write().unwrap().proj_helper.set_proj(&lv);
out_port.inner().set_view(Some(lv.clone()));
let line_edit = Arc::new(RwLock::new(LineEditor {
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> {
self.out_port.clone()
self.out_port.outer()
}
}
@ -205,6 +223,11 @@ impl LinesEditor {
Context::parse(&ctx, "Line ~ EditTree"),
|rt, σ| {
eprintln!("LINE EDITOR CONSTRUCT");
/*
rt.insert_branch(
Context::parse(&ctx, "EditTree"),
)*/
}
);
ctx.write().unwrap().morphisms.add_morphism( line_to_edittree );
@ -238,8 +261,7 @@ impl LinesEditor {
let mut list_edit = list_edit.into_node( depth_port );
nested_tty::editors::list::PTYListController::for_node( &mut list_edit, Some('\n'), None );
list_edit.disp.view
.write().unwrap()
list_edit.disp.view.write().unwrap()
.insert_branch(ReprTree::from_view(
Context::parse(&ctx, "TerminalView"),
lines_view
@ -258,26 +280,34 @@ impl LinesEditor {
.read().unwrap()
.data.len() as u64;
let line =
self.make_line(line_value)
let depth = SingletonBuffer::new(0).get_port();
let chars_rt = self.make_line(line_value);
let chars_edittree = chars_rt
.descend(Context::parse(&self.ctx, "EditTree")).unwrap()
.edittree(&self.ctx).get();
.edittree(&self.ctx).get()
.read().unwrap().clone();
let le = line.read().unwrap().get_edit::<ListEditor>().unwrap();
le.write().unwrap().goto(TreeCursor::none());
let line = LineEditor::new(&self.ctx, n);
line.write().unwrap().chars_edit = chars_edittree.get_edit::<ListEditor>().unwrap();
let line_port = line.read().unwrap().get_port();
let lvport = LineView::new( n, &*le.read().unwrap() ).read().unwrap().get_port();
line.write().unwrap().disp.view
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(
Context::parse(&self.ctx, "TerminalView"),
ReprLeaf::from_view( lvport )
ReprLeaf::from_view( line_port )
);
self.edit.write().unwrap()
.get_edit::< ListEditor >().unwrap()
.write().unwrap()
.data
.push(line);
.push( Arc::new(RwLock::new(line_edittree)) );
}
pub fn make_line(&self, line_value: &str) -> Arc<RwLock<ReprTree>> {
@ -287,6 +317,7 @@ impl LinesEditor {
line_value
);
// create Editor & transfer data to Editor
ctx.read().unwrap().apply_morphism(
&rt_line,
&laddertypes::MorphismType {

View 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"]

View 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!");
}

View file

@ -7,7 +7,7 @@ use {
},
laddertypes::{TypeTerm},
crate::{
repr_tree::{ReprTree, Context},
repr_tree::{ReprTree, ReprTreeArc, Context},
edit_tree::{TreeNav, TreeCursor, TreeNavResult, TreeHeightOp, diagnostics::{Diagnostics, Message}},
editors::{list::{ListCursorMode}, ObjCommander}
}
@ -32,9 +32,7 @@ pub struct EdittreeControl {
Option< Arc<dyn Any + Send + Sync> >
>,
pub spillbuf: Arc<RwLock<
Vec< Arc<RwLock< EditTree >> >
>>,
pub spillbuf: Arc<RwLock< Vec< ReprTreeArc > >>,
/// commander & navigation
pub cmd: SingletonBuffer<
@ -225,4 +223,3 @@ impl Diagnostics for EditTree {
self.get_diag()
}
}

View file

@ -35,28 +35,7 @@ impl ObjCommander for ListEditor {
fn send_cmd_obj(&mut self, cmd_obj: Arc<RwLock<ReprTree>>) -> TreeNavResult {
let cmd_repr = cmd_obj.read().unwrap();
if let Some(view) = cmd_repr.get_view::<dyn SingletonView<Item = EditTree>>() {
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>>() {
if let Some(cmd) = cmd_repr.get_view::<dyn SingletonView<Item = ListCmd>>() {
let cur = self.cursor.get();
drop(cmd_repr);
@ -70,7 +49,8 @@ impl ObjCommander for ListEditor {
if let Some(idx) = cur.idx {
match cur.mode {
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();
match cmd.get() {
@ -151,14 +131,30 @@ impl ObjCommander for ListEditor {
}
} else {
if let Some(cur_item) = self.get_item_mut() {
drop(cmd_repr);
cur_item.write().unwrap().send_cmd_obj(cmd_obj);
let cur = self.cursor.get();
if let Some(idx) = cur.idx {
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 {
TreeNavResult::Exit
}
}
}
}

View file

@ -10,7 +10,7 @@ use {
},
laddertypes::{TypeTerm},
crate::{
repr_tree::{Context, ReprTree, ReprLeaf, ReprTreeExt, GenericReprTreeMorphism},
repr_tree::{Context, ReprTree, ReprTreeArc, ReprLeaf, ReprTreeExt, GenericReprTreeMorphism},
edit_tree::{EditTree},
editors::{
char::{CharEditor},
@ -35,12 +35,12 @@ pub fn init_ctx(ctx: Arc<RwLock<Context>>) {
if let Some( item_type ) = σ.get( &item_id ) {
let mut item_vec_rt = src_rt
.descend(
Context::parse(&ctx, "<List Item~EditTree>~<Vec EditTree>")
Context::parse(&ctx, "<List Item>~<Vec EditTree>")
.apply_substitution(&|id| σ.get(id).cloned()).clone()
)
.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 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_edittree );
}

View file

@ -1,12 +1,12 @@
use {
r3vi::{
view::{OuterViewPort, singleton::*, sequence::*},
view::{OuterViewPort, singleton::*, sequence::*, list::*},
buffer::{singleton::*, vec::*},
projection::*
},
laddertypes::{TypeTerm},
crate::{
repr_tree::{Context, ReprTree},
repr_tree::{Context, ReprTree, ReprTreeExt, node::ReprTreeArc},
edit_tree::{EditTree, TreeNav, TreeCursor, diagnostics::Diagnostics},
editors::{list::{ListCursor, ListCursorMode, ListCmd}, ObjCommander},
},
@ -17,11 +17,8 @@ use {
pub struct ListEditor {
pub cursor: SingletonBuffer<ListCursor>,
// todo: (?) remove RwLock<..> around NestedNode ??
pub data: VecBuffer< Arc<RwLock<EditTree>> >,
pub spillbuf: Arc<RwLock<Vec<Arc<RwLock<EditTree>>>>>,
pub data: VecBuffer< ReprTreeArc >,
pub spillbuf: Arc<RwLock< Vec< ReprTreeArc > >>,
pub(super) addr_port: OuterViewPort<dyn SequenceView<Item = isize>>,
pub(super) mode_port: OuterViewPort<dyn SingletonView<Item = ListCursorMode>>,
@ -49,7 +46,7 @@ impl ListEditor {
pub fn with_data(
ctx: Arc<RwLock<Context>>,
typ: TypeTerm,
data: VecBuffer<Arc<RwLock<EditTree>>>
data: VecBuffer< ReprTreeArc >
) -> Self {
let cursor = SingletonBuffer::new(ListCursor::default());
@ -58,6 +55,7 @@ impl ListEditor {
.get_port()
.map({
let data = data.clone();
let ctx = ctx.clone();
move |c| {
let ip = SingletonBuffer::new(c.mode).get_port();
match c.mode {
@ -65,7 +63,10 @@ impl ListEditor {
ListCursorMode::Select => {
if let Some(idx) = c.idx {
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 {
ip
}
@ -86,11 +87,15 @@ impl ListEditor {
cursor.get_port()
.map({
let data = data.clone();
let ctx = ctx.clone();
move |cur| {
if cur.mode == ListCursorMode::Select {
if let Some(idx) = cur.idx {
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_nav(editor.clone())
.set_cmd(editor.clone())
.set_diag(e.get_data_port()
.set_diag(e.get_edittree_seq()
.enumerate()
.map(|(idx, item_editor)| {
let idx = *idx;
@ -156,10 +161,21 @@ impl ListEditor {
self.cursor.get_port()
}
pub fn get_data_port(&self) -> OuterViewPort<dyn SequenceView<Item = EditTree>> {
self.data.get_port().to_list().map(
|x| x.read().unwrap().clone()
).to_sequence()
pub fn get_reprtree_list(&self) -> OuterViewPort<dyn ListView<ReprTreeArc>> {
self.data.get_port().to_list()
}
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>> {
@ -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 {
let idx = crate::utils::modulo(idx as isize, self.data.len() as isize) as usize;
if idx < self.data.len() {
Some(self.data.get(idx).read().unwrap().clone())
Some( self.data.get(idx).clone() )
} else {
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 {
let idx = crate::utils::modulo(idx as isize, self.data.len() as isize) as usize;
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)
pub fn is_listlist(&self) -> bool {
self.ctx.read().unwrap().is_list_type(&self.typ)
@ -234,8 +267,9 @@ impl ListEditor {
}
/// insert a new element
pub fn insert(&mut self, item: Arc<RwLock<EditTree>>) {
item.read().unwrap().disp.depth.0.set_view(
pub fn insert(&mut self, item: ReprTreeArc) {
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()
);
@ -247,7 +281,7 @@ impl ListEditor {
if self.is_listlist() {
cur.mode = ListCursorMode::Select;
} else {
item.write().unwrap().goto(TreeCursor::none());
item_edit.write().unwrap().goto(TreeCursor::none());
cur.idx = Some(idx + 1);
}
}
@ -304,35 +338,28 @@ impl ListEditor {
let cur = self.get_cursor();
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 {
item.goto(TreeCursor::none());
ie.goto(TreeCursor::none());
self.set_leaf_mode(ListCursorMode::Insert);
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 mut et = self.ctx.read().unwrap().setup_edittree(&rt);
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());
for node in b.iter() {
tail_node
.send_cmd_obj(
ReprTree::from_singleton_buffer(
Context::parse(&self.ctx, "EditTree"),
SingletonBuffer::<EditTree>::new(
node.read().unwrap().clone()
)
)
);
for n in b.iter() {
tail_node.send_cmd_obj(n.clone());
}
b.clear();
@ -345,10 +372,7 @@ impl ListEditor {
}
drop(tail_node);
self.insert(
edittree.value.read().unwrap().clone()
);
self.insert(rt);
}
} else {
@ -361,8 +385,8 @@ impl ListEditor {
pub fn listlist_join_pxev(&mut self, idx: isize) {
{
let cur_editor = self.data.get(idx as usize);
let pxv_editor = self.data.get(idx as usize-1);
let cur_editor = self.data.get(idx as usize).edittree(&self.ctx).get();
let pxv_editor = self.data.get(idx as usize-1).edittree(&self.ctx).get();
let mut cur_editor = cur_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();
for x in data.iter() {
pxv_editor.send_cmd_obj(
ReprTree::from_singleton_buffer(
Context::parse(&self.ctx, "EditTree"),
SingletonBuffer::<EditTree>::new(
x.read().unwrap().clone()
)
)
);
pxv_editor.send_cmd_obj(x.clone());
}
@ -420,8 +437,8 @@ impl ListEditor {
pub fn listlist_join_nexd(&mut self, idx: usize) {
{
let cur_editor = self.data.get(idx);
let nxd_editor = self.data.get(idx + 1);
let cur_editor = self.data.get(idx).edittree(&self.ctx).get();
let nxd_editor = self.data.get(idx + 1).edittree(&self.ctx).get();
let mut cur_editor = cur_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();
for x in data.iter() {
cur_editor.send_cmd_obj(
ReprTree::from_singleton_buffer(
Context::parse(&self.ctx, "EditTree"),
SingletonBuffer::<EditTree>::new(
x.read().unwrap().clone()
)
)
);
cur_editor.send_cmd_obj(x.clone());
}
// fixme: is it oc0 or old_cur ??
@ -495,5 +505,3 @@ impl TreeType for ListEditor {
}
}
*/

View file

@ -11,6 +11,7 @@ use {
ListCursor, ListCursorMode,
editor::ListEditor
},
repr_tree::{ReprTreeExt},
edit_tree::{TreeCursor, TreeNav, TreeNavResult, TreeHeightOp}
},
cgmath::Vector2
@ -35,7 +36,10 @@ impl TreeNav for ListEditor {
TreeHeightOp::P => 0,
TreeHeightOp::Q => self.data.len() - 1,
_ => 0
}).read().unwrap().get_height(op)
})
.edittree(&self.ctx).get()
.read().unwrap()
.get_height(op)
} else {
1
}
@ -43,7 +47,9 @@ impl TreeNav for ListEditor {
TreeHeightOp::Max => {
1 + (0..self.data.len() as usize)
.map(|i| self.data
.get(i).read().unwrap()
.get(i)
.edittree(&self.ctx).get()
.read().unwrap()
.get_height(&TreeHeightOp::Max)
)
.max()
@ -68,7 +74,9 @@ impl TreeNav for ListEditor {
ListCursorMode::Select => {
if let Some(i) = cur.idx {
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);
return sub_cur;
} else {
@ -100,7 +108,7 @@ impl TreeNav for ListEditor {
ListCursorMode::Select => {
if let Some(i) = cur.idx {
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 {
sub_cur.tree_addr.insert(0, i as isize);
return sub_cur;
@ -124,7 +132,7 @@ impl TreeNav for ListEditor {
let old_cur = self.cursor.get();
if let Some(i) = old_cur.idx {
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 {
self.data
.get_mut(idx as usize)
self.get_edittree(idx as usize)
.write().unwrap()
.goto(TreeCursor {
leaf_mode: ListCursorMode::Select,
@ -165,8 +172,7 @@ impl TreeNav for ListEditor {
idx: Some(idx),
});
self.data
.get_mut(idx as usize)
self.get_edittree(idx as usize)
.write().unwrap()
.goto(TreeCursor {
leaf_mode: new_cur.leaf_mode,
@ -212,8 +218,7 @@ impl TreeNav for ListEditor {
// dn
if cur.tree_addr[0] < self.data.len() as isize {
if self.data
.get_mut(cur.tree_addr[0] as usize)
if self.get_edittree(cur.tree_addr[0] as usize)
.write().unwrap()
.goby(Vector2::new(direction.x, direction.y))
== TreeNavResult::Continue {
@ -247,11 +252,10 @@ impl TreeNav for ListEditor {
match cur.leaf_mode {
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 new_item = self.data
.get_mut(idx as usize);
let new_item = self.get_edittree(idx as usize);
let height = new_item.read().unwrap().get_height(
if direction.x < 0 {
@ -277,7 +281,7 @@ impl TreeNav for ListEditor {
if direction.x > 0
{
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);
if gravity && cur_height > 1 {
@ -289,7 +293,7 @@ impl TreeNav for ListEditor {
}
} else {
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);
if gravity && pxv_height > 1 {
@ -324,10 +328,7 @@ impl TreeNav for ListEditor {
// nested
if cur.tree_addr[0] < self.data.len() as isize {
let cur_item = self.data
.get_mut(cur.tree_addr[0] as usize);
let cur_item = self.get_edittree(cur.tree_addr[0] as usize);
let result = cur_item.write().unwrap().goby(direction);
match result
@ -353,8 +354,7 @@ impl TreeNav for ListEditor {
let mut new_addr = Vec::new();
if direction.x < 0 {
let pxv_item = self.data
.get_mut(cur.tree_addr[0] as usize - 1);
let pxv_item = self.get_edittree(cur.tree_addr[0] as usize - 1);
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;
@ -372,8 +372,7 @@ impl TreeNav for ListEditor {
}
} else {
let nxd_item = self.data
.get_mut(cur.tree_addr[0] as usize + 1);
let nxd_item = self.get_edittree(cur.tree_addr[0] as usize + 1);
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;
@ -422,4 +421,3 @@ impl TreeNav for ListEditor {
}
}
}

View file

@ -154,7 +154,7 @@ impl Context {
pub fn make_repr(ctx: &Arc<RwLock<Self>>, t: &TypeTerm) -> ReprTreeArc {
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
}
@ -277,4 +277,3 @@ impl Context {
}
//<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>>

View file

@ -43,6 +43,7 @@ pub trait ReprTreeExt {
fn insert_branch(&mut self, repr: Arc<RwLock<ReprTree>>);
fn create_branch(&mut self, rung: impl Into<TypeTerm>);
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 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 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()
}
}
@ -104,6 +106,10 @@ impl ReprTreeExt for Arc<RwLock<ReprTree>> {
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>> {
self.read().unwrap().view_char()
}
@ -142,4 +148,3 @@ impl ReprTreeExt for Arc<RwLock<ReprTree>> {
}
//<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>>

View file

@ -80,10 +80,25 @@ impl GenericReprTreeMorphism {
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 = lst_map_type.normalize();
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 mut item_ladder = item_morph.morph_type.src_type.clone().get_lnf_vec();
let top_type = item_ladder.remove( item_ladder.len() - 1 );
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")
@ -94,15 +109,15 @@ impl GenericReprTreeMorphism {
let dst_view = src_port.map(
move |x| {
let mut item_ladder = item_morph.morph_type.src_type.clone().get_lnf_vec();
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())
);
// TODO: required?
while item_ladder.len() > 0 {
let mut n = ReprTree::new_arc( item_ladder.remove( item_ladder.len() - 1) );
for t in item_ladder.iter().rev() {
let mut n = ReprTree::new_arc( t.clone() );
n.insert_branch( item_rt );
item_rt = n;
}
@ -112,13 +127,14 @@ impl GenericReprTreeMorphism {
.view_singleton::< DstItem >()
.get_view().unwrap()
.get()
}
);
});
repr_tree.attach_leaf_to(
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))
}
}
*/

View file

@ -28,6 +28,7 @@ use {
pub struct ReprTree {
halo: TypeTerm,
type_tag: TypeTerm,
required_branches: Vec< TypeTerm >,
branches: HashMap<TypeTerm, ReprTreeArc>,
leaf: Option< ReprLeaf >
}
@ -64,6 +65,7 @@ impl ReprTree {
ReprTree {
halo: TypeTerm::unit(),
type_tag: head_type,
required_branches: Vec::new(),
branches,
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(
&mut self,
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);
n.insert_branch(rt.clone());
Arc::new(RwLock::new(n))
}
//<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>>
//<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>>\\
// Buffer Access \\
//<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>>\\
pub fn singleton_buffer<T: Clone + Send + Sync + 'static>(&mut self) -> Option<SingletonBuffer<T>> {
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>>
where
@ -455,5 +512,3 @@ impl ReprTree {
}
//<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>>

View 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"

View file

@ -70,7 +70,7 @@ impl PTYListStyle {
pub fn get_seg_seq_view(&self, editor: &ListEditor) -> OuterViewPort<dyn SequenceView<Item = OuterViewPort<dyn TerminalView>>> {
let seg_seq = ListSegmentSequence::new(
editor.get_cursor_port(),
editor.get_data_port()
editor.get_edittree_seq()
);
let se = seg_seq.read().unwrap();
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> {
let seg_seq = ListSegmentSequence::new(
editor.get_cursor_port(),
editor.get_data_port()
editor.get_edittree_seq()
);
let seg_seq0 = seg_seq.read().unwrap();
@ -162,17 +162,17 @@ impl PTYListController {
}
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) {
self.editor.write().unwrap().clear();
}
/*
pub fn get_item(&self) -> Option<EditTree> {
self.editor.read().unwrap().get_item()
}
*/
pub fn handle_term_event(&mut self, event: &TerminalEvent, cmd_obj: Arc<RwLock<ReprTree>>) -> TreeNavResult {
let mut e = self.editor.write().unwrap();
match event {
@ -247,7 +247,7 @@ impl PTYListController {
match ne.send_cmd_obj(cmd_obj.clone()) {
TreeNavResult::Continue => {
drop(ne);
e.insert(new_edittree.value.read().unwrap().clone());
e.insert(rt);
TreeNavResult::Continue
}
TreeNavResult::Exit => {
@ -260,7 +260,7 @@ impl PTYListController {
}
},
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 child_close_char = item.read().unwrap().ctrl.close_char.get();

View file

@ -127,9 +127,10 @@ pub fn setup_edittree_hook(ctx: &Arc<RwLock<Context>>) {
let posint_hex_type = Context::parse(&ctx, "<PosInt 16 BigEndian>");
let item_tyid = ctx.read().unwrap().get_var_typeid("Item").unwrap();
ctx.write().unwrap().meta_chars.push(',');
ctx.write().unwrap().meta_chars.push('\"');
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('}');
// 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.