node: ViewPort for editor, cleanup PTYListEditor

- move split/join functions into ListEditor
- separate PTYListStyle and PTYListController
This commit is contained in:
Michael Sippel 2023-03-25 08:56:38 +01:00
parent 1575fa756e
commit b6bd888d3d
Signed by: senvas
GPG key ID: 060F22F65102F95C
7 changed files with 282 additions and 290 deletions

View file

@ -12,7 +12,7 @@ use {
},
crate::{
type_system::{Context, TypeTerm, ReprTree},
editors::list::{PTYListEditor},
editors::list::{ListEditor, PTYListController, PTYListStyle},
terminal::{
TerminalAtom, TerminalEvent, TerminalStyle, make_label
},
@ -114,7 +114,7 @@ impl DigitEditor {
pub fn get_type(&self) -> TypeTerm {
TypeTerm::Type {
id: self.ctx.read().unwrap().get_typeid("Digit").unwrap(),
id: self.ctx.read().unwrap().get_fun_typeid("Digit").unwrap(),
args: vec![
TypeTerm::Num(self.radix as i64).into()
]
@ -140,38 +140,31 @@ pub struct PosIntEditor {
impl PosIntEditor {
pub fn new(ctx: Arc<RwLock<Context>>, radix: u32) -> Self {
let editor = PTYListEditor::new(
ctx.clone(),
TypeTerm::Type {
id: ctx.read().unwrap().get_typeid("Digit").unwrap(),
args: vec![
TypeTerm::Num(radix as i64).into()
]
},
None,
0
);
let mut node = Context::make_node(&ctx, (&ctx, format!("( List ( Digit {} ) )", radix).as_str()).into(), 0).unwrap();
let view = editor.pty_view((
PTYListController::for_node( &mut node, Some(' '), None );
PTYListStyle::for_node( &mut node,
(
match radix {
2 => "0d".into(),
16 => "0x".into(),
_ => "".into()
},
"".into(),
"".into()));
let mut node = editor.into_node().set_view(view);
"".into()
)
);
// Set Type
let data = node.data.clone().unwrap();
node = node.set_data(ReprTree::ascend(
&data,
TypeTerm::Type {
id: ctx.read().unwrap().get_typeid("PosInt").unwrap(),
id: ctx.read().unwrap().get_fun_typeid("PosInt").unwrap(),
args: vec![
TypeTerm::Num(radix as i64).into(),
TypeTerm::Type {
id: ctx.read().unwrap().get_typeid("BigEndian").unwrap(),
id: ctx.read().unwrap().get_fun_typeid("BigEndian").unwrap(),
args: vec![]
}.into()
]

View file

@ -7,3 +7,4 @@ pub use {
editor::{DigitEditor, PosIntEditor},
radix::RadixProjection,
};

View file

@ -1,12 +1,13 @@
use {
r3vi::{
view::{OuterViewPort, singleton::*, sequence::*},
view::{port::UpdateTask, OuterViewPort, singleton::*, sequence::*},
buffer::{singleton::*, vec::*}
},
crate::{
type_system::{Context, TypeTerm, ReprTree},
editors::list::{ListCursor, ListCursorMode},
tree::{NestedNode, TreeNav}
tree::{NestedNode, TreeNav, TreeCursor},
diagnostics::Diagnostics
},
std::sync::{Arc, RwLock}
};
@ -27,6 +28,31 @@ pub struct ListEditor {
}
impl ListEditor {
pub fn init_ctx(ctx: &Arc<RwLock<Context>>) {
let mut ctx = ctx.write().unwrap();
ctx.add_list_typename("List".into());
ctx.add_node_ctor(
"List", Arc::new(
|ctx: Arc<RwLock<Context>>, ty: TypeTerm, depth: usize| {
match ty {
TypeTerm::Type {
id: _, args
} => {
if args.len() > 0 {
let typ = (args[0].clone().0)[0].clone();
Some(ListEditor::new(ctx, typ).into_node(depth))
} else {
None
}
}
_ => None
}
}
)
);
}
pub fn new(
ctx: Arc<RwLock<Context>>,
typ: TypeTerm,
@ -92,30 +118,33 @@ impl ListEditor {
let ctx = self.ctx.clone();
let editor = Arc::new(RwLock::new(self));
let e = editor.read().unwrap();
NestedNode::new(depth)
.set_ctx(ctx)
.set_data(data)
.set_editor(editor.clone())
.set_nav(editor.clone())
// .set_cmd(editor.clone())
//.set_cmd(editor.clone())
.set_diag(e
.get_data_port()
.enumerate()
.map(
|(idx, item_editor)| {
let idx = *idx;
item_editor
.get_msg_port()
.map(
move |msg| {
let mut msg = msg.clone();
msg.addr.insert(0, idx);
msg
}
pub fn new_node(
node: NestedNode,
item_type: TypeTerm
) -> NestedNode {
let ctx = node.ctx.clone().unwrap();
let editor = ListEditor::new(
ctx.clone(),
item_type,
);
let data = editor.get_data();
let editor = Arc::new(RwLock::new(editor));
node.set_data(data)
.set_editor(editor.clone())
.set_nav(editor.clone())
)
}
)
.flatten()
)
}
pub fn get_item_type(&self) -> TypeTerm {
@ -124,7 +153,7 @@ impl ListEditor {
pub fn get_seq_type(&self) -> TypeTerm {
TypeTerm::Type {
id: self.ctx.read().unwrap().get_typeid("List").unwrap(),
id: self.ctx.read().unwrap().get_fun_typeid("List").unwrap(),
args: vec![ self.get_item_type().into() ]
}
}
@ -255,8 +284,10 @@ impl ListEditor {
let prev_node = self.data.get(prev_idx);
if let Some(prev_editor) = prev_node.editor.clone() {
let prev_editor = prev_editor.downcast::<RwLock<ListEditor>>().unwrap();
prev_editor.0.update();
let prev_editor = prev_editor.get_view().unwrap().get().unwrap().downcast::<RwLock<ListEditor>>().unwrap();
let prev_editor = prev_editor.write().unwrap();
prev_editor.get_data_port().0.update();
if prev_editor.get_data_port().get_view().unwrap().iter()
.filter_map(|x| x.get_data_view::<dyn SingletonView<Item = Option<char>>>(vec![].into_iter())?.get()).count() == 0
@ -305,6 +336,110 @@ impl ListEditor {
self.data.push(other.data.get(i));
}
}
pub fn listlist_split(&mut self) {
let cur = self.get_cursor();
if let Some(item) = self.get_item_mut() {
let depth = item.depth;
if let Some(head_editor) = item.editor.clone() {
head_editor.0.update();
let head = head_editor.get_view().unwrap().get().unwrap().downcast::<RwLock<ListEditor>>().unwrap();
let mut head = head.write().unwrap();
if head.data.len() > 0 {
if cur.tree_addr.len() > 2 {
head.listlist_split();
}
let mut tail = head.split();
head.goto(TreeCursor::none());
tail.cursor.set(
ListCursor {
idx: Some(0),
mode: if cur.tree_addr.len() > 2 {
ListCursorMode::Select
} else {
ListCursorMode::Insert
}
}
);
let item_type =
if let Some(data) = item.data.clone() {
let data = data.read().unwrap();
Some(data.get_type().clone())
} else {
None
};
let mut tail_node = tail.into_node(depth);
tail_node = tail_node.set_ctx(item.ctx.clone().unwrap());
// if let Some(item_type) = item_type {
tail_node = tail_node.morph(self.typ.clone());
//}
self.insert(
tail_node
);
}
}
}
}
pub fn listlist_join_pxev(&mut self, idx: isize, item: &NestedNode) {
{
let prev_editor = self.data.get_mut(idx as usize-1);
let prev_editor = prev_editor.editor.clone();
if let Some(prev_editor) = prev_editor {
prev_editor.0.update();
if let Ok(prev_editor) = prev_editor.get_view().unwrap().get().unwrap().downcast::<RwLock<ListEditor>>() {
let mut prev_editor = prev_editor.write().unwrap();
let cur_editor = item.editor.clone().unwrap();
cur_editor.0.update();
let cur_editor = cur_editor.get_view().unwrap().get().unwrap().downcast::<RwLock<ListEditor>>().unwrap();
let cur_editor = cur_editor.write().unwrap();
prev_editor.join(&cur_editor);
self.cursor.set(
ListCursor {
idx: Some(idx - 1), mode: ListCursorMode::Select
}
);
}
}
}
self.data.remove(idx as usize);
}
pub fn listlist_join_nexd(&mut self, next_idx: usize, item: &NestedNode) {
{
let next_editor = self.data.get_mut(next_idx).editor.clone();
if let Some(next_editor) = next_editor {
next_editor.0.update();
if let Ok(next_editor) = next_editor.get_view().unwrap().get().unwrap().downcast::<RwLock<ListEditor>>() {
let mut next_editor = next_editor.write().unwrap();
let cur_editor = item.editor.clone().unwrap();
cur_editor.0.update();
let cur_editor = cur_editor.get_view().unwrap().get().unwrap().downcast::<RwLock<ListEditor>>().unwrap();
let mut cur_editor = cur_editor.write().unwrap();
cur_editor.join(&next_editor);
}
}
}
self.data.remove(next_idx);
}
}
/*
use crate::{

View file

@ -10,6 +10,6 @@ pub use {
cursor::{ListCursor, ListCursorMode},
editor::ListEditor,
segment::{ListSegment, ListSegmentSequence},
pty_editor::{PTYListEditor}
pty_editor::{PTYListStyle, PTYListController}
};

View file

@ -18,56 +18,30 @@ use {
//<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>>
pub struct PTYListEditor {
pub editor: Arc<RwLock<ListEditor>>,
split_char: Option<char>,
pub struct PTYListStyle {
style: (String, String, String),
depth: usize
}
//<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>>
impl PTYListEditor {
pub fn new(
ctx: Arc<RwLock<Context>>,
typ: TypeTerm,
split_char: Option<char>,
depth: usize
) -> Self {
Self::from_editor(
Arc::new(RwLock::new(ListEditor::new(ctx, typ))),
split_char,
impl PTYListStyle {
pub fn new(style: (&str, &str, &str), depth: usize) -> PTYListStyle {
PTYListStyle {
style: (style.0.into(), style.1.into(), style.2.into()),
depth
)
}
pub fn from_editor(
editor: Arc<RwLock<ListEditor>>,
split_char: Option<char>,
depth: usize
) -> Self {
PTYListEditor {
split_char,
depth,
editor,
}
}
pub fn get_seg_seq_view(&self) -> OuterViewPort<dyn SequenceView<Item = OuterViewPort<dyn TerminalView>>> {
pub fn get_seg_seq_view(&self, editor: &ListEditor) -> OuterViewPort<dyn SequenceView<Item = OuterViewPort<dyn TerminalView>>> {
let seg_seq = ListSegmentSequence::new(
self.editor.read().unwrap().get_cursor_port(),
self.editor.read().unwrap().get_data_port(),
editor.get_cursor_port(),
editor.get_data_port(),
self.depth
);
let se = seg_seq.read().unwrap();
se.get_view().map(move |segment| segment.pty_view())
}
pub fn pty_view(
&self,
display_style: (&str, &str, &str),
) -> OuterViewPort<dyn TerminalView> {
let editor = self.editor.read().unwrap();
pub fn pty_view(&self, editor: &ListEditor) -> OuterViewPort<dyn TerminalView> {
let seg_seq = ListSegmentSequence::new(
editor.get_cursor_port(),
editor.get_data_port(),
@ -78,44 +52,59 @@ impl PTYListEditor {
seg_seq
.get_view()
.map(move |segment| segment.pty_view())
.separate(make_label(display_style.1))
.wrap(make_label(display_style.0), make_label(display_style.2))
.separate(make_label(&self.style.1))
.wrap(make_label(&self.style.0), make_label(&self.style.2))
.to_grid_horizontal()
.flatten()
}
pub fn into_node(self) -> NestedNode {
let depth = self.depth;
let editor = Arc::new(RwLock::new(self));
let ed = editor.read().unwrap();
let edd = ed.editor.read().unwrap();
NestedNode::new(depth)
.set_data(edd.get_data())
.set_cmd(editor.clone())
.set_editor(ed.editor.clone())
.set_nav(ed.editor.clone())
.set_ctx(edd.ctx.clone())
.set_diag(
edd.get_data_port()
.enumerate()
.map(
|(idx, item_editor)| {
let idx = *idx;
item_editor
.get_msg_port()
.map(
move |msg| {
let mut msg = msg.clone();
msg.addr.insert(0, idx);
msg
pub fn for_node(node: &mut NestedNode, style: (&str, &str, &str)) {
node.view = Some(
Self::new(style, node.depth)
.pty_view(
&node.get_edit::<ListEditor>().unwrap().read().unwrap()
)
);
}
)
}
//<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>>
pub struct PTYListController {
pub editor: Arc<RwLock<ListEditor>>,
split_char: Option<char>,
close_char: Option<char>,
depth: usize
}
//<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>>
impl PTYListController {
pub fn from_editor(
editor: Arc<RwLock<ListEditor>>,
split_char: Option<char>,
close_char: Option<char>,
depth: usize
) -> Self {
PTYListController {
editor,
split_char,
close_char,
depth
}
)
.flatten()
)
}
pub fn for_node(
node: &mut NestedNode,
split_char: Option<char>,
close_char: Option<char>
) {
let editor = node.get_edit::<ListEditor>().unwrap();
let controller = Arc::new(RwLock::new(PTYListController::from_editor( editor, split_char, close_char, node.depth )));
node.cmd = Some(controller.clone());
}
pub fn get_data_port(&self) -> OuterViewPort<dyn SequenceView<Item = NestedNode>> {
@ -133,113 +122,16 @@ impl PTYListEditor {
pub fn set_depth(&mut self, depth: usize) {
self.depth = depth;
}
pub fn split(e: &mut ListEditor) {
let cur = e.get_cursor();
if let Some(item) = e.get_item_mut() {
let depth = item.depth;
if let Some(head_editor) = item.editor.clone() {
let head = head_editor.downcast::<RwLock<ListEditor>>().unwrap();
let mut head = head.write().unwrap();
if head.data.len() > 0 {
if cur.tree_addr.len() > 2 {
PTYListEditor::split(&mut head);
}
let mut tail = head.split();
head.goto(TreeCursor::none());
tail.cursor.set(
ListCursor {
idx: Some(0),
mode: if cur.tree_addr.len() > 2 {
ListCursorMode::Select
} else {
ListCursorMode::Insert
}
}
);
let item_type =
if let Some(data) = item.data.clone() {
let data = data.read().unwrap();
Some(data.get_type().clone())
} else {
None
};
let mut tail_node = tail.into_node(depth);
tail_node = tail_node.set_ctx(item.ctx.clone().unwrap());
if let Some(item_type) = item_type {
tail_node = tail_node.morph(item_type);
}
e.insert(
tail_node
);
}
}
}
}
fn join_pxev(e: &mut ListEditor, idx: isize, item: &NestedNode) {
{
let prev_editor = e.data.get_mut(idx as usize-1);
let prev_editor = prev_editor.editor.clone();
if let Some(prev_editor) = prev_editor {
if let Ok(prev_editor) = prev_editor.downcast::<RwLock<ListEditor>>() {
let mut prev_editor = prev_editor.write().unwrap();
let cur_editor = item.editor.clone().unwrap();
let cur_editor = cur_editor.downcast::<RwLock<ListEditor>>().unwrap();
let cur_editor = cur_editor.write().unwrap();
prev_editor.join(&cur_editor);
e.cursor.set(
ListCursor {
idx: Some(idx - 1), mode: ListCursorMode::Select
}
);
}
}
}
e.data.remove(idx as usize);
}
fn join_nexd(e: &mut ListEditor, next_idx: usize, item: &NestedNode) {
{
let next_editor = e.data.get_mut(next_idx).editor.clone();
if let Some(next_editor) = next_editor {
if let Ok(next_editor) = next_editor.downcast::<RwLock<ListEditor>>() {
let mut next_editor = next_editor.write().unwrap();
let cur_editor = item.editor.clone().unwrap();
let cur_editor = cur_editor.downcast::<RwLock<ListEditor>>().unwrap();
let mut cur_editor = cur_editor.write().unwrap();
cur_editor.join(&next_editor);
}
}
}
e.data.remove(next_idx);
}
}
use r3vi::view::singleton::SingletonView;
use crate::commander::ObjCommander;
impl ObjCommander for PTYListEditor {
impl ObjCommander for PTYListController {
fn send_cmd_obj(&mut self, cmd_obj: Arc<RwLock<ReprTree>>) -> TreeNavResult {
let mut e = self.editor.write().unwrap();
let cur = e.cursor.get();
let cur_depth = e.get_cursor().tree_addr.len();
let ctx = e.ctx.clone();
let ctx = ctx.read().unwrap();
@ -247,8 +139,24 @@ impl ObjCommander for PTYListEditor {
let co = cmd_obj.read().unwrap();
let cmd_type = co.get_type().clone();
let term_event_type = ctx.type_term_from_str("( TerminalEvent )").unwrap();
let nested_node_type = ctx.type_term_from_str("( NestedNode )").unwrap();
let char_type = ctx.type_term_from_str("( Char )").unwrap();
if cmd_type == nested_node_type {
if let Some(node_view) = co.get_view::<dyn SingletonView<Item = NestedNode>>() {
if let Some(idx) = cur.idx {
match cur.mode {
ListCursorMode::Select => {
*e.data.get_mut(idx as usize) = node_view.get();
}
ListCursorMode::Insert => {
e.data.insert(idx as usize, node_view.get());
}
}
}
}
}
if cmd_type == term_event_type {
if let Some(te_view) = co.get_view::<dyn SingletonView<Item = TerminalEvent>>() {
drop(co);
@ -309,7 +217,7 @@ impl ObjCommander for PTYListEditor {
|is_zero, x| is_zero && (*x == 0)
)
{
PTYListEditor::join_pxev(&mut e, idx, &item);
e.listlist_join_pxev(idx, &item);
/* Optional: recursive joining
@ -333,7 +241,7 @@ impl ObjCommander for PTYListEditor {
|is_end, x| is_end && (*x == -1)
)
{
PTYListEditor::join_nexd(&mut e, next_idx, &item);
e.listlist_join_nexd(next_idx, &item);
/* Optional: recursive joining
@ -351,7 +259,7 @@ impl ObjCommander for PTYListEditor {
TerminalEvent::Input(Event::Key(Key::Char(c))) => {
if Some(c) == self.split_char {
PTYListEditor::split(&mut e);
e.listlist_split();
TreeNavResult::Continue
} else {
item.send_cmd_obj(cmd_obj)
@ -382,14 +290,18 @@ impl ObjCommander for PTYListEditor {
drop(co);
let c = cmd_view.get();
if Some(c) == self.split_char {
PTYListEditor::split(&mut e);
if Some(c) == self.split_char && cur_depth == 2 {
e.listlist_split();
TreeNavResult::Continue
} else {
if let Some(mut item) = e.get_item_mut() {
match item.send_cmd_obj(cmd_obj) {
TreeNavResult::Continue => TreeNavResult::Continue,
TreeNavResult::Exit => {
if Some(c) == self.split_char {
e.listlist_split();
}
item.goto(TreeCursor::none());
e.cursor.set(ListCursor {
mode: ListCursorMode::Insert,

View file

@ -24,7 +24,7 @@ pub struct NestedNode {
pub ctx: Option<Arc<RwLock<Context>>>,
/// abstract editor
pub editor: Option<Arc<dyn Any + Send + Sync>>,
pub editor: Option<OuterViewPort<dyn SingletonView<Item = Option<Arc<dyn Any + Send + Sync>>>>>,
/// abstract data view
pub data: Option<Arc<RwLock<ReprTree>>>,
@ -195,7 +195,7 @@ impl NestedNode {
}
pub fn set_editor(mut self, editor: Arc<dyn Any + Send + Sync>) -> Self {
self.editor = Some(editor);
self.editor = Some(SingletonBuffer::new(Some(editor)).get_port());
self
}
@ -267,7 +267,7 @@ impl NestedNode {
*/
pub fn get_edit<T: Send + Sync + 'static>(&self) -> Option<Arc<RwLock<T>>> {
if let Some(edit) = self.editor.clone() {
if let Ok(edit) = edit.downcast::<RwLock<T>>() {
if let Ok(edit) = edit.get_view().unwrap().get().unwrap().downcast::<RwLock<T>>() {
Some(edit)
} else {
None

View file

@ -61,38 +61,13 @@ pub fn init_editor_ctx(parent: Arc<RwLock<Context>>) -> Arc<RwLock<Context>> {
}
)
);
ctx.write().unwrap().add_list_typename("Seq".into());
ctx.write().unwrap().add_list_typename("Sequence".into());
ctx.write().unwrap().add_list_typename("SepSeq".into());
ctx.write().unwrap().add_typename("NestedNode".into());
ctx.write().unwrap().add_list_typename("List".into());
ctx.write().unwrap().add_node_ctor(
"List", Arc::new(
|ctx: Arc<RwLock<Context>>, ty: TypeTerm, depth: usize| {
match ty {
TypeTerm::Type {
id: _, args
} => {
if args.len() > 0 {
let editor = PTYListEditor::new(
ctx,
(args[0].clone().0)[0].clone(),
Some(','),
depth + 1
);
let view = editor.pty_view(("{",", ", "}"));
Some(editor
.into_node()
.set_view(view))
} else {
None
}
}
_ => None
}
}
)
);
ListEditor::init_ctx( &ctx );
ctx.write().unwrap().add_list_typename("Symbol".into());
let pattern = MorphismTypePattern {
@ -102,16 +77,8 @@ pub fn init_editor_ctx(parent: Arc<RwLock<Context>>) -> Arc<RwLock<Context>> {
ctx.write().unwrap().add_morphism(pattern,
Arc::new(
|mut node, _dst_type:_| {
let depth = node.depth;
let editor = node.editor.clone().unwrap().downcast::<RwLock<ListEditor>>().unwrap();
let pty_editor = PTYListEditor::from_editor(
editor,
None,
depth
);
node.view = Some(pty_editor.pty_view(("", "", "")));
node.cmd = Some(Arc::new(RwLock::new(pty_editor)));
PTYListController::for_node( &mut node, None, None );
PTYListStyle::for_node( &mut node, ("","","") );
Some(node)
}
)
@ -123,7 +90,7 @@ pub fn init_editor_ctx(parent: Arc<RwLock<Context>>) -> Arc<RwLock<Context>> {
let mut node = Context::make_node(
&ctx,
TypeTerm::Type {
id: ctx.read().unwrap().get_typeid("List").unwrap(),
id: ctx.read().unwrap().get_fun_typeid("List").unwrap(),
args: vec![
TypeTerm::new(ctx.read().unwrap().get_typeid("Char").unwrap()).into()
]
@ -146,20 +113,8 @@ pub fn init_editor_ctx(parent: Arc<RwLock<Context>>) -> Arc<RwLock<Context>> {
ctx.write().unwrap().add_morphism(pattern,
Arc::new(
|mut node, _dst_type:_| {
let depth = node.depth;
let editor = node.editor.clone().unwrap().downcast::<RwLock<ListEditor>>().unwrap();
let pty_editor = PTYListEditor::from_editor(
editor,
None,
depth
);
node.view = Some(pty_editor.pty_view((
"\"".into(),
"".into(),
"\"".into()
)));
node.cmd = Some(Arc::new(RwLock::new(pty_editor)));
PTYListController::for_node( &mut node, None, Some('\"') );
PTYListStyle::for_node( &mut node, ("\"","","\"") );
Some(node)
}
)
@ -171,7 +126,7 @@ pub fn init_editor_ctx(parent: Arc<RwLock<Context>>) -> Arc<RwLock<Context>> {
let mut node = Context::make_node(
&ctx,
TypeTerm::Type {
id: ctx.read().unwrap().get_typeid("List").unwrap(),
id: ctx.read().unwrap().get_fun_typeid("List").unwrap(),
args: vec![
TypeTerm::new(ctx.read().unwrap().get_typeid("Char").unwrap()).into()
]
@ -243,7 +198,7 @@ pub fn init_math_ctx(parent: Arc<RwLock<Context>>) -> Arc<RwLock<Context>> {
Arc::new(
|mut node, dst_type| {
let depth = node.depth;
let editor = node.editor.clone().unwrap().downcast::<RwLock<ListEditor>>().unwrap();
let editor = node.editor.clone().unwrap().get_view().unwrap().get().unwrap().downcast::<RwLock<ListEditor>>().unwrap();
// todo: check src_type parameter to be ( Digit radix )
@ -254,21 +209,17 @@ pub fn init_math_ctx(parent: Arc<RwLock<Context>>) -> Arc<RwLock<Context>> {
if args.len() > 0 {
match (args[0].0)[0] {
TypeTerm::Num(_radix) => {
let pty_editor = PTYListEditor::from_editor(
editor,
PTYListController::for_node(
&mut node,
Some(','),
depth
None,
);
PTYListStyle::for_node(
&mut node,
("0d", "", "")
);
// todo: set data view
node.view = Some(pty_editor.pty_view(
(
"{".into(),
", ".into(),
"}".into()
)
));
node.cmd = Some(Arc::new(RwLock::new(pty_editor)));
Some(node)
},
_ => None
@ -297,7 +248,7 @@ pub fn init_math_ctx(parent: Arc<RwLock<Context>>) -> Arc<RwLock<Context>> {
let mut node = Context::make_node(
&ctx,
TypeTerm::Type {
id: ctx.read().unwrap().get_typeid("List").unwrap(),
id: ctx.read().unwrap().get_fun_typeid("List").unwrap(),
args: vec![
TypeTerm::new(ctx.read().unwrap().get_typeid("Digit").unwrap())
.num_arg(radix)