test different style for <List Char>, add meta-chars to ctx globally to avoid deadlock

This commit is contained in:
Michael Sippel 2024-01-18 17:16:20 +01:00
parent 0ac4a34743
commit e46c143dec
Signed by: senvas
GPG key ID: F96CF119C34B64A6
5 changed files with 27 additions and 36 deletions

View file

@ -32,15 +32,18 @@ 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 char_type = Context::parse(&ctx, "Char");
let digit_type = Context::parse(&ctx, "<Digit Radix>"); let digit_type = Context::parse(&ctx, "<Digit Radix>");
let list_type = Context::parse(&ctx, "<List Item>"); let list_type = Context::parse(&ctx, "<List Item>");
let posint_type = Context::parse(&ctx, "<PosInt Radix>");
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().set_edittree_hook( ctx.write().unwrap().set_edittree_hook(
Arc::new( Arc::new(
move |et: Arc<RwLock<EditTree>>, t: laddertypes::TypeTerm| { move |et: Arc<RwLock<EditTree>>, t: laddertypes::TypeTerm| {
if let Ok(σ) = laddertypes::unify(&t, &char_type) { if let Ok(σ) = laddertypes::unify(&t, &char_type.clone()) {
let mut et = et.write().unwrap(); let mut et = et.write().unwrap();
*et = nested_tty::editors::edittree_make_char_view(et.clone()); *et = nested_tty::editors::edittree_make_char_view(et.clone());
} }
@ -48,11 +51,22 @@ async fn main() {
let mut et = et.write().unwrap(); let mut et = et.write().unwrap();
*et = nested_tty::editors::edittree_make_digit_view(et.clone()); *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) { else if let Ok(σ) = laddertypes::unify(&t, &list_type) {
let mut et = et.write().unwrap(); let mut et = et.write().unwrap();
nested_tty::editors::list::PTYListStyle::for_node( &mut *et, ("(", ",", ")")); let item_type = σ.get( &laddertypes::TypeID::Var(item_tyid) ).unwrap();
nested_tty::editors::list::PTYListController::for_node( &mut *et, None, None ); if item_type == &char_type {
*et = nested_tty::editors::edittree_make_list_edit(et.clone()); nested_tty::editors::list::PTYListStyle::for_node( &mut *et, ("\"", "", "\""));
nested_tty::editors::list::PTYListController::for_node( &mut *et, None, Some('\"') );
} else {
nested_tty::editors::list::PTYListStyle::for_node( &mut *et, ("{", ", ", "}"));
nested_tty::editors::list::PTYListController::for_node( &mut *et, Some(','), Some('}') );
}
//*et = nested_tty::editors::edittree_make_list_edit(et.clone());
} }
} }
) )
@ -91,7 +105,7 @@ async fn main() {
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.clone(), r3vi::buffer::singleton::SingletonBuffer::new(0).get_port());
//--- //---
let rt_string = ReprTree::new_arc( Context::parse(&ctx, "<List <List <Digit 16>>>") ); 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 edittree = ctx.read().unwrap().setup_edittree(rt_string.clone(), r3vi::buffer::singleton::SingletonBuffer::new(0).get_port());
/* setup terminal /* setup terminal

View file

@ -175,7 +175,7 @@ impl ListEditor {
} else { } else {
None None
} }
} }
pub fn get_item_mut(&mut self) -> Option<MutableVecAccess<Arc<RwLock<EditTree>>>> { pub fn get_item_mut(&mut self) -> Option<MutableVecAccess<Arc<RwLock<EditTree>>>> {
if let Some(idx) = self.cursor.get().idx { if let Some(idx) = self.cursor.get().idx {

View file

@ -139,7 +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();
@ -151,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() )));

View file

@ -61,6 +61,7 @@ pub fn edittree_make_digit_view(
node node
} }
/* /*
pub fn edittree_make_seq_view( pub fn edittree_make_seq_view(
mut node: EditTree mut node: EditTree
@ -84,27 +85,3 @@ pub fn edittree_make_seq_view(
node node
} }
*/ */
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 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 et.data.read().unwrap().get_type() == &Context::parse(&node.ctx, "<Seq Char>") {
node_make_seq_view( node )
} else if et.data.read().unwrap().get_type() == &Context::parse(&node.ctx, "<List Char>") {
node_make_list_edit( node )
} else {
eprintln!("couldnt add view");
node
}
}
*/