From 9f53b65074d7f5e653ea23534339f24cf7d9b5fe Mon Sep 17 00:00:00 2001 From: Michael Sippel Date: Mon, 2 Sep 2024 00:02:38 +0200 Subject: [PATCH] tty backend: hooks to setup display for binary, octal, decimal \& hex notations of PosInt --- lib-nested-tty/src/lib.rs | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/lib-nested-tty/src/lib.rs b/lib-nested-tty/src/lib.rs index 2bc1138..0e12095 100644 --- a/lib-nested-tty/src/lib.rs +++ b/lib-nested-tty/src/lib.rs @@ -121,7 +121,10 @@ pub fn setup_edittree_hook(ctx: &Arc>) { let char_type = Context::parse(&ctx, "Char"); let digit_type = Context::parse(&ctx, ""); let list_type = Context::parse(&ctx, ""); - let posint_type = Context::parse(&ctx, ""); + let posint_bin_type = Context::parse(&ctx, ""); + let posint_oct_type = Context::parse(&ctx, ""); + let posint_dec_type = Context::parse(&ctx, ""); + let posint_hex_type = Context::parse(&ctx, ""); let item_tyid = ctx.read().unwrap().get_var_typeid("Item").unwrap(); ctx.write().unwrap().meta_chars.push(','); @@ -134,18 +137,28 @@ pub fn setup_edittree_hook(ctx: &Arc>) { ctx.write().unwrap().set_edittree_hook( Arc::new( 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()) { *et = crate::editors::edittree_make_char_view(et.clone()); } else if let Ok(σ) = laddertypes::unify(&t, &digit_type) { *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::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) { let item_type = σ.get( &laddertypes::TypeID::Var(item_tyid) ).unwrap();