MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / render

Method render

atomic-cli/src/commands/change/tree.rs:31–49  ·  view source on GitHub ↗
(&self)

Source from the content-addressed store, hash-verified

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
52fn clean(value: &str) -> String {

Calls 5

collectMethod · 0.45
iterMethod · 0.45
lenMethod · 0.45
pushMethod · 0.45
cloneMethod · 0.45