tty backend: hooks to setup display for binary, octal, decimal \& hex notations of PosInt

This commit is contained in:
Michael Sippel 2024-09-02 00:02:38 +02:00
parent 4b7d929abc
commit 9f53b65074
Signed by: senvas
GPG key ID: F96CF119C34B64A6

View file

@ -121,7 +121,10 @@ pub fn setup_edittree_hook(ctx: &Arc<RwLock<Context>>) {
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 posint_bin_type = Context::parse(&ctx, "<PosInt 2 BigEndian>");
let posint_oct_type = Context::parse(&ctx, "<PosInt 8 BigEndian>");
let posint_dec_type = Context::parse(&ctx, "<PosInt 10 BigEndian>");
let posint_hex_type = Context::parse(&ctx, "<PosInt 16 BigEndian>");
let item_tyid = ctx.read().unwrap().get_var_typeid("Item").unwrap(); let item_tyid = ctx.read().unwrap().get_var_typeid("Item").unwrap();
ctx.write().unwrap().meta_chars.push(','); ctx.write().unwrap().meta_chars.push(',');
@ -134,18 +137,28 @@ pub fn setup_edittree_hook(ctx: &Arc<RwLock<Context>>) {
ctx.write().unwrap().set_edittree_hook( ctx.write().unwrap().set_edittree_hook(
Arc::new( Arc::new(
move |et: &mut nested::edit_tree::EditTree, t: laddertypes::TypeTerm| { move |et: &mut nested::edit_tree::EditTree, t: laddertypes::TypeTerm| {
// let mut et = et.write().unwrap();
if let Ok(σ) = laddertypes::unify(&t, &char_type.clone()) { if let Ok(σ) = laddertypes::unify(&t, &char_type.clone()) {
*et = crate::editors::edittree_make_char_view(et.clone()); *et = crate::editors::edittree_make_char_view(et.clone());
} }
else if let Ok(σ) = laddertypes::unify(&t, &digit_type) { else if let Ok(σ) = laddertypes::unify(&t, &digit_type) {
*et = crate::editors::edittree_make_digit_view(et.clone()); *et = crate::editors::edittree_make_digit_view(et.clone());
} }
else if let Ok(σ) = laddertypes::unify(&t, &posint_type) { else if let Ok(σ) = laddertypes::unify(&t, &posint_bin_type) {
crate::editors::list::PTYListStyle::for_node( &mut *et, ("0b", "", ""));
crate::editors::list::PTYListController::for_node( &mut *et, None, None );
}
else if let Ok(σ) = laddertypes::unify(&t, &posint_oct_type) {
crate::editors::list::PTYListStyle::for_node( &mut *et, ("0o", "", ""));
crate::editors::list::PTYListController::for_node( &mut *et, None, None );
}
else if let Ok(σ) = laddertypes::unify(&t, &posint_dec_type) {
crate::editors::list::PTYListStyle::for_node( &mut *et, ("0d", "", "")); crate::editors::list::PTYListStyle::for_node( &mut *et, ("0d", "", ""));
crate::editors::list::PTYListController::for_node( &mut *et, None, None ); crate::editors::list::PTYListController::for_node( &mut *et, None, None );
} }
else if let Ok(σ) = laddertypes::unify(&t, &posint_hex_type) {
crate::editors::list::PTYListStyle::for_node( &mut *et, ("0x", "", ""));
crate::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 item_type = σ.get( &laddertypes::TypeID::Var(item_tyid) ).unwrap(); let item_type = σ.get( &laddertypes::TypeID::Var(item_tyid) ).unwrap();