Expand description
Generic tree visualization for consortium CLIs.
Mirrors tree -L N and nh-style output: depth-limited box-drawing
tree with optional colored status badges. Plus machine-friendly
formats — JSON, YAML, TOML — emitted from the same data model so
--format json / --format tree produce different surface
renderings of the same underlying tree.
§Usage
Implement TreeNode for whatever you want to visualize. The
renderer walks the tree generically.
use consortium_cli::tree::{render, NodeStatus, OutputFormat, TreeNode};
struct Pkg {
name: String,
status: NodeStatus,
deps: Vec<Pkg>,
}
impl TreeNode for Pkg {
fn label(&self) -> String { self.name.clone() }
fn status(&self) -> Option<NodeStatus> { Some(self.status.clone()) }
fn children(&self) -> Vec<&dyn TreeNode> {
self.deps.iter().map(|c| c as &dyn TreeNode).collect()
}
}
let root = Pkg {
name: "your-system".into(),
status: NodeStatus::Ok,
deps: vec![Pkg {
name: "hello-2.12.1".into(),
status: NodeStatus::InProgress,
deps: vec![],
}],
};
// tree -L 2 with colors
let txt = render(&root, &OutputFormat::Tree {
max_depth: Some(2),
color: true,
});
// machine output
let json = render(&root, &OutputFormat::Json);
let yaml = render(&root, &OutputFormat::Yaml);
let toml = render(&root, &OutputFormat::Toml);Enums§
- Node
Status - Status badge rendered next to a node.
Customlets callers add domain-specific badges without bloating this enum. - Output
Format - What the renderer should produce.
Traits§
- Tree
Node - A node in a tree. Implementors provide a label, optional status, optional metadata key/value pairs (rendered as a sub-line under the node label), and a list of children.
Functions§
- render
- Render
rootasformat. The renderer walksroot.children()recursively — implementors are responsible for cycle prevention (most cascade / dep / dag trees are naturally acyclic).