feat: it freaking works
All checks were successful
continuous-integration/drone/push Build is passing

Signed-off-by: kjuulh <contact@kjuulh.io>
This commit is contained in:
Kasper Juul Hermansen 2024-05-10 21:54:18 +02:00
parent 4a36116300
commit 3588dc2993
Signed by: kjuulh
GPG Key ID: 57B6E1465221F912

View File

@ -23,7 +23,7 @@ impl Summarize for MovementGraphItem {
] ]
} }
GraphItemType::Item { done } => { 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, depth: usize,
) -> Vec<Vec<ratatui::prelude::Span>> { ) -> Vec<Vec<ratatui::prelude::Span>> {
match items.split_first() { match items.split_first() {
Some((first, rest)) => match rest.is_empty() { Some((first, rest)) => match self.items.get(*first) {
true => match self.items.get(*first) { Some(item) => {
Some(item) => { let mut output = Vec::new();
let mut output = Vec::new();
if *first > 0 { if rest.is_empty() {
if let Some(sibling) = self.items.get(*first - 1) { for item in 0..*first {
output.append(&mut sibling.brief()) if let Some(sibling) = self.items.get(item) {
output.append(&mut sibling.brief());
} }
} }
output.append(&mut item.full(true)); output.append(&mut item.full(true));
if *first < self.items.len() { for item in *first + 1..self.items.len() {
if let Some(sibling) = self.items.get(*first + 1) { if let Some(sibling) = self.items.get(item) {
output.append(&mut sibling.brief()) 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 { } else {
match self.items.get(*first) { let heading = item.heading();
Some(item) => match item.values.items.get(*rest.first().unwrap()) { output.push(heading);
Some(actual_item) => {
let mut output = Vec::new();
if *first > 0 { let mut next_level = item.values.render_graph_spans(rest, 0);
if let Some(sibling) = self.items.get(*first - 1) { for item in next_level.iter_mut() {
output.append(&mut sibling.brief()) item.insert(0, Span::raw(" ".repeat(4)));
}
}
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![],
} }
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
}
} }
} }
} }