| 242 | } |
| 243 | |
| 244 | fn render(&self) -> String { |
| 245 | fn clean(label: &str) -> String { |
| 246 | label |
| 247 | .chars() |
| 248 | .map(|c| if c.is_control() { ' ' } else { c }) |
| 249 | .collect() |
| 250 | } |
| 251 | let mut out = format!("{}\n", clean(&self.label)); |
| 252 | let mut pending: Vec<_> = self |
| 253 | .children |
| 254 | .iter() |
| 255 | .enumerate() |
| 256 | .rev() |
| 257 | .map(|(i, child)| (child, String::new(), i + 1 == self.children.len())) |
| 258 | .collect(); |
| 259 | while let Some((node, prefix, last)) = pending.pop() { |
| 260 | let branch = if last { "└──" } else { "├──" }; |
| 261 | out.push_str(&format!("{prefix}{branch} {}\n", clean(&node.label))); |
| 262 | let prefix = format!("{prefix}{}", if last { " " } else { "│ " }); |
| 263 | for (i, child) in node.children.iter().enumerate().rev() { |
| 264 | pending.push((child, prefix.clone(), i + 1 == node.children.len())); |
| 265 | } |
| 266 | } |
| 267 | out |
| 268 | } |
| 269 | } |
| 270 | |
| 271 | fn render_memory_cli(node: &MemoryNode) -> String { |