MCPcopy Create free account
hub / github.com/csskit/csskit / build_prefix

Method build_prefix

crates/csskit/src/commands/tree.rs:170–185  ·  view source on GitHub ↗

Build the tree prefix (vertical bars and connectors) for a node.

(&self, visitor: &CollectionVisitor, node_idx: usize, node_depth: usize)

Source from the content-addressed store, hash-verified

168
169 /// Build the tree prefix (vertical bars and connectors) for a node.
170 fn build_prefix(&self, visitor: &CollectionVisitor, node_idx: usize, node_depth: usize) -> String {
171 let mut prefix = String::new();
172
173 // For each ancestor level, determine if we need a vertical bar
174 for d in 0..node_depth.saturating_sub(1) {
175 let ancestor_idx = visitor.find_ancestor_at_depth(node_idx, d + 1);
176 let show_bar = ancestor_idx.is_none_or(|idx| !visitor.is_last_child(idx));
177 prefix.push_str(if show_bar { "│ " } else { " " });
178 }
179
180 // Add the connector for this node
181 let connector = if visitor.is_last_child(node_idx) { "╰─ " } else { "├─ " };
182 prefix.push_str(connector);
183
184 prefix
185 }
186}

Callers 1

runMethod · 0.80

Calls 2

is_last_childMethod · 0.45

Tested by

no test coverage detected