PTYListEditor: move style into node constructor

This commit is contained in:
Michael Sippel 2023-02-11 12:03:37 +01:00
parent 4afdb61b87
commit d43d99c6d3
Signed by: senvas
GPG key ID: F96CF119C34B64A6
3 changed files with 29 additions and 43 deletions

View file

@ -125,13 +125,14 @@ impl PosIntEditor {
TypeTerm::Num(radix as i64) TypeTerm::Num(radix as i64)
] ]
}, },
None,
0
).into_node(
match radix { match radix {
16 => SeqDecorStyle::Hex, 16 => SeqDecorStyle::Hex,
_ => SeqDecorStyle::Plain _ => SeqDecorStyle::Plain
}, }
None, )
0
).into_node()
} }
} }

View file

@ -26,12 +26,7 @@ use {
pub struct PTYListEditor { pub struct PTYListEditor {
pub editor: Arc<RwLock<ListEditor>>, pub editor: Arc<RwLock<ListEditor>>,
split_char: Option<char>, split_char: Option<char>,
depth: usize
style: SeqDecorStyle,
depth: usize,
pub diag: OuterViewPort<dyn SequenceView<Item = crate::diagnostics::Message>>,
pub view: OuterViewPort<dyn TerminalView>
} }
//<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>> //<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>>
@ -40,27 +35,38 @@ impl PTYListEditor {
pub fn new( pub fn new(
ctx: Arc<RwLock<Context>>, ctx: Arc<RwLock<Context>>,
typ: TypeTerm, typ: TypeTerm,
style: SeqDecorStyle,
split_char: Option<char>, split_char: Option<char>,
depth: usize depth: usize
) -> Self { ) -> Self {
Self::from_editor( Self::from_editor(
ListEditor::new(ctx, typ, depth), style, split_char, depth) ListEditor::new(ctx, typ, depth), split_char, depth)
} }
pub fn from_editor( pub fn from_editor(
editor: ListEditor, editor: ListEditor,
style: SeqDecorStyle,
split_char: Option<char>, split_char: Option<char>,
depth: usize depth: usize
) -> Self { ) -> Self {
PTYListEditor { PTYListEditor {
split_char, split_char,
style,
depth, depth,
editor: Arc::new(RwLock::new(editor)),
}
}
view: editor.get_seg_seq_view().pty_decorate(style, depth), pub fn into_node(self, style: SeqDecorStyle) -> NestedNode {
diag: editor.get_data_port() let editor = Arc::new(RwLock::new(self));
let ed = editor.read().unwrap();
let edd = ed.editor.read().unwrap();
NestedNode::new()
.set_cmd(editor.clone())
.set_nav(ed.editor.clone())
.set_ctx(edd.ctx.clone())
.set_view(edd.get_seg_seq_view().pty_decorate(style, ed.depth))
.set_diag(
edd.get_data_port()
.enumerate() .enumerate()
.map( .map(
|(idx, item_editor)| { |(idx, item_editor)| {
@ -76,45 +82,25 @@ impl PTYListEditor {
) )
} }
) )
.flatten(), .flatten()
)
editor: Arc::new(RwLock::new(editor)),
}
} }
pub fn into_node(self) -> NestedNode {
let editor = Arc::new(RwLock::new(self));
let ed = editor.read().unwrap();
let edd = ed.editor.read().unwrap();
NestedNode::new()
.set_cmd(editor.clone())
.set_nav(ed.editor.clone())
.set_ctx(edd.ctx.clone())
.set_diag(ed.diag.clone())
.set_view(ed.view.clone())
}
pub fn get_data_port(&self) -> OuterViewPort<dyn SequenceView<Item = NestedNode>> { pub fn get_data_port(&self) -> OuterViewPort<dyn SequenceView<Item = NestedNode>> {
self.editor.read().unwrap().get_data_port() self.editor.read().unwrap().get_data_port()
} }
pub fn clear(&mut self) { pub fn clear(&mut self) {
self.editor.write().unwrap().clear(); self.editor.write().unwrap().clear();
} }
pub fn get_item(&self) -> Option<NestedNode> { pub fn get_item(&self) -> Option<NestedNode> {
self.editor.read().unwrap().get_item() self.editor.read().unwrap().get_item()
} }
pub fn set_depth(&mut self, depth: usize) { pub fn set_depth(&mut self, depth: usize) {
self.depth = depth; self.depth = depth;
} }
pub fn set_style(&mut self, style: SeqDecorStyle) {
self.style = style;
}
} }
impl Commander for PTYListEditor { impl Commander for PTYListEditor {

View file

@ -74,10 +74,9 @@ pub fn init_editor_ctx(parent: Arc<RwLock<Context>>) -> Arc<RwLock<Context>> {
PTYListEditor::new( PTYListEditor::new(
ctx.clone(), ctx.clone(),
args[0].clone(), args[0].clone(),
style,
delim, delim,
depth depth
).into_node() ).into_node(style)
) )
} else { } else {
None None