product editor: update diagnostics view

This commit is contained in:
Michael Sippel 2022-10-28 10:21:46 +02:00
parent 8eea49a688
commit 06c90197da
2 changed files with 31 additions and 9 deletions

View file

@ -13,7 +13,7 @@ pub fn bg_style_from_depth(depth: usize) -> TerminalStyle {
pub fn fg_style_from_depth(depth: usize) -> TerminalStyle { pub fn fg_style_from_depth(depth: usize) -> TerminalStyle {
match depth % 6 { match depth % 6 {
0 => TerminalStyle::fg_color((40, 180, 230)), 0 => TerminalStyle::fg_color((180, 180, 180)),
1 => TerminalStyle::fg_color((120, 120, 120)), 1 => TerminalStyle::fg_color((120, 120, 120)),
2 => TerminalStyle::fg_color((250, 165, 40)), 2 => TerminalStyle::fg_color((250, 165, 40)),
3 => TerminalStyle::fg_color((80, 180, 200)), 3 => TerminalStyle::fg_color((80, 180, 200)),

View file

@ -14,6 +14,7 @@ use {
tree_nav::{TreeNav, TerminalTreeEditor, TreeNavResult}, tree_nav::{TreeNav, TerminalTreeEditor, TreeNavResult},
diagnostics::{Diagnostics, Message}, diagnostics::{Diagnostics, Message},
terminal::{TerminalStyle}
}, },
cgmath::{Vector2, Point2}, cgmath::{Vector2, Point2},
std::sync::{Arc, RwLock}, std::sync::{Arc, RwLock},
@ -137,6 +138,7 @@ impl ProductEditor {
*cur_depth = cur.tree_addr.len(); *cur_depth = cur.tree_addr.len();
} }
*cur_dist = cur.tree_addr[0] - idx *cur_dist = cur.tree_addr[0] - idx
} else { } else {
*cur_dist = isize::MAX; *cur_dist = isize::MAX;
@ -149,6 +151,19 @@ impl ProductEditor {
b.push(crate::diagnostics::make_todo(crate::terminal::make_label(&format!("complete {}", self.ctx.read().unwrap().type_term_to_str(&t[0]))))); 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())); self.msg_buf.update(idx as usize, Some(b.get_port().to_sequence()));
if cur.tree_addr.len() > 0 {
if cur.tree_addr[0] == idx {
self.msg_buf.update(idx as usize, Some(b.get_port().to_sequence().map(
|msg| {
let mut msg = msg.clone();
msg.port = msg.port.map_item(|p,a| a.add_style_back(TerminalStyle::bg_color((40,40,40))));
msg
}
)));
}
}
} }
} else { } else {
@ -173,17 +188,20 @@ impl TerminalEditor for ProductEditor {
} }
fn handle_terminal_event(&mut self, event: &TerminalEvent) -> TerminalEditorResult { fn handle_terminal_event(&mut self, event: &TerminalEvent) -> TerminalEditorResult {
if let Some(mut segment) = self.get_cur_segment_mut().as_deref_mut() { let mut update_segment = false;
let result = if let Some(mut segment) = self.get_cur_segment_mut().as_deref_mut() {
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();
let result = if let Some(e) = editor.clone() { 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;
update_segment = true;
TerminalEditorResult::Continue TerminalEditorResult::Continue
} }
_ => { _ => {
@ -203,20 +221,24 @@ impl TerminalEditor for ProductEditor {
} else { } else {
let e = make_editor(self.ctx.clone(), t, *ed_depth+1); let e = make_editor(self.ctx.clone(), t, *ed_depth+1);
*editor = Some(e.clone()); *editor = Some(e.clone());
update_segment = true;
e.write().unwrap().dn(); e.write().unwrap().dn();
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();
x x
}; }
self.update_cur_segment();
result
} else { } else {
unreachable!() unreachable!();
TerminalEditorResult::Exit
} }
} else { } else {
TerminalEditorResult::Exit TerminalEditorResult::Exit
};
if update_segment {
self.update_cur_segment();
} }
result
} }
} }