| 284 | } |
| 285 | |
| 286 | fn render(&self) -> String { |
| 287 | fn clean(label: &str) -> String { |
| 288 | label |
| 289 | .chars() |
| 290 | .map(|c| if c.is_control() { ' ' } else { c }) |
| 291 | .collect() |
| 292 | } |
| 293 | let mut out = format!("{}\n", clean(&self.label)); |
| 294 | let mut pending: Vec<_> = self |
| 295 | .children |
| 296 | .iter() |
| 297 | .enumerate() |
| 298 | .rev() |
| 299 | .map(|(i, child)| (child, String::new(), i + 1 == self.children.len())) |
| 300 | .collect(); |
| 301 | while let Some((node, prefix, last)) = pending.pop() { |
| 302 | let branch = if last { "└──" } else { "├──" }; |
| 303 | out.push_str(&format!("{prefix}{branch} {}\n", clean(&node.label))); |
| 304 | let prefix = format!("{prefix}{}", if last { " " } else { "│ " }); |
| 305 | for (i, child) in node.children.iter().enumerate().rev() { |
| 306 | pending.push((child, prefix.clone(), i + 1 == node.children.len())); |
| 307 | } |
| 308 | } |
| 309 | out |
| 310 | } |
| 311 | } |
| 312 | |
| 313 | fn render_memory_cli(node: &MemoryNode) -> String { |