How treeprint works
masterThe treeprint package allows you to build and render ASCII trees using a fluent API.
- Initialize: Create a new tree using
treeprint.New()(ortreeprint.NewWithRoot(name)for a custom root). - Build Structure:
- Use
AddNode(name)to add a node at the current level. - Use
AddBranch(name)to create a new level (a branch) and descend into it.
- Use
- Render: Call
.String()or.Bytes()on the root tree or a specific branch to get the ASCII representation of that subtree.
tree := treeprint.New()
// Add a branch and descend
branch := tree.AddBranch("folder")
// Add nodes inside that branch
branch.AddNode("file1").AddNode("file2")
// Print the whole tree
fmt.Println(tree.String())