add diagnostics; contanis some bugs

This commit is contained in:
Michael Sippel 2022-10-23 19:29:50 +02:00
parent 906cc51329
commit b2f437d7df
12 changed files with 340 additions and 43 deletions

View file

@ -9,6 +9,7 @@ use {
TerminalView, TerminalView,
}, },
tree_nav::{TerminalTreeEditor, TreeCursor, TreeNav, TreeNavResult}, tree_nav::{TerminalTreeEditor, TreeCursor, TreeNav, TreeNavResult},
diagnostics::Diagnostics
}, },
std::sync::Arc, std::sync::Arc,
std::sync::RwLock, std::sync::RwLock,
@ -37,6 +38,8 @@ impl CharEditor {
} }
impl TreeNav for CharEditor {} impl TreeNav for CharEditor {}
impl Diagnostics for CharEditor {}
impl TerminalEditor for CharEditor { impl TerminalEditor for CharEditor {
fn get_term_view(&self) -> OuterViewPort<dyn TerminalView> { fn get_term_view(&self) -> OuterViewPort<dyn TerminalView> {
self.data self.data

View file

@ -6,7 +6,7 @@ pub fn bg_style_from_depth(depth: usize) -> TerminalStyle {
match depth { match depth {
0 => TerminalStyle::bg_color((150,80,230)), 0 => TerminalStyle::bg_color((150,80,230)),
1 => TerminalStyle::bg_color((35,35,35)), 1 => TerminalStyle::bg_color((35,35,35)),
2 => TerminalStyle::bg_color((10,10,10)), 2 => TerminalStyle::bg_color((20,20,20)),
_ => TerminalStyle::default(), _ => TerminalStyle::default(),
} }
} }

91
nested/src/diagnostics.rs Normal file
View file

@ -0,0 +1,91 @@
use {
crate::{
core::{OuterViewPort, ViewPort},
sequence::{SequenceView, SequenceViewExt, decorator::{PTYSeqDecorate, SeqDecorStyle}},
vec::{VecBuffer},
index::{buffer::IndexBuffer},
terminal::{
TerminalView, TerminalStyle, make_label
}
},
cgmath::Point2
};
#[derive(Clone)]
pub struct Message {
pub addr: Vec<usize>,
pub port: OuterViewPort<dyn TerminalView>
}
pub trait Diagnostics {
fn get_msg_port(&self) -> OuterViewPort<dyn SequenceView<Item = Message>> {
VecBuffer::new().get_port().to_sequence()
}
}
pub fn make_error(msg: OuterViewPort<dyn TerminalView>) -> Message {
let mut mb = IndexBuffer::new();
mb.insert_iter(vec![
(Point2::new(0, 0),
make_label("error: ")
.map_item(|p,a| a
.add_style_back(TerminalStyle::bold(true))
.add_style_back(TerminalStyle::fg_color((200,0,0))))
),
(Point2::new(1, 0),
msg
.map_item(|p,a| a
.add_style_back(TerminalStyle::fg_color((180,180,180))))
)
]);
Message {
addr: vec![],
port: mb.get_port().flatten()
}
}
pub fn make_warn(msg: OuterViewPort<dyn TerminalView>) -> Message {
let mut mb = IndexBuffer::new();
mb.insert_iter(vec![
(Point2::new(0, 0),
make_label("warning: ")
.map_item(|p,a| a
.add_style_back(TerminalStyle::bold(true))
.add_style_back(TerminalStyle::fg_color((200,200,0))))
),
(Point2::new(1, 0),
msg
.map_item(|p,a| a
.add_style_back(TerminalStyle::fg_color((180,180,180))))
)
]);
Message {
addr: vec![],
port: mb.get_port().flatten()
}
}
pub fn make_todo(msg: OuterViewPort<dyn TerminalView>) -> Message {
let mut mb = IndexBuffer::new();
mb.insert_iter(vec![
(Point2::new(0, 0),
make_label("todo: ")
.map_item(|p,a| a
.add_style_back(TerminalStyle::bold(true))
.add_style_back(TerminalStyle::fg_color((180,180,250))))
),
(Point2::new(1, 0),
msg
.map_item(|p,a| a
.add_style_back(TerminalStyle::fg_color((180,180,180))))
)
]);
Message {
addr: vec![],
port: mb.get_port().flatten()
}
}

View file

@ -4,23 +4,27 @@ use {
list::{PTYListEditor}, list::{PTYListEditor},
sequence::{SequenceView, SequenceViewExt, decorator::{PTYSeqDecorate, SeqDecorStyle}}, sequence::{SequenceView, SequenceViewExt, decorator::{PTYSeqDecorate, SeqDecorStyle}},
singleton::{SingletonBuffer, SingletonView}, singleton::{SingletonBuffer, SingletonView},
vec::{VecBuffer},
index::{buffer::IndexBuffer},
terminal::{ terminal::{
TerminalAtom, TerminalEditor, TerminalEditorResult, TerminalEvent, TerminalStyle, TerminalAtom, TerminalEditor, TerminalEditorResult, TerminalEvent, TerminalStyle,
TerminalView, TerminalView, make_label
}, },
tree_nav::{TerminalTreeEditor, TreeCursor, TreeNav, TreeNavResult}, tree_nav::{TerminalTreeEditor, TreeCursor, TreeNav, TreeNavResult},
diagnostics::{Diagnostics, Message}
}, },
std::sync::Arc, std::sync::Arc,
std::sync::RwLock, std::sync::RwLock,
termion::event::{Event, Key}, termion::event::{Event, Key},
cgmath::Vector2 cgmath::{Vector2, Point2}
}; };
//<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>> //<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>>
pub struct DigitEditor { pub struct DigitEditor {
radix: u32, radix: u32,
data: SingletonBuffer<Option<char>> data: SingletonBuffer<Option<char>>,
msg: VecBuffer<Message>,
} }
impl DigitEditor { impl DigitEditor {
@ -28,6 +32,7 @@ impl DigitEditor {
DigitEditor { DigitEditor {
radix, radix,
data: SingletonBuffer::new(None), data: SingletonBuffer::new(None),
msg: VecBuffer::new(),
} }
} }
@ -63,11 +68,26 @@ impl TerminalEditor for DigitEditor {
| TerminalEvent::Input(Event::Key(Key::Char('\n'))) => TerminalEditorResult::Exit, | TerminalEvent::Input(Event::Key(Key::Char('\n'))) => TerminalEditorResult::Exit,
TerminalEvent::Input(Event::Key(Key::Char(c))) => { TerminalEvent::Input(Event::Key(Key::Char(c))) => {
self.data.set(Some(*c)); self.data.set(Some(*c));
self.msg.clear();
if c.to_digit(self.radix).is_none() {
let mut mb = IndexBuffer::new();
mb.insert_iter(vec![
(Point2::new(1, 0), make_label("invalid digit '")),
(Point2::new(2, 0), make_label(&format!("{}", *c))
.map_item(|p,a| a.add_style_back(TerminalStyle::fg_color((140,140,250))))),
(Point2::new(3, 0), make_label("'"))
]);
self.msg.push(crate::diagnostics::make_error(mb.get_port().flatten()));
}
TerminalEditorResult::Exit TerminalEditorResult::Exit
} }
TerminalEvent::Input(Event::Key(Key::Backspace)) TerminalEvent::Input(Event::Key(Key::Backspace))
| TerminalEvent::Input(Event::Key(Key::Delete)) => { | TerminalEvent::Input(Event::Key(Key::Delete)) => {
self.data.set(None); self.data.set(None);
self.msg.clear();
self.msg.push(crate::diagnostics::make_warn(make_label("empty digit")));
TerminalEditorResult::Exit TerminalEditorResult::Exit
} }
_ => TerminalEditorResult::Continue, _ => TerminalEditorResult::Continue,
@ -77,6 +97,12 @@ impl TerminalEditor for DigitEditor {
impl TerminalTreeEditor for DigitEditor {} impl TerminalTreeEditor for DigitEditor {}
impl Diagnostics for DigitEditor {
fn get_msg_port(&self) -> OuterViewPort<dyn SequenceView<Item = crate::diagnostics::Message>> {
self.msg.get_port().to_sequence()
}
}
pub struct PosIntEditor { pub struct PosIntEditor {
radix: u32, radix: u32,
digits_editor: PTYListEditor<DigitEditor> digits_editor: PTYListEditor<DigitEditor>
@ -123,6 +149,12 @@ impl PosIntEditor {
} }
} }
impl Diagnostics for PosIntEditor {
fn get_msg_port(&self) -> OuterViewPort<dyn SequenceView<Item = crate::diagnostics::Message>> {
self.digits_editor.get_msg_port()
}
}
impl TreeNav for PosIntEditor { impl TreeNav for PosIntEditor {
fn get_cursor(&self) -> TreeCursor { fn get_cursor(&self) -> TreeCursor {
self.digits_editor.get_cursor() self.digits_editor.get_cursor()
@ -140,10 +172,24 @@ impl TreeNav for PosIntEditor {
impl TerminalEditor for PosIntEditor { impl TerminalEditor for PosIntEditor {
fn get_term_view(&self) -> OuterViewPort<dyn TerminalView> { fn get_term_view(&self) -> OuterViewPort<dyn TerminalView> {
match self.radix {
10 => {
self.digits_editor.editor
.get_seg_seq_view()
.pty_decorate(SeqDecorStyle::Plain, 0)
},
16 => {
self.digits_editor.editor self.digits_editor.editor
.get_seg_seq_view() .get_seg_seq_view()
.pty_decorate(SeqDecorStyle::Hex, 0) .pty_decorate(SeqDecorStyle::Hex, 0)
} }
_ => {
self.digits_editor.editor
.get_seg_seq_view()
.pty_decorate(SeqDecorStyle::Plain, 0)
}
}
}
fn handle_terminal_event(&mut self, event: &TerminalEvent) -> TerminalEditorResult { fn handle_terminal_event(&mut self, event: &TerminalEvent) -> TerminalEditorResult {
match event { match event {

View file

@ -17,9 +17,10 @@ pub mod grid;
pub mod vec; pub mod vec;
// editors // editors
pub mod tree_nav;
pub mod product; pub mod product;
pub mod list; pub mod list;
pub mod tree_nav;
pub mod diagnostics;
// high-level types // high-level types
pub mod char_editor; pub mod char_editor;

View file

@ -13,6 +13,7 @@ use {
TerminalView, TerminalView,
}, },
tree_nav::{TerminalTreeEditor, TreeCursor, TreeNav, TreeNavResult}, tree_nav::{TerminalTreeEditor, TreeCursor, TreeNav, TreeNavResult},
diagnostics::{Diagnostics},
vec::VecBuffer, vec::VecBuffer,
color::{bg_style_from_depth, fg_style_from_depth} color::{bg_style_from_depth, fg_style_from_depth}
}, },
@ -215,6 +216,30 @@ where ItemEditor: TerminalTreeEditor + ?Sized + Send + Sync + 'static
} }
} }
impl<ItemEditor> Diagnostics for PTYListEditor<ItemEditor>
where ItemEditor: TerminalTreeEditor + Diagnostics + ?Sized + Send + Sync + 'static
{
fn get_msg_port(&self) -> OuterViewPort<dyn SequenceView<Item = crate::diagnostics::Message>> {
self.editor
.get_data_port()
.enumerate()
.map(
|(idx, item_editor)| {
let idx = *idx;
item_editor.read().unwrap()
.get_msg_port()
.map(
move |msg| {
let mut msg = msg.clone();
msg.addr.insert(0, idx);
msg
}
)
}
)
.flatten()
}
}
impl<ItemEditor> TerminalTreeEditor for PTYListEditor<ItemEditor> impl<ItemEditor> TerminalTreeEditor for PTYListEditor<ItemEditor>
where ItemEditor: TerminalTreeEditor + ?Sized + Send + Sync + 'static where ItemEditor: TerminalTreeEditor + ?Sized + Send + Sync + 'static

View file

@ -5,13 +5,15 @@ use {
TerminalEditor, TerminalEditorResult, TerminalEditor, TerminalEditorResult,
TerminalEvent, TerminalView TerminalEvent, TerminalView
}, },
sequence::{SequenceView},
tree_nav::{TreeNav, TerminalTreeEditor, TreeNavResult},
vec::{VecBuffer, MutableVecAccess}, vec::{VecBuffer, MutableVecAccess},
index::{buffer::{IndexBuffer, MutableIndexAccess}, IndexView}, index::{buffer::{IndexBuffer, MutableIndexAccess}, IndexView},
list::ListCursorMode, list::ListCursorMode,
product::{segment::ProductEditorSegment}, product::{segment::ProductEditorSegment},
make_editor::make_editor sequence::{SequenceView},
make_editor::make_editor,
tree_nav::{TreeNav, TerminalTreeEditor, TreeNavResult},
diagnostics::{Diagnostics, Message},
}, },
cgmath::{Vector2, Point2}, cgmath::{Vector2, Point2},
std::sync::{Arc, RwLock}, std::sync::{Arc, RwLock},
@ -20,6 +22,8 @@ use {
}; };
pub struct ProductEditor { pub struct ProductEditor {
msg_buf: VecBuffer<Option<OuterViewPort<dyn SequenceView<Item = crate::diagnostics::Message>>>>,
msg_port: OuterViewPort<dyn SequenceView<Item = crate::diagnostics::Message>>,
segments: IndexBuffer<Point2<i16>, ProductEditorSegment>, segments: IndexBuffer<Point2<i16>, ProductEditorSegment>,
pub(super) n_indices: Vec<Point2<i16>>, pub(super) n_indices: Vec<Point2<i16>>,
@ -30,8 +34,28 @@ pub struct ProductEditor {
impl ProductEditor { impl ProductEditor {
pub fn new(depth: usize, ctx: Arc<RwLock<Context>>) -> Self { pub fn new(depth: usize, ctx: Arc<RwLock<Context>>) -> Self {
let msg_buf = VecBuffer::new();
ProductEditor { ProductEditor {
segments: IndexBuffer::new(), segments: IndexBuffer::new(),
msg_port: msg_buf.get_port()
.to_sequence()
.enumerate()
.filter_map(|(idx, msgs): &(usize, Option<OuterViewPort<dyn SequenceView<Item = crate::diagnostics::Message>>>)| {
let idx = *idx;
if let Some(msgs) = msgs {
Some(msgs.map(
move |msg| {
let mut msg = msg.clone();
msg.addr.insert(0, idx);
msg
}))
} else {
None
}
})
.flatten(),
msg_buf,
n_indices: Vec::new(), n_indices: Vec::new(),
ctx, ctx,
cursor: None, cursor: None,
@ -46,13 +70,17 @@ impl ProductEditor {
pub fn with_n(mut self, pos: Point2<i16>, n: TypeLadder) -> Self { pub fn with_n(mut self, pos: Point2<i16>, n: TypeLadder) -> Self {
self.segments.insert(pos, ProductEditorSegment::N{ self.segments.insert(pos, ProductEditorSegment::N{
t: n, t: n.clone(),
editor: None, editor: None,
ed_depth: self.depth + 1, ed_depth: self.depth + 1,
cur_depth: 0, cur_depth: 0,
cur_dist: isize::MAX cur_dist: isize::MAX
}); });
self.n_indices.push(pos); self.n_indices.push(pos);
let mut b = VecBuffer::new();
b.push(crate::diagnostics::make_todo(crate::terminal::make_label(&format!("complete {}", self.ctx.read().unwrap().type_term_to_str(&n[0])))));
self.msg_buf.push(Some(b.get_port().to_sequence()));
self self
} }
@ -101,7 +129,7 @@ impl ProductEditor {
} }
pub fn update_segment(&mut self, idx: isize) { pub fn update_segment(&mut self, idx: isize) {
if let Some(ProductEditorSegment::N{ t: _, editor, ed_depth: _, cur_depth, cur_dist }) = self.get_editor_segment_mut(idx).deref_mut() { if let Some(ProductEditorSegment::N{ t, editor, ed_depth: _, cur_depth, cur_dist }) = self.get_editor_segment_mut(idx).deref_mut() {
let cur = self.get_cursor(); let cur = self.get_cursor();
if cur.tree_addr.len() > 0 { if cur.tree_addr.len() > 0 {
@ -113,6 +141,16 @@ impl ProductEditor {
} else { } else {
*cur_dist = isize::MAX; *cur_dist = isize::MAX;
}; };
if let Some(e) = editor {
self.msg_buf.update(idx as usize, Some(e.read().unwrap().get_msg_port()));
} else {
let mut b = VecBuffer::new();
b.push(crate::diagnostics::make_todo(crate::terminal::make_label(&format!("complete {}", self.ctx.read().unwrap().type_term_to_str(&t[0])))));
self.msg_buf.update(idx as usize, Some(b.get_port().to_sequence()));
}
} else { } else {
unreachable!() unreachable!()
} }
@ -139,14 +177,13 @@ impl TerminalEditor for ProductEditor {
if let Some(ProductEditorSegment::N{ t, editor, ed_depth, cur_depth, cur_dist }) = segment.deref_mut() { if let Some(ProductEditorSegment::N{ t, editor, ed_depth, cur_depth, cur_dist }) = segment.deref_mut() {
*cur_depth = self.get_cursor().tree_addr.len(); *cur_depth = self.get_cursor().tree_addr.len();
if let Some(e) = editor.clone() { let result = if let Some(e) = editor.clone() {
let mut ce = e.write().unwrap(); let mut ce = e.write().unwrap();
match ce.handle_terminal_event(event) { match ce.handle_terminal_event(event) {
TerminalEditorResult::Exit => TerminalEditorResult::Exit =>
match event { match event {
TerminalEvent::Input(Event::Key(Key::Backspace)) => { TerminalEvent::Input(Event::Key(Key::Backspace)) => {
*editor = None; *editor = None;
*cur_depth = 1;
TerminalEditorResult::Continue TerminalEditorResult::Continue
} }
_ => { _ => {
@ -170,7 +207,10 @@ impl TerminalEditor for ProductEditor {
let x = e.write().unwrap().handle_terminal_event(event); let x = e.write().unwrap().handle_terminal_event(event);
*cur_depth = e.write().unwrap().get_cursor().tree_addr.len(); *cur_depth = e.write().unwrap().get_cursor().tree_addr.len();
x x
} };
self.update_cur_segment();
result
} else { } else {
unreachable!() unreachable!()
} }
@ -180,3 +220,10 @@ impl TerminalEditor for ProductEditor {
} }
} }
impl Diagnostics for ProductEditor {
fn get_msg_port(&self) -> OuterViewPort<dyn SequenceView<Item = crate::diagnostics::Message>> {
self.msg_port.clone()
}
}

View file

@ -117,6 +117,9 @@ where
s.cast.notify(&(idx + chunk_offset)); s.cast.notify(&(idx + chunk_offset));
s.cast.notify_each(dirty_idx); s.cast.notify_each(dirty_idx);
} else {
let dirty_idx = s.update_all_offsets();
s.cast.notify_each(dirty_idx);
} }
}, },
), ),
@ -124,7 +127,6 @@ where
); );
chunk_port.0.update(); chunk_port.0.update();
let dirty_idx = self.update_all_offsets(); let dirty_idx = self.update_all_offsets();
self.cast.notify_each(dirty_idx); self.cast.notify_each(dirty_idx);
} else { } else {
@ -161,8 +163,11 @@ where
let old_length = self.length; let old_length = self.length;
self.length = cur_offset; self.length = cur_offset;
/* FIXXME: causes hangup
if self.length < old_length {
dirty_idx.extend(self.length..old_length); dirty_idx.extend(self.length..old_length);
}
*/
dirty_idx dirty_idx
} }

View file

@ -150,6 +150,7 @@ pub trait TreeNav {
} }
use crate::terminal::{TerminalEditor}; use crate::terminal::{TerminalEditor};
use crate::diagnostics::{Diagnostics};
pub trait TerminalTreeEditor : TerminalEditor + TreeNav + Send {} pub trait TerminalTreeEditor : TerminalEditor + TreeNav + Diagnostics + Send {}

View file

@ -8,7 +8,7 @@ use {
nested::{ nested::{
vec::VecBuffer, vec::VecBuffer,
list::{ListEditor, PTYListEditor}, list::{ListEditor, PTYListEditor},
sequence::decorator::{Separate, Wrap, SeqDecorStyle}, sequence::{SequenceView, decorator::{Separate, Wrap, SeqDecorStyle}},
core::{TypeTerm, Context}, core::{TypeTerm, Context},
core::{OuterViewPort, ViewPort}, core::{OuterViewPort, ViewPort},
index::{IndexArea, IndexView}, index::{IndexArea, IndexView},
@ -17,6 +17,7 @@ use {
TerminalAtom, TerminalEditor, TerminalEditorResult, TerminalEvent, TerminalStyle, TerminalView, make_label TerminalAtom, TerminalEditor, TerminalEditorResult, TerminalEvent, TerminalStyle, TerminalView, make_label
}, },
tree_nav::{TreeCursor, TreeNav, TreeNavResult, TerminalTreeEditor}, tree_nav::{TreeCursor, TreeNav, TreeNavResult, TerminalTreeEditor},
diagnostics::{Diagnostics},
make_editor::make_editor, make_editor::make_editor,
product::ProductEditor product::ProductEditor
} }
@ -76,6 +77,22 @@ impl Action for ActCp {
} }
} }
pub struct ActNum {}
impl Action for ActNum {
fn make_editor(&self, ctx: Arc<RwLock<Context>>) -> Arc<RwLock<dyn TerminalTreeEditor + Send + Sync>> {
let depth = 1;
Arc::new(RwLock::new(ProductEditor::new(depth, ctx.clone())
.with_t(Point2::new(1, 1), " Value")
.with_n(Point2::new(0, 1), vec![ ctx.read().unwrap().type_term_from_str("( PosInt 16 BigEndian )").unwrap() ] )
.with_t(Point2::new(1, 2), " Radix")
.with_n(Point2::new(0, 2), vec![ ctx.read().unwrap().type_term_from_str("( PosInt 10 BigEndian )").unwrap() ] )
)) as Arc<RwLock<dyn TerminalTreeEditor + Send + Sync>>
// Arc::new(RwLock::new(nested::integer::PosIntEditor::new(10)))
}
}
pub struct Commander { pub struct Commander {
ctx: Arc<RwLock<Context>>, ctx: Arc<RwLock<Context>>,
cmds: HashMap<String, Arc<dyn Action + Send + Sync>>, cmds: HashMap<String, Arc<dyn Action + Send + Sync>>,
@ -87,6 +104,9 @@ pub struct Commander {
view_elements: VecBuffer<OuterViewPort<dyn TerminalView>>, view_elements: VecBuffer<OuterViewPort<dyn TerminalView>>,
out_port: OuterViewPort<dyn TerminalView>, out_port: OuterViewPort<dyn TerminalView>,
m_buf: VecBuffer<OuterViewPort<dyn SequenceView<Item = nested::diagnostics::Message>>>,
msg_port: OuterViewPort<dyn SequenceView<Item = nested::diagnostics::Message>>
} }
impl Commander { impl Commander {
@ -123,7 +143,9 @@ impl Commander {
cmds.insert("echo".into(), Arc::new(ActEcho{}) as Arc<dyn Action + Send + Sync>); cmds.insert("echo".into(), Arc::new(ActEcho{}) as Arc<dyn Action + Send + Sync>);
cmds.insert("ls".into(), Arc::new(ActLs{}) as Arc<dyn Action + Send + Sync>); cmds.insert("ls".into(), Arc::new(ActLs{}) as Arc<dyn Action + Send + Sync>);
cmds.insert("cp".into(), Arc::new(ActCp{}) as Arc<dyn Action + Send + Sync>); cmds.insert("cp".into(), Arc::new(ActCp{}) as Arc<dyn Action + Send + Sync>);
cmds.insert("num".into(), Arc::new(ActNum{}) as Arc<dyn Action + Send + Sync>);
let m_buf = VecBuffer::new();
let mut c = Commander { let mut c = Commander {
ctx, ctx,
cmds, cmds,
@ -136,7 +158,12 @@ impl Commander {
.to_sequence() .to_sequence()
.separate(make_label(" ")) .separate(make_label(" "))
.to_grid_horizontal() .to_grid_horizontal()
.flatten() .flatten(),
msg_port: m_buf.get_port()
.to_sequence()
.flatten(),
m_buf
}; };
c c
@ -154,6 +181,8 @@ impl TerminalEditor for Commander {
TerminalEvent::Input(Event::Key(Key::Char('\n'))) => { TerminalEvent::Input(Event::Key(Key::Char('\n'))) => {
// run // run
cmd_editor.write().unwrap().goto(TreeCursor::none()); cmd_editor.write().unwrap().goto(TreeCursor::none());
TerminalEditorResult::Exit TerminalEditorResult::Exit
} }
event => { event => {
@ -171,6 +200,8 @@ impl TerminalEditor for Commander {
*self.view_elements.get_mut(1) = editor.read().unwrap().get_term_view(); *self.view_elements.get_mut(1) = editor.read().unwrap().get_term_view();
self.m_buf.push(editor.read().unwrap().get_msg_port());
if *event == TerminalEvent::Input(Event::Key(Key::Char('\n'))) { if *event == TerminalEvent::Input(Event::Key(Key::Char('\n'))) {
return self.handle_terminal_event(event); return self.handle_terminal_event(event);
} }
@ -194,7 +225,6 @@ impl TerminalEditor for Commander {
} else { } else {
*self.view_elements.get_mut(1) = editor.read().unwrap().get_term_view().map_item(|p,a| a.add_style_front(TerminalStyle::fg_color((80,80,80)))); *self.view_elements.get_mut(1) = editor.read().unwrap().get_term_view().map_item(|p,a| a.add_style_front(TerminalStyle::fg_color((80,80,80))));
} }
self.cmd_editor = Some(editor); self.cmd_editor = Some(editor);
*self.valid.write().unwrap() = true; *self.valid.write().unwrap() = true;
} else { } else {
@ -213,6 +243,12 @@ impl TerminalEditor for Commander {
} }
} }
impl Diagnostics for Commander {
fn get_msg_port(&self) -> OuterViewPort<dyn SequenceView<Item = nested::diagnostics::Message>> {
self.msg_port.clone()
}
}
impl TreeNav for Commander { impl TreeNav for Commander {
fn get_cursor(&self) -> TreeCursor { fn get_cursor(&self) -> TreeCursor {
if let (Some(cmd_editor), true) = (self.cmd_editor.as_ref(), self.confirmed) { if let (Some(cmd_editor), true) = (self.cmd_editor.as_ref(), self.confirmed) {
@ -242,7 +278,6 @@ impl TreeNav for Commander {
self.symbol_editor.goto(cur) self.symbol_editor.goto(cur)
} }
} }
} }
impl TerminalTreeEditor for Commander {} impl TerminalTreeEditor for Commander {}

View file

@ -24,6 +24,8 @@ use {
}, },
tree_nav::{TreeNav, TerminalTreeEditor, TreeCursor, TreeNavResult}, tree_nav::{TreeNav, TerminalTreeEditor, TreeCursor, TreeNavResult},
vec::VecBuffer, vec::VecBuffer,
integer::{PosIntEditor},
diagnostics::{Diagnostics}
}, },
std::sync::{Arc, RwLock}, std::sync::{Arc, RwLock},
termion::event::{Event, Key}, termion::event::{Event, Key},
@ -55,7 +57,17 @@ async fn main() {
"PosInt", "Digit", "LittleEndian", "BigEndian", "PosInt", "Digit", "LittleEndian", "BigEndian",
"DiffStream", "", "List", "Path", "Term", "RGB", "Vec3i" "DiffStream", "", "List", "Path", "Term", "RGB", "Vec3i"
] { ctx.write().unwrap().add_typename(tn.into()); } ] { ctx.write().unwrap().add_typename(tn.into()); }
/*
let mut process_list_editor = PTYListEditor::new(
Box::new(
move || {
Arc::new(RwLock::new(PosIntEditor::new(16)))
}
),
SeqDecorStyle::VerticalSexpr,
0
);
*/
let mut process_list_editor = PTYListEditor::new( let mut process_list_editor = PTYListEditor::new(
Box::new({let ctx = ctx.clone(); move || Arc::new(RwLock::new(Commander::new(ctx.clone())))}), Box::new({let ctx = ctx.clone(); move || Arc::new(RwLock::new(Commander::new(ctx.clone())))}),
/* /*
@ -86,19 +98,12 @@ async fn main() {
let mut cur_size = nested::singleton::SingletonBuffer::new(Vector2::new(10, 10)); let mut cur_size = nested::singleton::SingletonBuffer::new(Vector2::new(10, 10));
let mut status_chars = VecBuffer::new(); let mut status_chars = VecBuffer::new();
let mut plist = VecBuffer::new(); let mut plist_port =
let mut plist = VecBuffer::new(); plist.get_port(); async_std::task::spawn(async move { let (w,
let mut plist_port = plist.get_port(); _h) = termion::terminal_size().unwrap(); let mut x: usize = 0;
async_std::task::spawn(async move { loop { let val = (5.0 + (x as f32 / 3.0).sin() * 5.0 + 2.0 +
let (w, _h) = termion::terminal_size().unwrap(); ((7 + x) as f32 / 5.0).sin() * 2.0 + 2.0 + ((9 + x) as f32 /
let mut x: usize = 0; 10.0).cos() * 3.0) as usize;
loop {
let val = (5.0
+ (x as f32 / 3.0).sin() * 5.0
+ 2.0
+ ((7 + x) as f32 / 5.0).sin() * 2.0
+ 2.0
+ ((9 + x) as f32 / 10.0).cos() * 3.0) as usize;
if x < w as usize { if x < w as usize {
plist.push(val); plist.push(val);
@ -133,6 +138,36 @@ async fn main() {
.separate(make_label(" ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~").map_item(|p,a| a.add_style_front(TerminalStyle::fg_color((40,40,40))))) .separate(make_label(" ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~").map_item(|p,a| a.add_style_front(TerminalStyle::fg_color((40,40,40)))))
.to_grid_vertical() .to_grid_vertical()
.flatten()), .flatten()),
(Point2::new(0, 5), make_label(" ")),
(Point2::new(0, 6), make_label("-~~--~~--~~--~~--~~--~~--~~--~~--~~--~~").map_item(|p,a| a.add_style_front(TerminalStyle::fg_color((200,200,200))))),
(Point2::new(0, 7), process_list_editor.get_msg_port().map(
|entry| {
let mut b = VecBuffer::new();
b.push(
make_label("@")
.map_item(|p,a| a
.add_style_back(TerminalStyle::bold(true))
.add_style_back(TerminalStyle::fg_color((180,180,0))))
);
for x in entry.addr.iter() {
b.push(
make_label(&format!("{}", x))
);
b.push(
make_label(".")
.map_item(|p,a| a
.add_style_back(TerminalStyle::bold(true))
.add_style_back(TerminalStyle::fg_color((180,180,0))))
);
}
b.push(entry.port.clone());
b.get_port().to_sequence().to_grid_horizontal().flatten()
}
).to_grid_vertical().flatten())
]); ]);
let (w, h) = termion::terminal_size().unwrap(); let (w, h) = termion::terminal_size().unwrap();
@ -219,7 +254,7 @@ async fn main() {
term_port.inner().get_broadcast().notify(&IndexArea::Full); term_port.inner().get_broadcast().notify(&IndexArea::Full);
continue; continue;
} }
/*
if let Some(process_editor) = process_list_editor.get_item() { if let Some(process_editor) = process_list_editor.get_item() {
let mut pe = process_editor.write().unwrap(); let mut pe = process_editor.write().unwrap();
/* /*
@ -233,7 +268,7 @@ async fn main() {
} }
*/ */
} }
*/
match ev { match ev {
TerminalEvent::Input(Event::Key(Key::Ctrl('d'))) => break, TerminalEvent::Input(Event::Key(Key::Ctrl('d'))) => break,
TerminalEvent::Input(Event::Key(Key::Ctrl('l'))) => { TerminalEvent::Input(Event::Key(Key::Ctrl('l'))) => {
@ -241,7 +276,7 @@ async fn main() {
leaf_mode: ListCursorMode::Insert, leaf_mode: ListCursorMode::Insert,
tree_addr: vec![0], tree_addr: vec![0],
}); });
process_list_editor.clear(); //process_list_editor.clear();
} }
TerminalEvent::Input(Event::Key(Key::Left)) => { TerminalEvent::Input(Event::Key(Key::Left)) => {
process_list_editor.pxev(); process_list_editor.pxev();

View file

@ -11,6 +11,7 @@ use {
TerminalView, TerminalView,
}, },
tree_nav::{TerminalTreeEditor, TreeCursor, TreeNav, TreeNavResult}, tree_nav::{TerminalTreeEditor, TreeCursor, TreeNav, TreeNavResult},
diagnostics::Diagnostics
}, },
std::sync::Arc, std::sync::Arc,
std::sync::RwLock, std::sync::RwLock,
@ -73,6 +74,9 @@ impl TreeNav for ProcessArg {
} }
} }
impl Diagnostics for ProcessArg {
}
impl TerminalTreeEditor for ProcessArg {} impl TerminalTreeEditor for ProcessArg {}
pub struct ProcessLauncher { pub struct ProcessLauncher {
@ -263,4 +267,8 @@ impl TreeNav for ProcessLauncher {
} }
impl Diagnostics for ProcessLauncher {
}
impl TerminalTreeEditor for ProcessLauncher {} impl TerminalTreeEditor for ProcessLauncher {}