add diagnostics; contanis some bugs
This commit is contained in:
parent
906cc51329
commit
b2f437d7df
12 changed files with 340 additions and 43 deletions
nested/src
|
@ -9,6 +9,7 @@ use {
|
|||
TerminalView,
|
||||
},
|
||||
tree_nav::{TerminalTreeEditor, TreeCursor, TreeNav, TreeNavResult},
|
||||
diagnostics::Diagnostics
|
||||
},
|
||||
std::sync::Arc,
|
||||
std::sync::RwLock,
|
||||
|
@ -37,6 +38,8 @@ impl CharEditor {
|
|||
}
|
||||
|
||||
impl TreeNav for CharEditor {}
|
||||
impl Diagnostics for CharEditor {}
|
||||
|
||||
impl TerminalEditor for CharEditor {
|
||||
fn get_term_view(&self) -> OuterViewPort<dyn TerminalView> {
|
||||
self.data
|
||||
|
|
|
@ -6,7 +6,7 @@ pub fn bg_style_from_depth(depth: usize) -> TerminalStyle {
|
|||
match depth {
|
||||
0 => TerminalStyle::bg_color((150,80,230)),
|
||||
1 => TerminalStyle::bg_color((35,35,35)),
|
||||
2 => TerminalStyle::bg_color((10,10,10)),
|
||||
2 => TerminalStyle::bg_color((20,20,20)),
|
||||
_ => TerminalStyle::default(),
|
||||
}
|
||||
}
|
||||
|
|
91
nested/src/diagnostics.rs
Normal file
91
nested/src/diagnostics.rs
Normal 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()
|
||||
}
|
||||
}
|
||||
|
|
@ -4,23 +4,27 @@ use {
|
|||
list::{PTYListEditor},
|
||||
sequence::{SequenceView, SequenceViewExt, decorator::{PTYSeqDecorate, SeqDecorStyle}},
|
||||
singleton::{SingletonBuffer, SingletonView},
|
||||
vec::{VecBuffer},
|
||||
index::{buffer::IndexBuffer},
|
||||
terminal::{
|
||||
TerminalAtom, TerminalEditor, TerminalEditorResult, TerminalEvent, TerminalStyle,
|
||||
TerminalView,
|
||||
TerminalView, make_label
|
||||
},
|
||||
tree_nav::{TerminalTreeEditor, TreeCursor, TreeNav, TreeNavResult},
|
||||
diagnostics::{Diagnostics, Message}
|
||||
},
|
||||
std::sync::Arc,
|
||||
std::sync::RwLock,
|
||||
termion::event::{Event, Key},
|
||||
cgmath::Vector2
|
||||
cgmath::{Vector2, Point2}
|
||||
};
|
||||
|
||||
//<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>>
|
||||
|
||||
pub struct DigitEditor {
|
||||
radix: u32,
|
||||
data: SingletonBuffer<Option<char>>
|
||||
data: SingletonBuffer<Option<char>>,
|
||||
msg: VecBuffer<Message>,
|
||||
}
|
||||
|
||||
impl DigitEditor {
|
||||
|
@ -28,6 +32,7 @@ impl DigitEditor {
|
|||
DigitEditor {
|
||||
radix,
|
||||
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(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
|
||||
}
|
||||
TerminalEvent::Input(Event::Key(Key::Backspace))
|
||||
| TerminalEvent::Input(Event::Key(Key::Delete)) => {
|
||||
self.data.set(None);
|
||||
self.msg.clear();
|
||||
self.msg.push(crate::diagnostics::make_warn(make_label("empty digit")));
|
||||
TerminalEditorResult::Exit
|
||||
}
|
||||
_ => TerminalEditorResult::Continue,
|
||||
|
@ -77,6 +97,12 @@ impl TerminalEditor 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 {
|
||||
radix: u32,
|
||||
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 {
|
||||
fn get_cursor(&self) -> TreeCursor {
|
||||
self.digits_editor.get_cursor()
|
||||
|
@ -140,9 +172,23 @@ impl TreeNav for PosIntEditor {
|
|||
|
||||
impl TerminalEditor for PosIntEditor {
|
||||
fn get_term_view(&self) -> OuterViewPort<dyn TerminalView> {
|
||||
self.digits_editor.editor
|
||||
.get_seg_seq_view()
|
||||
.pty_decorate(SeqDecorStyle::Hex, 0)
|
||||
match self.radix {
|
||||
10 => {
|
||||
self.digits_editor.editor
|
||||
.get_seg_seq_view()
|
||||
.pty_decorate(SeqDecorStyle::Plain, 0)
|
||||
},
|
||||
16 => {
|
||||
self.digits_editor.editor
|
||||
.get_seg_seq_view()
|
||||
.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 {
|
||||
|
|
|
@ -17,9 +17,10 @@ pub mod grid;
|
|||
pub mod vec;
|
||||
|
||||
// editors
|
||||
pub mod tree_nav;
|
||||
pub mod product;
|
||||
pub mod list;
|
||||
pub mod tree_nav;
|
||||
pub mod diagnostics;
|
||||
|
||||
// high-level types
|
||||
pub mod char_editor;
|
||||
|
|
|
@ -13,6 +13,7 @@ use {
|
|||
TerminalView,
|
||||
},
|
||||
tree_nav::{TerminalTreeEditor, TreeCursor, TreeNav, TreeNavResult},
|
||||
diagnostics::{Diagnostics},
|
||||
vec::VecBuffer,
|
||||
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>
|
||||
where ItemEditor: TerminalTreeEditor + ?Sized + Send + Sync + 'static
|
||||
|
|
|
@ -5,13 +5,15 @@ use {
|
|||
TerminalEditor, TerminalEditorResult,
|
||||
TerminalEvent, TerminalView
|
||||
},
|
||||
sequence::{SequenceView},
|
||||
tree_nav::{TreeNav, TerminalTreeEditor, TreeNavResult},
|
||||
vec::{VecBuffer, MutableVecAccess},
|
||||
index::{buffer::{IndexBuffer, MutableIndexAccess}, IndexView},
|
||||
list::ListCursorMode,
|
||||
product::{segment::ProductEditorSegment},
|
||||
make_editor::make_editor
|
||||
sequence::{SequenceView},
|
||||
make_editor::make_editor,
|
||||
|
||||
tree_nav::{TreeNav, TerminalTreeEditor, TreeNavResult},
|
||||
diagnostics::{Diagnostics, Message},
|
||||
},
|
||||
cgmath::{Vector2, Point2},
|
||||
std::sync::{Arc, RwLock},
|
||||
|
@ -20,6 +22,8 @@ use {
|
|||
};
|
||||
|
||||
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>,
|
||||
pub(super) n_indices: Vec<Point2<i16>>,
|
||||
|
||||
|
@ -30,8 +34,28 @@ pub struct ProductEditor {
|
|||
|
||||
impl ProductEditor {
|
||||
pub fn new(depth: usize, ctx: Arc<RwLock<Context>>) -> Self {
|
||||
let msg_buf = VecBuffer::new();
|
||||
ProductEditor {
|
||||
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(),
|
||||
ctx,
|
||||
cursor: None,
|
||||
|
@ -42,17 +66,21 @@ impl ProductEditor {
|
|||
pub fn with_t(mut self, pos: Point2<i16>, t: &str) -> Self {
|
||||
self.segments.insert(pos, ProductEditorSegment::T(t.to_string(), self.depth));
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
pub fn with_n(mut self, pos: Point2<i16>, n: TypeLadder) -> Self {
|
||||
self.segments.insert(pos, ProductEditorSegment::N{
|
||||
t: n,
|
||||
t: n.clone(),
|
||||
editor: None,
|
||||
ed_depth: self.depth + 1,
|
||||
cur_depth: 0,
|
||||
cur_dist: isize::MAX
|
||||
});
|
||||
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
|
||||
}
|
||||
|
||||
|
@ -101,7 +129,7 @@ impl ProductEditor {
|
|||
}
|
||||
|
||||
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();
|
||||
|
||||
if cur.tree_addr.len() > 0 {
|
||||
|
@ -113,6 +141,16 @@ impl ProductEditor {
|
|||
} else {
|
||||
*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 {
|
||||
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() {
|
||||
*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();
|
||||
match ce.handle_terminal_event(event) {
|
||||
TerminalEditorResult::Exit =>
|
||||
match event {
|
||||
TerminalEvent::Input(Event::Key(Key::Backspace)) => {
|
||||
*editor = None;
|
||||
*cur_depth = 1;
|
||||
TerminalEditorResult::Continue
|
||||
}
|
||||
_ => {
|
||||
|
@ -170,7 +207,10 @@ impl TerminalEditor for ProductEditor {
|
|||
let x = e.write().unwrap().handle_terminal_event(event);
|
||||
*cur_depth = e.write().unwrap().get_cursor().tree_addr.len();
|
||||
x
|
||||
}
|
||||
};
|
||||
|
||||
self.update_cur_segment();
|
||||
result
|
||||
} else {
|
||||
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()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -117,6 +117,9 @@ where
|
|||
|
||||
s.cast.notify(&(idx + chunk_offset));
|
||||
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();
|
||||
|
||||
let dirty_idx = self.update_all_offsets();
|
||||
self.cast.notify_each(dirty_idx);
|
||||
} else {
|
||||
|
@ -161,8 +163,11 @@ where
|
|||
|
||||
let old_length = self.length;
|
||||
self.length = cur_offset;
|
||||
|
||||
dirty_idx.extend(self.length..old_length);
|
||||
/* FIXXME: causes hangup
|
||||
if self.length < old_length {
|
||||
dirty_idx.extend(self.length..old_length);
|
||||
}
|
||||
*/
|
||||
dirty_idx
|
||||
}
|
||||
|
||||
|
|
|
@ -150,6 +150,7 @@ pub trait TreeNav {
|
|||
}
|
||||
|
||||
use crate::terminal::{TerminalEditor};
|
||||
use crate::diagnostics::{Diagnostics};
|
||||
|
||||
pub trait TerminalTreeEditor : TerminalEditor + TreeNav + Send {}
|
||||
pub trait TerminalTreeEditor : TerminalEditor + TreeNav + Diagnostics + Send {}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue