example wip: create display for edit tree

This commit is contained in:
Michael Sippel 2024-01-17 03:42:47 +01:00
parent 863fe95848
commit 0ac4a34743
Signed by: senvas
GPG key ID: F96CF119C34B64A6
6 changed files with 87 additions and 102 deletions

View file

@ -6,6 +6,7 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies] [dependencies]
laddertypes = { path = "../../../lib-laddertypes" }
r3vi = { path = "../../../lib-r3vi" } r3vi = { path = "../../../lib-r3vi" }
nested = { path = "../../lib-nested-core" } nested = { path = "../../lib-nested-core" }
nested-tty = { path = "../../lib-nested-tty" } nested-tty = { path = "../../lib-nested-tty" }

View file

@ -32,6 +32,32 @@ async fn main() {
nested::editors::integer::editor::init_ctx( ctx.clone() ); nested::editors::integer::editor::init_ctx( ctx.clone() );
nested::editors::list::init_ctx( ctx.clone() ); nested::editors::list::init_ctx( ctx.clone() );
let char_type = Context::parse(&ctx, "Char");
let digit_type = Context::parse(&ctx, "<Digit Radix>");
let list_type = Context::parse(&ctx, "<List Item>");
ctx.write().unwrap().set_edittree_hook(
Arc::new(
move |et: Arc<RwLock<EditTree>>, t: laddertypes::TypeTerm| {
if let Ok(σ) = laddertypes::unify(&t, &char_type) {
let mut et = et.write().unwrap();
*et = nested_tty::editors::edittree_make_char_view(et.clone());
}
else if let Ok(σ) = laddertypes::unify(&t, &digit_type) {
let mut et = et.write().unwrap();
*et = nested_tty::editors::edittree_make_digit_view(et.clone());
}
else if let Ok(σ) = laddertypes::unify(&t, &list_type) {
let mut et = et.write().unwrap();
nested_tty::editors::list::PTYListStyle::for_node( &mut *et, ("(", ",", ")"));
nested_tty::editors::list::PTYListController::for_node( &mut *et, None, None );
*et = nested_tty::editors::edittree_make_list_edit(et.clone());
}
}
)
);
/* structure of Repr-Tree /* structure of Repr-Tree
* *
* === Repr-Tree === * === Repr-Tree ===
@ -60,67 +86,13 @@ async fn main() {
SingletonBuffer::new('x').get_port().into() SingletonBuffer::new('x').get_port().into()
); );
let port_char = rt_digit.read().unwrap()
.descend(Context::parse(&ctx, "Char")).unwrap().read().unwrap()
.get_port::<dyn r3vi::view::singleton::SingletonView<Item = char>>().unwrap().0;
ctx.read().unwrap()
.morphisms
.morph(
rt_digit.clone(),
&Context::parse(&ctx, "<Digit 16>~EditTree")
);
let port_edit = rt_digit.read().unwrap()
.descend(Context::parse(&ctx, "EditTree")).unwrap()
.read().unwrap()
.get_port::<dyn r3vi::view::singleton::SingletonView<Item = Arc<RwLock<EditTree>> >>().unwrap();
/* setup TTY-Display for DigitEditor /* setup TTY-Display for DigitEditor
*/ */
{ let edittree_digit = ctx.read().unwrap().setup_edittree(rt_digit.clone(), r3vi::buffer::singleton::SingletonBuffer::new(0).get_port());
let et = port_edit.get_view().unwrap().get().clone();
let mut et = et.write().unwrap();
*et = nested_tty::editors::edittree_make_digit_view(et.clone());
}
//--- //---
let rt_string = ReprTree::new_arc( Context::parse(&ctx, "<List <Digit 10>>") ); let rt_string = ReprTree::new_arc( Context::parse(&ctx, "<List <List <Digit 16>>>") );
ctx.read().unwrap() let edittree = ctx.read().unwrap().setup_edittree(rt_string.clone(), r3vi::buffer::singleton::SingletonBuffer::new(0).get_port());
.morphisms
.morph(
rt_string.clone(),
&Context::parse(&ctx, "<List <Digit 10>>~EditTree")
);
let editport_string = rt_string.read().unwrap()
.descend(Context::parse(&ctx, "EditTree")).unwrap()
.read().unwrap()
.get_port::<dyn r3vi::view::singleton::SingletonView<Item = Arc<RwLock<EditTree>>> >().unwrap();
/* setup TTY-Display for ListEditor
*/
{
let et = editport_string.get_view().unwrap().get().clone();
let mut et = et.write().unwrap();
*et = nested_tty::editors::edittree_make_list_edit(et.clone());
}
/*
let vec_string = Arc::new(RwLock::new(Vec::<char>::new()));
rt_string.write().unwrap()
.insert_leaf(
vec![ Context::parse(&ctx, "<Vec Char>") ].into_iter(),
r3vi::view::ViewPort::with_view(vec_string).into_outer().into()
);
rt_string.write().unwrap()
.insert_leaf(
vec![ Context::parse(&ctx, "EditTree") ].into_iter(),
r3vi::view::ViewPort::with_view()
);
*/
/* setup terminal /* setup terminal
*/ */
@ -128,9 +100,9 @@ async fn main() {
/* event handler /* event handler
*/ */
let ctx = ctx.clone(); let ctx = ctx.clone();
let et1 = editport_string.clone(); let et1 = edittree.clone();
move |ev| { move |ev| {
et1.get_view().unwrap().get().write().unwrap().send_cmd_obj(ev.to_repr_tree(&ctx)); et1.write().unwrap().send_cmd_obj(ev.to_repr_tree(&ctx));
} }
}); });
@ -146,7 +118,7 @@ async fn main() {
}) })
.offset(Vector2::new(5, 0)), .offset(Vector2::new(5, 0)),
); );
compositor.write().unwrap().push( port_edit.get_view().unwrap().get().read().unwrap().display_view().offset(Vector2::new(0,2)) ); compositor.write().unwrap().push( edittree_digit.read().unwrap().display_view().offset(Vector2::new(0,2)) );
let label = ctx.read().unwrap().type_term_to_str(&rt_digit.read().unwrap().get_type()); let label = ctx.read().unwrap().type_term_to_str(&rt_digit.read().unwrap().get_type());
compositor compositor
@ -154,7 +126,7 @@ async fn main() {
.unwrap() .unwrap()
.push(nested_tty::make_label(&label).offset(Vector2::new(0, 1))); .push(nested_tty::make_label(&label).offset(Vector2::new(0, 1)));
compositor.write().unwrap().push( editport_string.get_view().unwrap().get().read().unwrap().display_view().offset(Vector2::new(0,4)) ); compositor.write().unwrap().push( edittree.read().unwrap().display_view().offset(Vector2::new(0,4)) );
let label = ctx.read().unwrap().type_term_to_str(&rt_string.read().unwrap().get_type()); let label = ctx.read().unwrap().type_term_to_str(&rt_string.read().unwrap().get_type());
compositor compositor

View file

@ -11,7 +11,7 @@ use {
//<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>> //<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>>
pub fn init_ctx(ctx: Arc<RwLock<Context>>) { pub fn init_ctx(ctx: Arc<RwLock<Context>>) {
ctx.write().unwrap().add_list_typename("List".into());
ctx.write().unwrap().add_varname("Item"); ctx.write().unwrap().add_varname("Item");
let mt = crate::repr_tree::MorphismType { let mt = crate::repr_tree::MorphismType {
src_type: Context::parse(&ctx, "<List Item>"), src_type: Context::parse(&ctx, "<List Item>"),
@ -24,7 +24,6 @@ pub fn init_ctx(ctx: Arc<RwLock<Context>>) {
move |rt, σ| { move |rt, σ| {
let item_id = laddertypes::TypeID::Var( ctx.read().unwrap().get_var_typeid("Item").unwrap() ); let item_id = laddertypes::TypeID::Var( ctx.read().unwrap().get_var_typeid("Item").unwrap() );
if let Some( item_type ) = σ.get( &item_id ) { if let Some( item_type ) = σ.get( &item_id ) {
eprintln!("create list of {:?}", item_type);
let mut edittree_list = ListEditor::new( let mut edittree_list = ListEditor::new(
ctx.clone(), ctx.clone(),
item_type.clone() item_type.clone()
@ -43,33 +42,5 @@ pub fn init_ctx(ctx: Arc<RwLock<Context>>) {
} }
} }
); );
/*
ctx.add_typename("ListCmd".into());
ctx.add_list_typename("List".into());
ctx.add_node_ctor(
"List", Arc::new(
|ctx: Arc<RwLock<Context>>, ty: TypeTerm, depth: OuterViewPort<dyn SingletonView<Item = usize>>| {
match ty {
TypeTerm::App(args) => {
if args.len() > 1 {
let typ = args[1].clone();
let mut node = ListEditor::new(ctx.clone(), typ).into_node(depth);
// PTYListController::for_node( &mut node, Some(','), Some('}') );
// PTYListStyle::for_node( &mut node, ("{",", ","}") );
Some(node)
} else {
None
}
}
_ => None
}
}
)
);
*/
} }

View file

@ -29,12 +29,16 @@ pub struct Context {
pub list_types: Vec< TypeID >, pub list_types: Vec< TypeID >,
pub meta_chars: Vec< char >, pub meta_chars: Vec< char >,
edittree_hook: Arc< dyn Fn(Arc<RwLock<EditTree>>, TypeTerm) + Send +Sync +'static >,
/// recursion /// recursion
parent: Option<Arc<RwLock<Context>>>, parent: Option<Arc<RwLock<Context>>>,
} }
impl Context { impl Context {
pub fn with_parent(parent: Option<Arc<RwLock<Context>>>) -> Self { pub fn with_parent(
parent: Option<Arc<RwLock<Context>>>
) -> Self {
Context { Context {
type_dict: match parent.as_ref() { type_dict: match parent.as_ref() {
Some(p) => p.read().unwrap().type_dict.clone(), Some(p) => p.read().unwrap().type_dict.clone(),
@ -51,6 +55,8 @@ impl Context {
None => Vec::new() None => Vec::new()
}, },
parent, parent,
edittree_hook: Arc::new(|_et, _t| {})
} }
} }
@ -58,6 +64,10 @@ impl Context {
Context::with_parent(None) Context::with_parent(None)
} }
pub fn set_edittree_hook(&mut self, hook: Arc< dyn Fn(Arc<RwLock<EditTree>>, TypeTerm) + Send +Sync +'static >) {
self.edittree_hook = hook;
}
pub fn depth(&self) -> usize { pub fn depth(&self) -> usize {
if let Some(parent) = self.parent.as_ref() { if let Some(parent) = self.parent.as_ref() {
parent.read().unwrap().depth() + 1 parent.read().unwrap().depth() + 1
@ -165,6 +175,36 @@ impl Context {
None None
} }
} }
pub fn setup_edittree(
&self,
rt: Arc<RwLock<ReprTree>>,
depth: OuterViewPort<dyn SingletonView<Item = usize>>
) -> Arc<RwLock<EditTree>> {
let ladder = TypeTerm::Ladder(vec![
rt.read().unwrap().get_type().clone(),
self.type_term_from_str("EditTree").expect("")
]);
self.morphisms.morph(
rt.clone(),
&ladder
);
let new_edittree = rt
.read().unwrap()
.descend(
self.type_term_from_str("EditTree").expect("")
).unwrap()
.read().unwrap()
.get_view::<dyn SingletonView<Item = Arc<RwLock<EditTree>> >>()
.unwrap()
.get();
(*self.edittree_hook)( new_edittree.clone(), rt.read().unwrap().get_type().clone() );
new_edittree
}
} }
//<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>> //<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>>

View file

@ -139,6 +139,7 @@ impl PTYListController {
split_char: Option<char>, split_char: Option<char>,
close_char: Option<char> close_char: Option<char>
) { ) {
/*
{ {
let ctx = node.ctx.as_ref(); let ctx = node.ctx.as_ref();
let mut ctx = ctx.write().unwrap(); let mut ctx = ctx.write().unwrap();
@ -150,7 +151,7 @@ impl PTYListController {
ctx.meta_chars.push(*c); ctx.meta_chars.push(*c);
} }
} }
*/
let editor = node.get_edit::<ListEditor>().unwrap(); let editor = node.get_edit::<ListEditor>().unwrap();
let controller = Arc::new(RwLock::new(PTYListController::from_editor( editor, split_char, close_char, node.disp.depth.clone() ))); let controller = Arc::new(RwLock::new(PTYListController::from_editor( editor, split_char, close_char, node.disp.depth.clone() )));
@ -219,21 +220,22 @@ impl PTYListController {
match cur.mode { match cur.mode {
ListCursorMode::Insert => { ListCursorMode::Insert => {
/* TODO let rt = ReprTree::new_arc(e.typ.clone());
let mut new_edit = Context::make_node(&e.ctx, e.typ.clone(), self.depth.map(|d| d+1)).unwrap(); let new_edittree = ctx.setup_edittree(
new_edit.goto(TreeCursor::home()); rt,
self.depth.map(|d| d+1)
match new_edit.send_cmd_obj(cmd_obj.clone()) { );
let mut ne = new_edittree.write().unwrap();
match ne.send_cmd_obj(cmd_obj.clone()) {
TreeNavResult::Continue => { TreeNavResult::Continue => {
e.insert(Arc::new(RwLock::new(new_edit.clone()))); drop(ne);
e.insert(new_edittree.clone());
TreeNavResult::Continue TreeNavResult::Continue
} }
TreeNavResult::Exit => { TreeNavResult::Exit => {
TreeNavResult::Exit TreeNavResult::Exit
} }
} }
*/
TreeNavResult::Continue
}, },
ListCursorMode::Select => { ListCursorMode::Select => {
if let Some(item) = e.get_item_mut() { if let Some(item) = e.get_item_mut() {

View file

@ -90,7 +90,6 @@ pub fn edittree_make_list_edit(
) -> EditTree { ) -> EditTree {
list::PTYListStyle::for_node( &mut node, ("(", "", ")") ); list::PTYListStyle::for_node( &mut node, ("(", "", ")") );
list::PTYListController::for_node( &mut node, None, None ); list::PTYListController::for_node( &mut node, None, None );
node node
} }
/* /*