add notes, formatting, shallow simplifications
This commit is contained in:
parent
73d457ba24
commit
77d9e64531
8 changed files with 69 additions and 69 deletions
|
@ -40,26 +40,31 @@ async fn main() {
|
|||
|
||||
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.
|
||||
// It provides the necessary bridge to the rendering- & input-backend.
|
||||
ctx.write().unwrap().set_edittree_hook(
|
||||
Arc::new(
|
||||
move |et: Arc<RwLock<EditTree>>, t: laddertypes::TypeTerm| {
|
||||
let mut et = et.write().unwrap();
|
||||
|
||||
if let Ok(σ) = laddertypes::unify(&t, &char_type.clone()) {
|
||||
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, &posint_type) {
|
||||
let mut et = et.write().unwrap();
|
||||
nested_tty::editors::list::PTYListStyle::for_node( &mut *et, ("0d", "", ""));
|
||||
nested_tty::editors::list::PTYListController::for_node( &mut *et, None, None );
|
||||
}
|
||||
else if let Ok(σ) = laddertypes::unify(&t, &list_type) {
|
||||
let mut et = et.write().unwrap();
|
||||
let item_type = σ.get( &laddertypes::TypeID::Var(item_tyid) ).unwrap();
|
||||
if item_type == &char_type {
|
||||
|
||||
// choose style based on element type
|
||||
if *item_type == char_type {
|
||||
nested_tty::editors::list::PTYListStyle::for_node( &mut *et, ("\"", "", "\""));
|
||||
nested_tty::editors::list::PTYListController::for_node( &mut *et, None, Some('\"') );
|
||||
} else {
|
||||
|
@ -97,16 +102,23 @@ async fn main() {
|
|||
rt_digit.write().unwrap()
|
||||
.insert_leaf(
|
||||
vec![ Context::parse(&ctx, "Char") ].into_iter(),
|
||||
SingletonBuffer::new('x').get_port().into()
|
||||
SingletonBuffer::new('4').get_port().into()
|
||||
);
|
||||
|
||||
/* 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 edittree_digit = ctx.read().unwrap()
|
||||
.setup_edittree(
|
||||
rt_digit
|
||||
.read().unwrap()
|
||||
.descend( Context::parse(&ctx, "Char") ).unwrap()
|
||||
.clone(),
|
||||
r3vi::buffer::singleton::SingletonBuffer::new(0).get_port());
|
||||
|
||||
//---
|
||||
let rt_string = ReprTree::new_arc( Context::parse(&ctx, "<List <List Char>>") );
|
||||
let edittree = ctx.read().unwrap().setup_edittree(rt_string.clone(), r3vi::buffer::singleton::SingletonBuffer::new(0).get_port());
|
||||
let rt_string = ReprTree::new_arc( Context::parse(&ctx, "<List <Digit 10>>") );
|
||||
let edittree = ctx.read().unwrap()
|
||||
.setup_edittree(rt_string.clone(), r3vi::buffer::singleton::SingletonBuffer::new(0).get_port());
|
||||
|
||||
/* setup terminal
|
||||
*/
|
||||
|
@ -125,28 +137,39 @@ async fn main() {
|
|||
let compositor = TerminalCompositor::new(app.port.inner());
|
||||
|
||||
// add some views to the display compositor
|
||||
compositor.write().unwrap().push(
|
||||
nested_tty::make_label("Hello World")
|
||||
.map_item(|p, a| {
|
||||
a.add_style_back(TerminalStyle::fg_color(((25 * p.x % 255) as u8, 200, 0)))
|
||||
})
|
||||
.offset(Vector2::new(5, 0)),
|
||||
);
|
||||
compositor.write().unwrap().push( edittree_digit.read().unwrap().display_view().offset(Vector2::new(0,2)) );
|
||||
{
|
||||
let mut comp = compositor.write().unwrap();
|
||||
|
||||
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)));
|
||||
comp.push(
|
||||
nested_tty::make_label("Hello World")
|
||||
.map_item(|p, a| {
|
||||
a.add_style_back(TerminalStyle::fg_color(((25 * p.x % 255) as u8, 200, 0)))
|
||||
})
|
||||
.offset(Vector2::new(5, 0)),
|
||||
);
|
||||
|
||||
compositor.write().unwrap().push( edittree.read().unwrap().display_view().offset(Vector2::new(0,4)) );
|
||||
comp.push(
|
||||
edittree_digit.read().unwrap().display_view()
|
||||
.offset(Vector2::new(0,2))
|
||||
);
|
||||
|
||||
let label = ctx.read().unwrap().type_term_to_str(&rt_string.read().unwrap().get_type());
|
||||
compositor
|
||||
.write()
|
||||
.unwrap()
|
||||
.push(nested_tty::make_label(&label).offset(Vector2::new(0, 3)));
|
||||
let label_str = ctx.read().unwrap().type_term_to_str(&rt_digit.read().unwrap().get_type());
|
||||
comp.push(
|
||||
nested_tty::make_label(&label_str)
|
||||
.offset(Vector2::new(0, 1))
|
||||
);
|
||||
|
||||
comp.push(
|
||||
edittree.read().unwrap().display_view()
|
||||
.offset(Vector2::new(0,4))
|
||||
);
|
||||
|
||||
let label_str = ctx.read().unwrap().type_term_to_str(&rt_string.read().unwrap().get_type());
|
||||
comp.push(
|
||||
nested_tty::make_label(&label_str)
|
||||
.offset(Vector2::new(0, 3))
|
||||
);
|
||||
}
|
||||
|
||||
/* write the changes in the view of `term_port` to the terminal
|
||||
*/
|
||||
|
|
|
@ -38,7 +38,7 @@ pub enum TreeNavCmd {
|
|||
|
||||
pub trait TreeNav {
|
||||
/* CORE
|
||||
*/
|
||||
*/
|
||||
fn get_cursor(&self) -> TreeCursor {
|
||||
TreeCursor::default()
|
||||
}
|
||||
|
|
|
@ -32,7 +32,9 @@ pub struct EdittreeControl {
|
|||
Option< Arc<dyn Any + Send + Sync> >
|
||||
>,
|
||||
|
||||
pub spillbuf: Arc<RwLock< Vec< Arc<RwLock< EditTree >> > >>,
|
||||
pub spillbuf: Arc<RwLock<
|
||||
Vec< Arc<RwLock< EditTree >> >
|
||||
>>,
|
||||
|
||||
/// commander & navigation
|
||||
pub cmd: SingletonBuffer<
|
||||
|
@ -47,9 +49,6 @@ pub struct EdittreeControl {
|
|||
>,
|
||||
}
|
||||
|
||||
/*
|
||||
* TODO: rename to EditNode
|
||||
*/
|
||||
#[derive(Clone)]
|
||||
pub struct EditTree {
|
||||
/// context
|
||||
|
|
|
@ -31,10 +31,15 @@ pub fn init_ctx( ctx: Arc<RwLock<Context>> ) {
|
|||
{
|
||||
let ctx = ctx.clone();
|
||||
move |rt, σ| {
|
||||
if let Some(v) = rt.read().unwrap().get_view::<dyn SingletonView<Item = char>>() {
|
||||
eprintln!("prev value: {}", v.get());
|
||||
}
|
||||
|
||||
/* Create EditTree object
|
||||
*/
|
||||
let mut edittree_char = CharEditor::new_edit_tree(
|
||||
ctx.clone(),
|
||||
SingletonBuffer::new('>'),
|
||||
r3vi::buffer::singleton::SingletonBuffer::<usize>::new(0).get_port()
|
||||
);
|
||||
|
||||
|
@ -97,6 +102,7 @@ impl CharEditor {
|
|||
|
||||
pub fn new_edit_tree(
|
||||
ctx0: Arc<RwLock<Context>>,
|
||||
data: SingletonBuffer<char>,
|
||||
depth: OuterViewPort<dyn SingletonView<Item = usize>>
|
||||
) -> EditTree {
|
||||
let data = SingletonBuffer::new('\0');
|
||||
|
|
|
@ -185,39 +185,6 @@ pub struct PosIntEditor {
|
|||
|
||||
impl PosIntEditor {
|
||||
pub fn new(ctx: Arc<RwLock<Context>>, radix: u32) -> Self {
|
||||
/*
|
||||
let mut node = Context::make_node(
|
||||
&ctx,
|
||||
Context::parse(&ctx, format!("<List <Digit {}>>", radix).as_str()),
|
||||
r3vi::buffer::singleton::SingletonBuffer::new(0).get_port()
|
||||
).unwrap();
|
||||
|
||||
// Set Type
|
||||
node.data = ReprTree::ascend(
|
||||
&node.data.clone(),
|
||||
TypeTerm::App(vec![
|
||||
TypeTerm::TypeID(ctx.read().unwrap().get_typeid("PosInt").unwrap()),
|
||||
TypeTerm::Num(radix as i64).into(),
|
||||
TypeTerm::TypeID(ctx.read().unwrap().get_typeid("BigEndian").unwrap())
|
||||
]
|
||||
));
|
||||
*/
|
||||
/*
|
||||
PTYListController::for_node( &mut node, Some(' '), None );
|
||||
PTYListStyle::for_node( &mut node,
|
||||
(
|
||||
match radix {
|
||||
2 => "0b".into(),
|
||||
8 => "0o".into(),
|
||||
10 => "0d".into(),
|
||||
16 => "0x".into(),
|
||||
_ => "".into()
|
||||
},
|
||||
"".into(),
|
||||
"".into()
|
||||
)
|
||||
);
|
||||
*/
|
||||
PosIntEditor {
|
||||
radix,
|
||||
digits: EditTree::new(
|
||||
|
|
|
@ -22,6 +22,7 @@ pub enum ListCmd {
|
|||
}
|
||||
|
||||
impl ListCmd {
|
||||
// note: cant use Into becaue of ctx (maybe global typedict?)
|
||||
pub fn into_repr_tree(self, ctx: &Arc<RwLock<Context>>) -> Arc<RwLock<ReprTree>> {
|
||||
let buf = r3vi::buffer::singleton::SingletonBuffer::new(self);
|
||||
ReprTree::new_leaf(
|
||||
|
|
|
@ -24,6 +24,8 @@ pub struct ReprTree {
|
|||
branches: HashMap<TypeTerm, Arc<RwLock<ReprTree>>>,
|
||||
}
|
||||
|
||||
//<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>>
|
||||
|
||||
impl std::fmt::Debug for ReprTree {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
writeln!(f, "| type: {:?}", self.type_tag)?;
|
||||
|
@ -36,6 +38,8 @@ impl std::fmt::Debug for ReprTree {
|
|||
}
|
||||
}
|
||||
|
||||
//<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>>
|
||||
|
||||
impl ReprTree {
|
||||
pub fn new(type_tag: impl Into<TypeTerm>) -> Self {
|
||||
ReprTree {
|
||||
|
|
|
@ -190,15 +190,15 @@ impl PTYListController {
|
|||
}
|
||||
|
||||
pub fn handle_meta_char(&mut self, c: char, child_close_char: Option<char>) -> TreeNavResult {
|
||||
eprintln!("handle meta char: got '{}', child_close={:?}, self.close={:?}, split={:?}", c, child_close_char, self.close_char, self.split_char);
|
||||
// eprintln!("handle meta char: got '{}', child_close={:?}, self.close={:?}, split={:?}", c, child_close_char, self.close_char, self.split_char);
|
||||
let mut e = self.editor.write().unwrap();
|
||||
let cur = e.cursor.get();
|
||||
|
||||
|
||||
if Some(c) == self.split_char
|
||||
// || Some(c) == child_close_char
|
||||
{
|
||||
e.listlist_split();
|
||||
eprintln!("done listlist split");
|
||||
// eprintln!("done listlist split");
|
||||
TreeNavResult::Continue
|
||||
} else if Some(c) == child_close_char {
|
||||
e.goto(TreeCursor::none());
|
||||
|
|
Loading…
Reference in a new issue