Package asciitree render Ascii trees from a tree struct
It is a Golang implement of Javascript package which is https://www.npmjs.com/package/oo-ascii-tree/v/1.1.0
It implements the oo-ascii-tree
interface as much as possible
package main
import (
"os"
"github.com/YanxinTang/asciitree"
)
func main() {
New := asciitree.New
basicTree := New(
"root",
New("child1"),
New("child2",
New("grandchild1"),
New("grandchild2"),
),
New("child3"),
)
basicTree.PrintTree(os.Stdout)
}
And you will get :
root
├── child1
├─┬ child2
│ ├── grandchild1
│ └── grandchild2
└── child3
package main
import (
"os"
"github.com/YanxinTang/asciitree"
)
func main() {
New := asciitree.New
multiLineTree := New(
"root",
New("child1-1\nchild1-2\nchild-3"),
New("child2",
New("grandchild1"),
New("grandchild2-1\ngrandchild2-2"),
),
New("child3"),
)
multiLineTree.PrintTree(os.Stdout)
}
Output:
root
├── child1-1
│ child1-2
│ child-3
├─┬ child2
│ ├── grandchild1
│ └── grandchild2-1
│ grandchild2-2
└── child3
package main
import (
"os"
"github.com/YanxinTang/asciitree"
)
func main() {
TitleNode := func(text string, children ...*asciitree.ASCIITree) *asciitree.ASCIITree {
title := fmt.Sprintf("%s\n%s", strings.ToUpper(text), strings.Repeat("=", len(text)))
return asciitree.New(title, children...)
}
New := asciitree.New
titleTree := New(
"root",
TitleNode("child1"),
TitleNode("child2",
asciitree.New("grandchild1"),
asciitree.New("grandchild2"),
),
asciitree.New("child3"),
)
titleTree.PrintTree(os.Stdout)
}
Output:
root
├── CHILD1
│ ======
├─┬ CHILD2
│ │ ======
│ ├── grandchild1
│ └── grandchild2
└── child3