| 29 | } |
| 30 | |
| 31 | fn render(&self) -> String { |
| 32 | let mut out = format!("{}\n", clean(&self.label)); |
| 33 | let mut pending: Vec<_> = self |
| 34 | .children |
| 35 | .iter() |
| 36 | .enumerate() |
| 37 | .rev() |
| 38 | .map(|(i, child)| (child, String::new(), i + 1 == self.children.len())) |
| 39 | .collect(); |
| 40 | while let Some((node, prefix, last)) = pending.pop() { |
| 41 | let branch = if last { "└──" } else { "├──" }; |
| 42 | out.push_str(&format!("{prefix}{branch} {}\n", clean(&node.label))); |
| 43 | let prefix = format!("{prefix}{}", if last { " " } else { "│ " }); |
| 44 | for (i, child) in node.children.iter().enumerate().rev() { |
| 45 | pending.push((child, prefix.clone(), i + 1 == node.children.len())); |
| 46 | } |
| 47 | } |
| 48 | out |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | fn clean(value: &str) -> String { |