example wip
This commit is contained in:
parent
fdf2d60b35
commit
863fe95848
6 changed files with 168 additions and 109 deletions
|
@ -29,6 +29,8 @@ async fn main() {
|
|||
let ctx = Arc::new(RwLock::new(Context::new()));
|
||||
|
||||
nested::editors::char::init_ctx( ctx.clone() );
|
||||
nested::editors::integer::editor::init_ctx( ctx.clone() );
|
||||
nested::editors::list::init_ctx( ctx.clone() );
|
||||
|
||||
/* structure of Repr-Tree
|
||||
*
|
||||
|
@ -47,12 +49,11 @@ async fn main() {
|
|||
* / | \
|
||||
* TTY PixelBuf SDF
|
||||
*/
|
||||
let rt_digit = ReprTree::new_arc( Context::parse(&ctx, "<Digit 10>") );
|
||||
// let port_char = r3vi::view::ViewPort::<dyn r3vi::view::singleton::SingletonView<Item = char>>::new();
|
||||
let port_u32 = r3vi::view::ViewPort::<dyn r3vi::view::singleton::SingletonView<Item = u32>>::new();
|
||||
let port_edit = r3vi::view::ViewPort::<dyn r3vi::view::singleton::SingletonView<Item = EditTree>>::new();
|
||||
let port_char_edit = r3vi::view::ViewPort::<dyn r3vi::view::singleton::SingletonView<Item = EditTree>>::new();
|
||||
let rt_digit = ReprTree::new_arc( Context::parse(&ctx, "<Digit 16>") );
|
||||
|
||||
/* add initial representation
|
||||
* <Digit 16> ~ Char
|
||||
*/
|
||||
rt_digit.write().unwrap()
|
||||
.insert_leaf(
|
||||
vec![ Context::parse(&ctx, "Char") ].into_iter(),
|
||||
|
@ -63,93 +64,73 @@ async fn main() {
|
|||
.descend(Context::parse(&ctx, "Char")).unwrap().read().unwrap()
|
||||
.get_port::<dyn r3vi::view::singleton::SingletonView<Item = char>>().unwrap().0;
|
||||
|
||||
rt_digit.write().unwrap()
|
||||
.insert_leaf(
|
||||
vec![ Context::parse(&ctx, "EditTree") ].into_iter(),
|
||||
port_edit.outer().into()
|
||||
ctx.read().unwrap()
|
||||
.morphisms
|
||||
.morph(
|
||||
rt_digit.clone(),
|
||||
&Context::parse(&ctx, "<Digit 16>~EditTree")
|
||||
);
|
||||
|
||||
/*
|
||||
let rt_string = ReprTree::new_arc( Context::parse(&ctx, "<Seq Char>") );
|
||||
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();
|
||||
|
||||
let vec_string = Arc::new(RwLock::new(Vec::new()));
|
||||
/* setup TTY-Display for DigitEditor
|
||||
*/
|
||||
{
|
||||
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>>") );
|
||||
ctx.read().unwrap()
|
||||
.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()
|
||||
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 projections between representations
|
||||
*/
|
||||
eprintln!("rt_digit = {:?}", rt_digit);
|
||||
eprintln!("morph [ Char ==> Char~EditTree ]");
|
||||
|
||||
let rt_char = rt_digit.read().unwrap()
|
||||
.descend(Context::parse(&ctx, "Char"))
|
||||
.unwrap().clone();
|
||||
|
||||
eprintln!("rt_char = {:?}", rt_char);
|
||||
|
||||
ctx.read().unwrap()
|
||||
.morphisms
|
||||
.morph(
|
||||
rt_char.clone(),
|
||||
&Context::parse(&ctx, "Char~EditTree")
|
||||
);
|
||||
|
||||
eprintln!("rt_digit = {:?}", rt_char);
|
||||
|
||||
let edittree_char =
|
||||
ReprTree::descend_ladder(
|
||||
&rt_digit,
|
||||
vec![
|
||||
Context::parse(&ctx, "Char"),
|
||||
Context::parse(&ctx, "EditTree")
|
||||
].into_iter()
|
||||
).unwrap()
|
||||
.read().unwrap()
|
||||
.get_view::<dyn r3vi::view::singleton::SingletonView<Item = EditTree>>().unwrap()
|
||||
.get();
|
||||
|
||||
let mut edit_char = edittree_char.get_edit::< nested::editors::char::CharEditor >().unwrap();
|
||||
port_char.attach_to( edit_char.read().unwrap().get_port() );
|
||||
|
||||
let buf_edit_char = r3vi::buffer::singleton::SingletonBuffer::new( edittree_char.clone() );
|
||||
port_char_edit.attach_to( buf_edit_char.get_port() );
|
||||
|
||||
// created by <Digit 10> ==> <Digit 10>~EditTree
|
||||
let mut node_edit_digit =
|
||||
nested::editors::integer::DigitEditor::new(
|
||||
ctx.clone(),
|
||||
16
|
||||
).into_node(
|
||||
r3vi::buffer::singleton::SingletonBuffer::<usize>::new(0).get_port()
|
||||
);
|
||||
|
||||
node_edit_digit = nested_tty::editors::edittree_make_digit_view( node_edit_digit );
|
||||
let mut edit_digit = node_edit_digit.get_edit::< nested::editors::integer::DigitEditor >().unwrap();
|
||||
/*
|
||||
// created by <Digit 10> ==> <Digit 10>~U32
|
||||
port_u32.attach_to( port_char.outer().map(|c| c.to_digit(16).unwrap_or(0)) );
|
||||
// port_u32.attach_to( edit_digit.read().unwrap().get_data_port().map(|d| d.unwrap_or(0)) );
|
||||
|
||||
let port_proj_u32_to_char = port_u32.outer().map(|val| char::from_digit(val, 16).unwrap_or('?') );
|
||||
*/
|
||||
|
||||
let buf_edit_digit = r3vi::buffer::singleton::SingletonBuffer::new( node_edit_digit );
|
||||
port_edit.attach_to( buf_edit_digit.get_port() );
|
||||
|
||||
/* setup terminal
|
||||
*/
|
||||
let app = TTYApplication::new({
|
||||
/* event handler
|
||||
*/
|
||||
let ctx = ctx.clone();
|
||||
let node1 = buf_edit_digit.clone();
|
||||
let et1 = editport_string.clone();
|
||||
move |ev| {
|
||||
node1.get().send_cmd_obj(ev.to_repr_tree(&ctx));
|
||||
et1.get_view().unwrap().get().write().unwrap().send_cmd_obj(ev.to_repr_tree(&ctx));
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -165,19 +146,22 @@ async fn main() {
|
|||
})
|
||||
.offset(Vector2::new(5, 0)),
|
||||
);
|
||||
compositor.write().unwrap().push( buf_edit_digit.get().display_view().offset(Vector2::new(0,2)) );
|
||||
compositor.write().unwrap().push( port_edit.get_view().unwrap().get().read().unwrap().display_view().offset(Vector2::new(0,2)) );
|
||||
|
||||
let label = ctx.read().unwrap().type_term_to_str(&rt_digit.read().unwrap().get_type());
|
||||
compositor
|
||||
.write()
|
||||
.unwrap()
|
||||
.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)) );
|
||||
|
||||
let label = ctx.read().unwrap().type_term_to_str(&rt_string.read().unwrap().get_type());
|
||||
compositor
|
||||
.write()
|
||||
.unwrap()
|
||||
.push(node1.display_view().offset(Vector2::new(15, 2)));
|
||||
*/
|
||||
.push(nested_tty::make_label(&label).offset(Vector2::new(0, 3)));
|
||||
|
||||
/* write the changes in the view of `term_port` to the terminal
|
||||
*/
|
||||
app.show().await.expect("output error!");
|
||||
|
|
|
@ -37,17 +37,13 @@ pub fn init_ctx( ctx: Arc<RwLock<Context>> ) {
|
|||
ctx.clone(),
|
||||
r3vi::buffer::singleton::SingletonBuffer::<usize>::new(0).get_port()
|
||||
);
|
||||
/*
|
||||
/* setup tty-view for EditTree
|
||||
*/
|
||||
edittree_char = nested_tty::editors::edittree_make_char_view( edittree_char );
|
||||
*/
|
||||
|
||||
/* Insert EditTree into ReprTree
|
||||
*/
|
||||
let mut rt = rt.write().unwrap();
|
||||
rt.insert_leaf(
|
||||
vec![ Context::parse(&ctx, "EditTree") ].into_iter(),
|
||||
SingletonBuffer::new(edittree_char).get_port().into()
|
||||
SingletonBuffer::new( Arc::new(RwLock::new( edittree_char )) ).get_port().into()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,6 +22,51 @@ use {
|
|||
cgmath::{Point2}
|
||||
};
|
||||
|
||||
|
||||
pub fn init_ctx( ctx: Arc<RwLock<Context>> ) {
|
||||
|
||||
// todo: proper scoping of Radix variable
|
||||
ctx.write().unwrap().add_varname("Radix");
|
||||
let morphtype =
|
||||
crate::repr_tree::MorphismType {
|
||||
src_type: Context::parse(&ctx, "<Digit Radix>"),
|
||||
dst_type: Context::parse(&ctx, "<Digit Radix>~EditTree")
|
||||
};
|
||||
|
||||
ctx.write().unwrap()
|
||||
.morphisms
|
||||
.add_morphism(
|
||||
morphtype,
|
||||
{
|
||||
let ctx = ctx.clone();
|
||||
move |rt, σ| {
|
||||
let radix =
|
||||
match σ.get( &laddertypes::TypeID::Var(ctx.read().unwrap().get_var_typeid("Radix").unwrap()) ) {
|
||||
Some(TypeTerm::Num(n)) => *n as u32,
|
||||
_ => 0
|
||||
};
|
||||
|
||||
/* Create EditTree object
|
||||
*/
|
||||
let mut edittree_digit = DigitEditor::new(
|
||||
ctx.clone(),
|
||||
radix
|
||||
).into_node(
|
||||
r3vi::buffer::singleton::SingletonBuffer::<usize>::new(0).get_port()
|
||||
);
|
||||
|
||||
/* Insert EditTree into ReprTree
|
||||
*/
|
||||
let mut rt = rt.write().unwrap();
|
||||
rt.insert_leaf(
|
||||
vec![ Context::parse(&ctx, "EditTree") ].into_iter(),
|
||||
SingletonBuffer::new( Arc::new(RwLock::new(edittree_digit)) ).get_port().into()
|
||||
);
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
//<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>>
|
||||
|
||||
pub struct DigitEditor {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use {
|
||||
r3vi::{view::{OuterViewPort, singleton::*}},
|
||||
r3vi::{view::{OuterViewPort, singleton::*}, buffer::singleton::*},
|
||||
laddertypes::{TypeTerm},
|
||||
crate::{
|
||||
repr_tree::{Context},
|
||||
|
@ -10,10 +10,43 @@ use {
|
|||
|
||||
//<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>>
|
||||
|
||||
pub fn init_ctx(ctx: &mut Context) {
|
||||
pub fn init_ctx(ctx: Arc<RwLock<Context>>) {
|
||||
|
||||
ctx.write().unwrap().add_varname("Item");
|
||||
let mt = crate::repr_tree::MorphismType {
|
||||
src_type: Context::parse(&ctx, "<List Item>"),
|
||||
dst_type: Context::parse(&ctx, "<List Item>~EditTree")
|
||||
};
|
||||
ctx.write().unwrap().morphisms.add_morphism(
|
||||
mt,
|
||||
{
|
||||
let ctx = ctx.clone();
|
||||
move |rt, σ| {
|
||||
let item_id = laddertypes::TypeID::Var( ctx.read().unwrap().get_var_typeid("Item").unwrap() );
|
||||
if let Some( item_type ) = σ.get( &item_id ) {
|
||||
eprintln!("create list of {:?}", item_type);
|
||||
let mut edittree_list = ListEditor::new(
|
||||
ctx.clone(),
|
||||
item_type.clone()
|
||||
).into_node(
|
||||
r3vi::buffer::singleton::SingletonBuffer::<usize>::new(0).get_port()
|
||||
);
|
||||
|
||||
let mut rt = rt.write().unwrap();
|
||||
rt.insert_leaf(
|
||||
vec![ Context::parse(&ctx, "EditTree") ].into_iter(),
|
||||
SingletonBuffer::new( Arc::new(RwLock::new( edittree_list )) ).get_port().into()
|
||||
);
|
||||
} else {
|
||||
eprintln!("no item type");
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
/*
|
||||
|
||||
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>>| {
|
||||
|
|
|
@ -61,21 +61,21 @@ pub fn edittree_make_digit_view(
|
|||
|
||||
node
|
||||
}
|
||||
|
||||
/*
|
||||
pub fn node_make_seq_view(
|
||||
mut node: NestedNode
|
||||
) -> NestedNode {
|
||||
pub fn edittree_make_seq_view(
|
||||
mut node: EditTree
|
||||
) -> EditTree {
|
||||
node.disp.view
|
||||
.write().unwrap()
|
||||
.insert_branch(ReprTree::new_leaf(
|
||||
Context::parse(&node.ctx, "TerminalView"),
|
||||
node.data
|
||||
.read()
|
||||
node.get_edit::< nested::editors::list::ListEditor >()
|
||||
.unwrap()
|
||||
.get_port::<dyn SequenceView<Item = NestedNode>>()
|
||||
.expect("unable to get Seq-view")
|
||||
.map(move |char_node| node_make_tty_view(char_node.clone()).display_view() )
|
||||
.read().unwrap()
|
||||
.get_data_port()
|
||||
.map(move |item_edittree|
|
||||
edittree_make_tty_view( item_edittree ).display_view()
|
||||
)
|
||||
.wrap(make_label("("), make_label(")"))
|
||||
.to_grid_horizontal()
|
||||
.flatten()
|
||||
|
@ -83,24 +83,25 @@ pub fn node_make_seq_view(
|
|||
));
|
||||
node
|
||||
}
|
||||
*/
|
||||
|
||||
pub fn node_make_list_edit(
|
||||
mut node: NestedNode
|
||||
) -> NestedNode {
|
||||
pub fn edittree_make_list_edit(
|
||||
mut node: EditTree
|
||||
) -> EditTree {
|
||||
list::PTYListStyle::for_node( &mut node, ("(", "", ")") );
|
||||
list::PTYListController::for_node( &mut node, None, None );
|
||||
|
||||
node
|
||||
}
|
||||
|
||||
pub fn node_make_tty_view(
|
||||
node: NestedNode
|
||||
) -> NestedNode {
|
||||
if node.data.read().unwrap().get_type() == &Context::parse(&node.ctx, "Char") {
|
||||
/*
|
||||
pub fn edittree_make_tty_view(
|
||||
et: EditTree
|
||||
) -> EditTree {
|
||||
if et.data.read().unwrap().get_type() == &Context::parse(&node.ctx, "Char") {
|
||||
node_make_char_view( node )
|
||||
} else if node.data.read().unwrap().get_type() == &Context::parse(&node.ctx, "<Seq Char>") {
|
||||
} else if et.data.read().unwrap().get_type() == &Context::parse(&node.ctx, "<Seq Char>") {
|
||||
node_make_seq_view( node )
|
||||
} else if node.data.read().unwrap().get_type() == &Context::parse(&node.ctx, "<List Char>") {
|
||||
} else if et.data.read().unwrap().get_type() == &Context::parse(&node.ctx, "<List Char>") {
|
||||
node_make_list_edit( node )
|
||||
} else {
|
||||
eprintln!("couldnt add view");
|
||||
|
|
|
@ -56,10 +56,10 @@ impl DisplaySegment for nested::edit_tree::EditTree {
|
|||
}
|
||||
|
||||
else {
|
||||
make_label("?")
|
||||
make_label("# could not get ViewPort #")
|
||||
}
|
||||
} else {
|
||||
make_label("?")
|
||||
make_label("# No TTY View available #")
|
||||
.map_item(|_p,a| a.add_style_back(TerminalStyle::fg_color((220, 30, 30))))
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue