From 3588dc29932ca18793f180ac10ff6a1de3b3a9ab Mon Sep 17 00:00:00 2001 From: kjuulh Date: Fri, 10 May 2024 21:54:18 +0200 Subject: [PATCH] feat: it freaking works Signed-off-by: kjuulh --- .../src/components/render_graph/summarize.rs | 87 +++++++------------ 1 file changed, 33 insertions(+), 54 deletions(-) diff --git a/crates/hyperlog-tui/src/components/render_graph/summarize.rs b/crates/hyperlog-tui/src/components/render_graph/summarize.rs index a9638fb..6777c6a 100644 --- a/crates/hyperlog-tui/src/components/render_graph/summarize.rs +++ b/crates/hyperlog-tui/src/components/render_graph/summarize.rs @@ -23,7 +23,7 @@ impl Summarize for MovementGraphItem { ] } GraphItemType::Item { done } => { - vec![Span::from(if done { "- [x] " } else { "- [ ] " }), name] + vec![Span::from(if done { "[x] " } else { "[ ] " }), name] } } } @@ -88,73 +88,52 @@ impl SummarizeRenderGraph for MovementGraph { depth: usize, ) -> Vec> { match items.split_first() { - Some((first, rest)) => match rest.is_empty() { - true => match self.items.get(*first) { - Some(item) => { - let mut output = Vec::new(); + Some((first, rest)) => match self.items.get(*first) { + Some(item) => { + let mut output = Vec::new(); - if *first > 0 { - if let Some(sibling) = self.items.get(*first - 1) { - output.append(&mut sibling.brief()) + if rest.is_empty() { + for item in 0..*first { + if let Some(sibling) = self.items.get(item) { + output.append(&mut sibling.brief()); } } output.append(&mut item.full(true)); - if *first < self.items.len() { - if let Some(sibling) = self.items.get(*first + 1) { - output.append(&mut sibling.brief()) + for item in *first + 1..self.items.len() { + if let Some(sibling) = self.items.get(item) { + output.append(&mut sibling.brief()); } } - - output - } - None => vec![], - }, - false => { - if rest.len() > 1 { - let mut output = Vec::new(); - // TODO: add heading for the current item, and shift lines by one - if let Some(item) = self.items.get(*first) { - output.push(item.heading()) - } - for mut line in self.render_graph_spans(rest, 0) { - line.insert(0, Span::from("~".repeat(4))); - - output.push(line); - } - - output } else { - match self.items.get(*first) { - Some(item) => match item.values.items.get(*rest.first().unwrap()) { - Some(actual_item) => { - let mut output = Vec::new(); + let heading = item.heading(); + output.push(heading); - if *first > 0 { - if let Some(sibling) = self.items.get(*first - 1) { - output.append(&mut sibling.brief()) - } - } - - output.append(&mut actual_item.full(true)); - - if *first < self.items.len() { - if let Some(sibling) = self.items.get(*first + 1) { - output.append(&mut sibling.brief()) - } - } - - output - } - None => vec![], - }, - None => vec![], + let mut next_level = item.values.render_graph_spans(rest, 0); + for item in next_level.iter_mut() { + item.insert(0, Span::raw(" ".repeat(4))); } + output.append(&mut next_level); } + + output + } + None => { + let mut output = Vec::new(); + for item in &self.items { + output.append(&mut item.brief()); + } + output } }, - None => self.items.iter().flat_map(|i| i.brief()).collect_vec(), + None => { + let mut output = Vec::new(); + for item in &self.items { + output.append(&mut item.brief()); + } + output + } } } }