2024-05-25 00:39:47 +02:00
|
|
|
|
//! In the following example, a <List Char> editor
|
|
|
|
|
//! as before is used, but its data is morphed into
|
|
|
|
|
//! representing a positional integer which is then
|
|
|
|
|
//! projected into different radices and displayed
|
|
|
|
|
//! in different views on screen
|
|
|
|
|
|
|
|
|
|
extern crate cgmath;
|
|
|
|
|
extern crate nested;
|
|
|
|
|
extern crate nested_tty;
|
|
|
|
|
extern crate r3vi;
|
|
|
|
|
extern crate termion;
|
|
|
|
|
|
|
|
|
|
use {
|
|
|
|
|
cgmath::Vector2,
|
|
|
|
|
nested::{
|
|
|
|
|
editors::{
|
|
|
|
|
ObjCommander
|
|
|
|
|
},
|
|
|
|
|
repr_tree::{Context, ReprTree, ReprTreeExt, ReprLeaf},
|
2024-06-03 17:02:08 +02:00
|
|
|
|
edit_tree::{EditTree, TreeNav, TreeCursor}
|
2024-05-25 00:39:47 +02:00
|
|
|
|
},
|
|
|
|
|
nested_tty::{
|
|
|
|
|
DisplaySegment, TTYApplication,
|
|
|
|
|
TerminalCompositor, TerminalStyle, TerminalView,
|
|
|
|
|
TerminalAtom, TerminalEvent
|
|
|
|
|
},
|
|
|
|
|
r3vi::{
|
|
|
|
|
buffer::{singleton::*, vec::*},
|
2024-06-03 17:02:08 +02:00
|
|
|
|
view::{port::UpdateTask, singleton::*, list::*, sequence::*},
|
2024-05-25 00:39:47 +02:00
|
|
|
|
projection::*
|
|
|
|
|
},
|
|
|
|
|
std::sync::{Arc, RwLock},
|
|
|
|
|
};
|
|
|
|
|
|
2024-07-21 18:16:43 +02:00
|
|
|
|
fn rebuild_projections(
|
|
|
|
|
ctx: Arc<RwLock<Context>>,
|
|
|
|
|
repr_tree: Arc<RwLock<ReprTree>>,
|
|
|
|
|
morph_types: Vec< (laddertypes::TypeTerm, laddertypes::TypeTerm) >
|
|
|
|
|
) {
|
2024-08-02 21:58:07 +02:00
|
|
|
|
repr_tree.write().unwrap().detach(&ctx);
|
2024-07-21 18:16:43 +02:00
|
|
|
|
for (src_type, dst_type) in morph_types.iter() {
|
|
|
|
|
ctx.read().unwrap().morphisms.apply_morphism(
|
|
|
|
|
repr_tree.clone(),
|
|
|
|
|
&src_type,
|
|
|
|
|
&dst_type
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-05-25 00:39:47 +02:00
|
|
|
|
|
2024-08-02 22:43:00 +02:00
|
|
|
|
fn setup_hex_master(ctx: &Arc<RwLock<Context>>, rt_int: &Arc<RwLock<ReprTree>>) {
|
2024-07-21 18:16:43 +02:00
|
|
|
|
rebuild_projections(
|
|
|
|
|
ctx.clone(),
|
|
|
|
|
rt_int.clone(),
|
|
|
|
|
vec![
|
2024-08-02 22:43:00 +02:00
|
|
|
|
// extract values from hex-editor
|
2024-07-21 18:16:43 +02:00
|
|
|
|
(
|
2024-08-02 22:43:00 +02:00
|
|
|
|
"ℕ ~ <PosInt 16 BigEndian> ~ <Seq <Digit 16>> ~ <List <Digit 16> ~ Char> ~ EditTree",
|
2024-07-21 18:16:43 +02:00
|
|
|
|
"ℕ ~ <PosInt 16 BigEndian> ~ <Seq <Digit 16>> ~ <List <Digit 16> ~ Char>"
|
|
|
|
|
),
|
|
|
|
|
|
2024-08-02 22:43:00 +02:00
|
|
|
|
// convert to little-endian
|
2024-07-21 18:16:43 +02:00
|
|
|
|
(
|
|
|
|
|
"ℕ ~ <PosInt 16 BigEndian> ~ <Seq <Digit 16>> ~ <List <Digit 16> ~ Char>",
|
2024-08-02 22:43:00 +02:00
|
|
|
|
"ℕ ~ <PosInt 16 LittleEndian> ~ <Seq <Digit 16>> ~ <List <Digit 16> ~ Char>"
|
2024-07-21 18:16:43 +02:00
|
|
|
|
),
|
2024-08-02 22:43:00 +02:00
|
|
|
|
// convert digit representation from char to u64
|
2024-07-21 18:16:43 +02:00
|
|
|
|
(
|
2024-08-02 22:43:00 +02:00
|
|
|
|
"ℕ ~ <PosInt 16 LittleEndian> ~ <Seq <Digit 16>> ~ <List <Digit 16> ~ Char>",
|
|
|
|
|
"ℕ ~ <PosInt 16 LittleEndian> ~ <Seq <Digit 16>> ~ <List <Digit 16> ~ ℤ_2^64 ~ machine.UInt64>"
|
2024-07-21 18:16:43 +02:00
|
|
|
|
),
|
2024-08-02 22:43:00 +02:00
|
|
|
|
// convert radix to decimal
|
2024-07-21 18:16:43 +02:00
|
|
|
|
(
|
2024-08-02 22:43:00 +02:00
|
|
|
|
"ℕ ~ <PosInt 16 LittleEndian> ~ <Seq <Digit 16>> ~ <List <Digit 16> ~ ℤ_2^64 ~ machine.UInt64>",
|
|
|
|
|
"ℕ ~ <PosInt 10 LittleEndian> ~ <Seq <Digit 10>> ~ <List <Digit 10> ~ ℤ_2^64 ~ machine.UInt64>"
|
|
|
|
|
),
|
|
|
|
|
// convert decimal digit representation back to char
|
|
|
|
|
(
|
|
|
|
|
"ℕ ~ <PosInt 10 LittleEndian> ~ <Seq <Digit 10>> ~ <List <Digit 10> ~ ℤ_2^64 ~ machine.UInt64>",
|
|
|
|
|
"ℕ ~ <PosInt 10 LittleEndian> ~ <Seq <Digit 10>> ~ <List <Digit 10> ~ Char>"
|
|
|
|
|
),
|
|
|
|
|
// convert to big-endian
|
|
|
|
|
(
|
|
|
|
|
"ℕ ~ <PosInt 10 LittleEndian> ~ <Seq <Digit 10>> ~ <List <Digit 10> ~ Char>",
|
|
|
|
|
"ℕ ~ <PosInt 10 BigEndian> ~ <Seq <Digit 10>> ~ <List <Digit 10> ~ Char>"
|
2024-07-21 18:16:43 +02:00
|
|
|
|
),
|
2024-06-03 17:02:08 +02:00
|
|
|
|
|
2024-08-02 22:43:00 +02:00
|
|
|
|
// decimal editor
|
2024-08-02 21:58:07 +02:00
|
|
|
|
(
|
2024-08-02 22:43:00 +02:00
|
|
|
|
"ℕ ~ <PosInt 10 BigEndian> ~ <Seq <Digit 10>> ~ <List <Digit 10> ~ Char>",
|
|
|
|
|
"ℕ ~ <PosInt 10 BigEndian> ~ <Seq <Digit 10>> ~ <List <Digit 10> ~ Char ~ EditTree>"
|
2024-08-02 21:58:07 +02:00
|
|
|
|
),
|
2024-08-01 18:35:57 +02:00
|
|
|
|
(
|
2024-08-02 22:43:00 +02:00
|
|
|
|
"ℕ ~ <PosInt 10 BigEndian> ~ <Seq <Digit 10>> ~ <List <Digit 10> ~ Char ~ EditTree>",
|
|
|
|
|
"ℕ ~ <PosInt 10 BigEndian> ~ <Seq <Digit 10>> ~ <List <Digit 10> ~ Char ~ EditTree> ~ <Vec EditTree>"
|
2024-08-02 21:58:07 +02:00
|
|
|
|
),
|
2024-08-02 22:43:00 +02:00
|
|
|
|
(
|
|
|
|
|
"ℕ ~ <PosInt 10 BigEndian> ~ <Seq <Digit 10>> ~ <List <Digit 10> ~ Char ~ EditTree> ~ <Vec EditTree>",
|
|
|
|
|
"ℕ ~ <PosInt 10 BigEndian> ~ <Seq <Digit 10>> ~ <List <Digit 10> ~ Char> ~ EditTree"
|
|
|
|
|
),
|
|
|
|
|
|
2024-08-01 18:35:57 +02:00
|
|
|
|
].into_iter()
|
|
|
|
|
.map(|(s,d)| (Context::parse(&ctx, s), Context::parse(&ctx, d)))
|
|
|
|
|
.collect()
|
2024-06-03 17:02:08 +02:00
|
|
|
|
);
|
2024-07-21 18:16:43 +02:00
|
|
|
|
}
|
2024-06-03 17:02:08 +02:00
|
|
|
|
|
2024-08-02 22:43:00 +02:00
|
|
|
|
fn setup_dec_master(ctx: &Arc<RwLock<Context>>, rt_int: &Arc<RwLock<ReprTree>>) {
|
2024-07-21 18:16:43 +02:00
|
|
|
|
rebuild_projections(
|
|
|
|
|
ctx.clone(),
|
|
|
|
|
rt_int.clone(),
|
|
|
|
|
vec![
|
2024-08-02 22:43:00 +02:00
|
|
|
|
// extract values from decimal-editor
|
2024-07-21 18:16:43 +02:00
|
|
|
|
(
|
2024-08-02 22:43:00 +02:00
|
|
|
|
"ℕ ~ <PosInt 10 BigEndian> ~ <Seq <Digit 10>> ~ <List <Digit 10> ~ Char> ~ EditTree",
|
|
|
|
|
"ℕ ~ <PosInt 10 BigEndian> ~ <Seq <Digit 10>> ~ <List <Digit 10> ~ Char>"
|
2024-07-21 18:16:43 +02:00
|
|
|
|
),
|
|
|
|
|
|
2024-08-02 22:43:00 +02:00
|
|
|
|
// convert to little-endian
|
2024-07-21 18:16:43 +02:00
|
|
|
|
(
|
2024-08-02 22:43:00 +02:00
|
|
|
|
"ℕ ~ <PosInt 10 BigEndian> ~ <Seq <Digit 10>> ~ <List <Digit 10> ~ Char>",
|
|
|
|
|
"ℕ ~ <PosInt 10 LittleEndian> ~ <Seq <Digit 10>> ~ <List <Digit 10> ~ Char>"
|
2024-07-21 18:16:43 +02:00
|
|
|
|
),
|
2024-08-02 22:43:00 +02:00
|
|
|
|
// convert digit representation to u64
|
2024-07-21 18:16:43 +02:00
|
|
|
|
(
|
2024-08-02 22:43:00 +02:00
|
|
|
|
"ℕ ~ <PosInt 10 LittleEndian> ~ <Seq <Digit 10>> ~ <List <Digit 10> ~ Char>",
|
|
|
|
|
"ℕ ~ <PosInt 10 LittleEndian> ~ <Seq <Digit 10>> ~ <List <Digit 10> ~ ℤ_2^64 ~ machine.UInt64>"
|
2024-07-21 18:16:43 +02:00
|
|
|
|
),
|
2024-08-02 22:43:00 +02:00
|
|
|
|
// convert radix to decimal
|
|
|
|
|
(
|
|
|
|
|
"ℕ ~ <PosInt 10 LittleEndian> ~ <Seq <Digit 10>> ~ <List <Digit 10> ~ ℤ_2^64 ~ machine.UInt64>",
|
|
|
|
|
"ℕ ~ <PosInt 16 LittleEndian> ~ <Seq <Digit 16>> ~ <List <Digit 16> ~ ℤ_2^64 ~ machine.UInt64>"
|
|
|
|
|
),
|
|
|
|
|
// convert back digit representation char
|
2024-07-21 18:16:43 +02:00
|
|
|
|
(
|
2024-08-02 22:43:00 +02:00
|
|
|
|
"ℕ ~ <PosInt 16 LittleEndian> ~ <Seq <Digit 16>> ~ <List <Digit 16> ~ ℤ_2^64 ~ machine.UInt64>",
|
|
|
|
|
"ℕ ~ <PosInt 16 LittleEndian> ~ <Seq <Digit 16>> ~ <List <Digit 16> ~ Char>"
|
2024-07-21 18:16:43 +02:00
|
|
|
|
),
|
2024-08-02 22:43:00 +02:00
|
|
|
|
// convert back to big-endian
|
2024-07-21 18:16:43 +02:00
|
|
|
|
(
|
2024-08-02 22:43:00 +02:00
|
|
|
|
"ℕ ~ <PosInt 16 LittleEndian> ~ <Seq <Digit 16>> ~ <List <Digit 16> ~ Char>",
|
|
|
|
|
"ℕ ~ <PosInt 16 BigEndian> ~ <Seq <Digit 16>> ~ <List <Digit 16> ~ Char>"
|
2024-07-21 18:16:43 +02:00
|
|
|
|
),
|
2024-05-25 19:21:16 +02:00
|
|
|
|
|
2024-08-02 22:43:00 +02:00
|
|
|
|
// hex editor
|
2024-08-02 21:58:07 +02:00
|
|
|
|
(
|
2024-08-02 22:43:00 +02:00
|
|
|
|
"ℕ ~ <PosInt 16 BigEndian> ~ <Seq <Digit 16>> ~ <List <Digit 16> ~ Char>",
|
|
|
|
|
"ℕ ~ <PosInt 16 BigEndian> ~ <Seq <Digit 16>> ~ <List <Digit 16> ~ Char ~ EditTree>"
|
2024-08-02 21:58:07 +02:00
|
|
|
|
),
|
2024-08-01 18:35:57 +02:00
|
|
|
|
(
|
2024-08-02 22:43:00 +02:00
|
|
|
|
"ℕ ~ <PosInt 16 BigEndian> ~ <Seq <Digit 16>> ~ <List <Digit 16> ~ Char ~ EditTree>",
|
|
|
|
|
"ℕ ~ <PosInt 16 BigEndian> ~ <Seq <Digit 16>> ~ <List <Digit 16> ~ Char ~ EditTree> ~ <Vec EditTree>"
|
|
|
|
|
),
|
|
|
|
|
(
|
|
|
|
|
"ℕ ~ <PosInt 16 BigEndian> ~ <Seq <Digit 16>> ~ <List <Digit 16> ~ Char ~ EditTree> ~ <Vec EditTree>",
|
|
|
|
|
"ℕ ~ <PosInt 16 BigEndian> ~ <Seq <Digit 16>> ~ <List <Digit 16> ~ Char> ~ EditTree"
|
|
|
|
|
),
|
2024-08-02 21:58:07 +02:00
|
|
|
|
].into_iter()
|
2024-08-01 18:35:57 +02:00
|
|
|
|
.map(|(s,d)| (Context::parse(&ctx, s), Context::parse(&ctx, d)))
|
|
|
|
|
.collect()
|
2024-05-25 00:39:47 +02:00
|
|
|
|
);
|
2024-07-21 18:16:43 +02:00
|
|
|
|
}
|
2024-05-25 00:39:47 +02:00
|
|
|
|
|
2024-07-21 18:16:43 +02:00
|
|
|
|
#[async_std::main]
|
|
|
|
|
async fn main() {
|
|
|
|
|
/* setup context
|
2024-05-25 19:21:16 +02:00
|
|
|
|
*/
|
2024-07-21 18:16:43 +02:00
|
|
|
|
let ctx = Arc::new(RwLock::new(Context::new()));
|
|
|
|
|
nested::editors::char::init_ctx( ctx.clone() );
|
|
|
|
|
nested::editors::digit::init_ctx( ctx.clone() );
|
|
|
|
|
nested::editors::integer::init_ctx( ctx.clone() );
|
|
|
|
|
nested::editors::list::init_ctx( ctx.clone() );
|
|
|
|
|
nested_tty::setup_edittree_hook(&ctx);
|
|
|
|
|
|
|
|
|
|
/* Create a Representation-Tree of type `ℕ`
|
|
|
|
|
*/
|
|
|
|
|
let mut rt_int = ReprTree::new_arc( Context::parse(&ctx, "ℕ") );
|
|
|
|
|
|
|
|
|
|
/* Add a specific Representation-Path (big-endian hexadecimal)
|
|
|
|
|
*/
|
2024-08-02 22:43:00 +02:00
|
|
|
|
let mut digits_hex = VecBuffer::with_data(vec![ 'c', 'f', 'f' ]);
|
2024-07-21 18:16:43 +02:00
|
|
|
|
rt_int.insert_leaf(
|
|
|
|
|
Context::parse(&ctx, "<PosInt 16 BigEndian>~<Seq <Digit 16>>~<List <Digit 16>>~<List Char>~<Vec Char>"),
|
2024-08-02 22:43:00 +02:00
|
|
|
|
nested::repr_tree::ReprLeaf::from_vec_buffer( digits_hex.clone() )
|
2024-07-21 18:16:43 +02:00
|
|
|
|
);
|
|
|
|
|
|
2024-08-02 22:43:00 +02:00
|
|
|
|
let mut digits_dec = VecBuffer::with_data(vec!['3', '2', '1']);
|
2024-07-21 18:16:43 +02:00
|
|
|
|
rt_int.insert_leaf(
|
2024-08-02 22:43:00 +02:00
|
|
|
|
Context::parse(&ctx, "<PosInt 10 BigEndian>~<Seq <Digit 10>>~<List <Digit 10>>~<List Char>~<Vec Char>"),
|
|
|
|
|
nested::repr_tree::ReprLeaf::from_vec_buffer( digits_dec.clone() )
|
2024-07-21 18:16:43 +02:00
|
|
|
|
);
|
|
|
|
|
|
2024-08-02 22:43:00 +02:00
|
|
|
|
let mut digits_hex_editvec = VecBuffer::<Arc<RwLock<EditTree>>>::new();
|
2024-07-21 18:16:43 +02:00
|
|
|
|
rt_int.insert_leaf(
|
|
|
|
|
Context::parse(&ctx, "
|
2024-08-02 22:43:00 +02:00
|
|
|
|
<PosInt 16 BigEndian>
|
2024-07-21 18:16:43 +02:00
|
|
|
|
~ <Seq <Digit 16>>
|
|
|
|
|
~ <List <Digit 16>
|
|
|
|
|
~ Char
|
|
|
|
|
~ EditTree>
|
|
|
|
|
~ <Vec EditTree>
|
2024-06-03 17:02:08 +02:00
|
|
|
|
"),
|
2024-08-02 22:43:00 +02:00
|
|
|
|
nested::repr_tree::ReprLeaf::from_vec_buffer( digits_hex_editvec.clone() )
|
2024-05-25 00:39:47 +02:00
|
|
|
|
);
|
2024-05-25 19:21:16 +02:00
|
|
|
|
|
2024-08-02 22:43:00 +02:00
|
|
|
|
let mut digits_dec_editvec = VecBuffer::<Arc<RwLock<EditTree>>>::new();
|
2024-07-21 18:16:43 +02:00
|
|
|
|
rt_int.insert_leaf(
|
|
|
|
|
Context::parse(&ctx, "
|
2024-08-02 22:43:00 +02:00
|
|
|
|
<PosInt 10 BigEndian>
|
|
|
|
|
~ <Seq <Digit 10>>
|
|
|
|
|
~ <List <Digit 10>
|
2024-07-21 18:16:43 +02:00
|
|
|
|
~ Char
|
|
|
|
|
~ EditTree>
|
|
|
|
|
~ <Vec EditTree>
|
|
|
|
|
"),
|
2024-08-02 22:43:00 +02:00
|
|
|
|
nested::repr_tree::ReprLeaf::from_vec_buffer( digits_dec_editvec.clone() )
|
2024-05-25 00:39:47 +02:00
|
|
|
|
);
|
2024-05-25 19:21:16 +02:00
|
|
|
|
|
2024-07-21 18:16:43 +02:00
|
|
|
|
/* initially copy values from Vec to EditTree...
|
2024-05-25 19:21:16 +02:00
|
|
|
|
*/
|
2024-07-21 18:16:43 +02:00
|
|
|
|
rebuild_projections(
|
|
|
|
|
ctx.clone(),
|
2024-05-25 00:39:47 +02:00
|
|
|
|
rt_int.clone(),
|
2024-07-21 18:16:43 +02:00
|
|
|
|
// master representation
|
|
|
|
|
vec![
|
|
|
|
|
(
|
2024-08-02 22:43:00 +02:00
|
|
|
|
"ℕ ~ <PosInt 16 BigEndian> ~ <Seq <Digit 16>> ~ <List <Digit 16> ~ Char> ~ <Vec Char>",
|
|
|
|
|
"ℕ ~ <PosInt 16 BigEndian> ~ <Seq <Digit 16>> ~ <List <Digit 16> ~ Char>"
|
2024-07-21 18:16:43 +02:00
|
|
|
|
),
|
|
|
|
|
(
|
2024-08-02 22:43:00 +02:00
|
|
|
|
"ℕ ~ <PosInt 16 BigEndian> ~ <Seq <Digit 16>> ~ <List <Digit 16> ~ Char>",
|
|
|
|
|
"ℕ ~ <PosInt 16 BigEndian> ~ <Seq <Digit 16>> ~ <List <Digit 16> ~ Char ~ EditTree>"
|
2024-07-21 18:16:43 +02:00
|
|
|
|
),
|
|
|
|
|
(
|
2024-08-02 22:43:00 +02:00
|
|
|
|
"ℕ ~ <PosInt 16 BigEndian> ~ <Seq <Digit 16>> ~ <List <Digit 16> ~ Char> ~ <List EditTree>",
|
|
|
|
|
"ℕ ~ <PosInt 16 BigEndian> ~ <Seq <Digit 16>> ~ <List <Digit 16> ~ Char> ~ <List EditTree> ~ <Vec EditTree>"
|
2024-07-21 18:16:43 +02:00
|
|
|
|
),
|
|
|
|
|
(
|
2024-08-02 22:43:00 +02:00
|
|
|
|
"ℕ ~ <PosInt 16 BigEndian> ~ <Seq <Digit 16>> ~ <List <Digit 16> ~ Char> ~ <List EditTree> ~ <Vec EditTree>",
|
|
|
|
|
"ℕ ~ <PosInt 16 BigEndian> ~ <Seq <Digit 16>> ~ <List <Digit 16> ~ Char> ~ EditTree"
|
2024-07-21 18:16:43 +02:00
|
|
|
|
),
|
|
|
|
|
].into_iter()
|
|
|
|
|
.map(|(s,d)| (Context::parse(&ctx, s), Context::parse(&ctx, d)))
|
|
|
|
|
.collect()
|
2024-05-25 00:39:47 +02:00
|
|
|
|
);
|
|
|
|
|
|
2024-08-02 22:43:00 +02:00
|
|
|
|
setup_hex_master(&ctx, &rt_int);
|
2024-06-03 17:02:08 +02:00
|
|
|
|
|
2024-08-02 22:43:00 +02:00
|
|
|
|
let edittree_hex_be_list = ctx.read().unwrap()
|
2024-07-21 18:16:43 +02:00
|
|
|
|
.setup_edittree(
|
|
|
|
|
rt_int.descend(Context::parse(&ctx,"
|
2024-08-02 22:43:00 +02:00
|
|
|
|
<PosInt 16 BigEndian>
|
2024-07-21 18:16:43 +02:00
|
|
|
|
~ <Seq <Digit 16>>
|
|
|
|
|
~ <List <Digit 16>>
|
|
|
|
|
~ <List Char>
|
|
|
|
|
")).expect("descend"),
|
|
|
|
|
SingletonBuffer::new(0).get_port()
|
2024-08-02 21:58:07 +02:00
|
|
|
|
).unwrap().get();
|
|
|
|
|
|
2024-08-02 22:43:00 +02:00
|
|
|
|
let edittree_dec_be_list = ctx.read().unwrap()
|
2024-07-21 18:16:43 +02:00
|
|
|
|
.setup_edittree(
|
|
|
|
|
rt_int.descend(Context::parse(&ctx,"
|
2024-08-02 22:43:00 +02:00
|
|
|
|
<PosInt 10 BigEndian>
|
|
|
|
|
~ <Seq <Digit 10>>
|
|
|
|
|
~ <List <Digit 10>>
|
2024-07-21 18:16:43 +02:00
|
|
|
|
~ <List Char>
|
|
|
|
|
")).expect("descend"),
|
|
|
|
|
SingletonBuffer::new(0).get_port()
|
2024-08-02 21:58:07 +02:00
|
|
|
|
).unwrap().get();
|
2024-08-01 18:35:57 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let hex_digits_view = rt_int.descend(Context::parse(&ctx, "
|
|
|
|
|
<PosInt 16 LittleEndian>
|
|
|
|
|
~ <Seq <Digit 16> >
|
|
|
|
|
~ <List <Digit 16>
|
|
|
|
|
~ ℤ_2^64
|
|
|
|
|
~ machine.UInt64 >
|
|
|
|
|
")).expect("descend")
|
|
|
|
|
.view_list::<u64>()
|
|
|
|
|
.map(|v| TerminalAtom::from(char::from_digit(*v as u32, 16)))
|
|
|
|
|
.to_sequence()
|
|
|
|
|
.to_grid_horizontal()
|
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
let dec_digits_view = rt_int.descend(Context::parse(&ctx, "
|
|
|
|
|
<PosInt 10 LittleEndian>
|
|
|
|
|
~ <Seq <Digit 10>>
|
|
|
|
|
~ <List <Digit 10>
|
|
|
|
|
~ ℤ_2^64
|
|
|
|
|
~ machine.UInt64 >
|
|
|
|
|
")).expect("descend")
|
|
|
|
|
.view_list::<u64>()
|
|
|
|
|
.map(|v| TerminalAtom::from(char::from_digit(*v as u32, 10)))
|
|
|
|
|
.to_sequence()
|
|
|
|
|
.to_grid_horizontal()
|
|
|
|
|
;
|
|
|
|
|
|
2024-06-03 17:02:08 +02:00
|
|
|
|
/* list of both editors
|
|
|
|
|
*/
|
|
|
|
|
let mut list_editor = nested::editors::list::ListEditor::new(ctx.clone(), Context::parse(&ctx, "<Seq Char>"));
|
2024-08-02 21:58:07 +02:00
|
|
|
|
list_editor.data.push( edittree_hex_be_list.clone() );
|
2024-08-02 22:43:00 +02:00
|
|
|
|
list_editor.data.push( edittree_dec_be_list.clone() );
|
2024-06-03 17:02:08 +02:00
|
|
|
|
let mut edittree = list_editor.into_node(SingletonBuffer::new(0).get_port());
|
2024-05-25 19:21:16 +02:00
|
|
|
|
|
2024-06-03 17:02:08 +02:00
|
|
|
|
/* cursors are a bit screwed initially so fix them up
|
|
|
|
|
* TODO: how to fix this generally?
|
|
|
|
|
*/
|
2024-08-02 21:58:07 +02:00
|
|
|
|
edittree_hex_be_list.write().unwrap().goto(TreeCursor::none());
|
2024-08-02 22:43:00 +02:00
|
|
|
|
edittree_dec_be_list.write().unwrap().goto(TreeCursor::none());
|
2024-06-03 17:02:08 +02:00
|
|
|
|
edittree.goto(TreeCursor{
|
|
|
|
|
leaf_mode: nested::editors::list::ListCursorMode::Insert,
|
2024-08-02 22:43:00 +02:00
|
|
|
|
tree_addr: vec![0,0]
|
2024-06-03 17:02:08 +02:00
|
|
|
|
});
|
|
|
|
|
let edittree = Arc::new(RwLock::new(edittree));
|
|
|
|
|
|
2024-05-25 00:39:47 +02:00
|
|
|
|
/* setup terminal
|
|
|
|
|
*/
|
|
|
|
|
let app = TTYApplication::new({
|
|
|
|
|
/* event handler
|
|
|
|
|
*/
|
|
|
|
|
let ctx = ctx.clone();
|
2024-07-21 18:16:43 +02:00
|
|
|
|
let rt_int = rt_int.clone();
|
|
|
|
|
let last_idx = RwLock::new(1);
|
2024-05-25 00:39:47 +02:00
|
|
|
|
move |ev| {
|
2024-07-21 18:16:43 +02:00
|
|
|
|
|
|
|
|
|
let cur = edittree.read().unwrap().get_cursor();
|
|
|
|
|
if cur.tree_addr.len() > 0 {
|
|
|
|
|
match cur.tree_addr[0] {
|
|
|
|
|
0 => {
|
|
|
|
|
let mut li = last_idx.write().unwrap();
|
|
|
|
|
if *li != 0 {
|
2024-08-02 22:43:00 +02:00
|
|
|
|
setup_hex_master(&ctx, &rt_int);
|
2024-07-21 18:16:43 +02:00
|
|
|
|
*li = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
1 => {
|
|
|
|
|
let mut li = last_idx.write().unwrap();
|
|
|
|
|
if *li != 1 {
|
2024-08-02 22:43:00 +02:00
|
|
|
|
setup_dec_master(&ctx, &rt_int);
|
2024-07-21 18:16:43 +02:00
|
|
|
|
*li = 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
_=>{}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-03 17:02:08 +02:00
|
|
|
|
edittree.write().unwrap().send_cmd_obj(ev.to_repr_tree(&ctx));
|
2024-05-25 00:39:47 +02:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
/* Setup the compositor to serve as root-view
|
|
|
|
|
* by routing it to the `app.port` Viewport,
|
|
|
|
|
* so it will be displayed on TTY-output.
|
|
|
|
|
*/
|
|
|
|
|
let compositor = TerminalCompositor::new(app.port.inner());
|
2024-07-21 18:16:43 +02:00
|
|
|
|
|
2024-05-25 00:39:47 +02:00
|
|
|
|
/* Now add some views to our compositor
|
|
|
|
|
*/
|
|
|
|
|
{
|
|
|
|
|
let mut comp = compositor.write().unwrap();
|
|
|
|
|
|
2024-06-03 17:02:08 +02:00
|
|
|
|
fn show_edit_tree( ctx: &Arc<RwLock<Context>>, comp: &mut TerminalCompositor, rt: &Arc<RwLock<ReprTree>>, y: i16 )
|
|
|
|
|
{
|
|
|
|
|
let rt_edittree = rt.descend(Context::parse(&ctx, "EditTree")).expect("descend");
|
|
|
|
|
let halo_type = rt_edittree.read().unwrap().get_halo_type().clone();
|
2024-08-02 21:58:07 +02:00
|
|
|
|
let edittree = rt_edittree.read().unwrap().get_view::<dyn r3vi::view::singleton::SingletonView<Item = Arc<RwLock<EditTree>>>>().unwrap().get().read().unwrap().clone();
|
2024-06-03 17:02:08 +02:00
|
|
|
|
|
|
|
|
|
comp.push( nested_tty::make_label( &ctx.read().unwrap().type_term_to_str(&halo_type) )
|
2024-05-25 00:39:47 +02:00
|
|
|
|
.map_item(|_pt, atom| atom.add_style_front(TerminalStyle::fg_color((90,90,90))))
|
2024-06-03 17:02:08 +02:00
|
|
|
|
.offset(Vector2::new(1,y)));
|
|
|
|
|
|
|
|
|
|
comp.push( edittree.display_view()
|
|
|
|
|
.offset(Vector2::new(1,y+1)));
|
|
|
|
|
}
|
2024-05-25 00:39:47 +02:00
|
|
|
|
|
2024-06-03 17:02:08 +02:00
|
|
|
|
show_edit_tree(&ctx, &mut comp, &rt_int.descend(Context::parse(&ctx, "<PosInt 16 BigEndian> ~ <Seq~List <Digit 16>~Char>")).expect(""), 1);
|
2024-08-02 22:43:00 +02:00
|
|
|
|
show_edit_tree(&ctx, &mut comp, &rt_int.descend(Context::parse(&ctx, "<PosInt 10 BigEndian> ~ <Seq~List <Digit 10>~Char>")).expect(""), 4);
|
2024-05-25 00:39:47 +02:00
|
|
|
|
|
2024-06-03 17:02:08 +02:00
|
|
|
|
/* project the seq of u64 representations to a view
|
|
|
|
|
*/
|
|
|
|
|
comp.push(nested_tty::make_label("dec: ").offset(Vector2::new(3,7)));
|
|
|
|
|
comp.push(dec_digits_view.offset(Vector2::new(8,7)).map_item(|_,a| {
|
2024-05-25 19:21:16 +02:00
|
|
|
|
a.add_style_back(TerminalStyle::fg_color((30,90,200)))
|
|
|
|
|
}));
|
2024-08-01 18:35:57 +02:00
|
|
|
|
|
2024-06-03 17:02:08 +02:00
|
|
|
|
comp.push(nested_tty::make_label("hex: ").offset(Vector2::new(3,8)));
|
|
|
|
|
comp.push(hex_digits_view.offset(Vector2::new(8,8)).map_item(|_,a| {
|
2024-05-25 19:21:16 +02:00
|
|
|
|
a.add_style_back(TerminalStyle::fg_color((200, 200, 30)))
|
|
|
|
|
}));
|
2024-05-25 00:39:47 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* write the changes in the view of `term_port` to the terminal
|
|
|
|
|
*/
|
|
|
|
|
app.show().await.expect("output error!");
|
|
|
|
|
}
|
2024-05-25 19:21:16 +02:00
|
|
|
|
|