From 06c90197da8000de8d1f56db358d90a3c15c16f9 Mon Sep 17 00:00:00 2001 From: Michael Sippel Date: Fri, 28 Oct 2022 10:21:46 +0200 Subject: [PATCH] product editor: update diagnostics view --- nested/src/color.rs | 2 +- nested/src/product/editor.rs | 38 ++++++++++++++++++++++++++++-------- 2 files changed, 31 insertions(+), 9 deletions(-) diff --git a/nested/src/color.rs b/nested/src/color.rs index 5e94396..322a7af 100644 --- a/nested/src/color.rs +++ b/nested/src/color.rs @@ -13,7 +13,7 @@ pub fn bg_style_from_depth(depth: usize) -> TerminalStyle { pub fn fg_style_from_depth(depth: usize) -> TerminalStyle { match depth % 6 { - 0 => TerminalStyle::fg_color((40, 180, 230)), + 0 => TerminalStyle::fg_color((180, 180, 180)), 1 => TerminalStyle::fg_color((120, 120, 120)), 2 => TerminalStyle::fg_color((250, 165, 40)), 3 => TerminalStyle::fg_color((80, 180, 200)), diff --git a/nested/src/product/editor.rs b/nested/src/product/editor.rs index 35a0e7e..3c36be5 100644 --- a/nested/src/product/editor.rs +++ b/nested/src/product/editor.rs @@ -14,6 +14,7 @@ use { tree_nav::{TreeNav, TerminalTreeEditor, TreeNavResult}, diagnostics::{Diagnostics, Message}, + terminal::{TerminalStyle} }, cgmath::{Vector2, Point2}, std::sync::{Arc, RwLock}, @@ -137,6 +138,7 @@ impl ProductEditor { *cur_depth = cur.tree_addr.len(); } + *cur_dist = cur.tree_addr[0] - idx } else { *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]))))); 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 { @@ -173,17 +188,20 @@ impl TerminalEditor for ProductEditor { } 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() { *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(); match ce.handle_terminal_event(event) { TerminalEditorResult::Exit => match event { TerminalEvent::Input(Event::Key(Key::Backspace)) => { *editor = None; + update_segment = true; TerminalEditorResult::Continue } _ => { @@ -203,20 +221,24 @@ impl TerminalEditor for ProductEditor { } else { let e = make_editor(self.ctx.clone(), t, *ed_depth+1); *editor = Some(e.clone()); + update_segment = true; + e.write().unwrap().dn(); 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!() + unreachable!(); + TerminalEditorResult::Exit } } else { TerminalEditorResult::Exit + }; + + if update_segment { + self.update_cur_segment(); } + result } }