spruce/tree
Pure nested tree rendering.
Trees use the context’s symbol mode for branch glyphs by default.
Call unicode or ascii to force a specific mode, or branches for
custom glyphs.
Types
The four tokens used to draw tree branches.
pub type BranchChars {
BranchChars(
branch_mid: String,
branch_last: String,
pipe: String,
blank: String,
)
}
Constructors
-
BranchChars( branch_mid: String, branch_last: String, pipe: String, blank: String, )
Values
pub fn branches(tree: Tree, chars: BranchChars) -> Tree
Set all four branch tokens used to render the tree.
pub fn child(parent: Tree, child child: Tree) -> Tree
Add a child to parent, preserving insertion order.
pub fn columns(tree: Tree, columns: List(String)) -> Tree
Set cells that render_table places after this node’s label.
pub fn render_table(context: spruce.Spruce, tree: Tree) -> String
Render labels and their columns as an aligned, borderless table.
The tree label is the first column. Cell widths are ANSI-aware, and multi-line labels and cells preserve the tree’s continuation guides.
pub fn render_with(
context: spruce.Spruce,
tree: Tree,
render_label: fn(String, Int, Int, Bool) -> String,
) -> String
Render a tree with a function that can transform each label.
The function receives the label, its prefix’s visual width, its zero-based depth, and whether it is the last child. The root has depth zero and is always marked as last.