Textree
:deciduous_tree: Pretty print nested trees in go
Install / Use
/learn @plouc/TextreeREADME
textree
textree is a go package to easily pretty print nested trees in plain text.
Install
go get github.com/plouc/textree
Usage
import (
"os"
"github.com/plouc/textree"
)
Construct a tree:
root := textree.NewNode("1")
childA := textree.NewNode("1.1")
root.Append(childA)
childA.Append(textree.NewNode("1.1.1"))
childA.Append(textree.NewNode("1.1.2"))
childB := textree.NewNode("1.2")
root.Append(childB)
childB.Append(textree.NewNode("1.2.1"))
Then render the tree using the root element:
o := textree.NewRenderOptions()
root.Render(os.Stdout, o)
Listing a directory
You can get something similar to the tree command.
tree, err := textTree.TreeFromDir("./")
if err != nil {
fmt.Printf("%v\n", err)
return
}
tree.Render(os.Stdout, textree.NewRenderOptions())
For complete usage of textree, see the full package docs.
Examples
Some examples are available in the examples/ directory.
go run examples/main.go
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Basic example
using default options
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
┌ ROOT
│
└──┬ 1
│
├──┬ 1.1
│ │
│ ├─── 1.1.1
│ └─── 1.1.2
│
├──┬ 1.2
│ │
│ └─── 1.2.1
│
├──┬ 1.3
│ │
│ ├─── 1.3.1
│ ├──┬ 1.3.2
│ │ │
│ │ ├─── 1.3.2.1
│ │ └─── 1.3.2.2
│ │
│ └─── 1.3.3
│
├─── 1.4
└─── 1.5
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Dotted example
using RenderOptions.Dotted()
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
┌ ROOT
:
···· 1
:
:··· 1.1
: :
: :··· 1.1.1
: ···· 1.1.2
:
:··· 1.2
: :
: ···· 1.2.1
:
:··· 1.3
: :
: :··· 1.3.1
: :··· 1.3.2
: : :
: : :··· 1.3.2.1
: : ···· 1.3.2.2
: :
: ···· 1.3.3
:
:··· 1.4
···· 1.5
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Rounded example
using RenderOptions.Rounded()
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
┌ ROOT
│
╰──╮ 1
│
├──╮ 1.1
│ │
│ ├─── 1.1.1
│ ╰─── 1.1.2
│
├──╮ 1.2
│ │
│ ╰─── 1.2.1
│
├──╮ 1.3
│ │
│ ├─── 1.3.1
│ ├──╮ 1.3.2
│ │ │
│ │ ├─── 1.3.2.1
│ │ ╰─── 1.3.2.2
│ │
│ ╰─── 1.3.3
│
├─── 1.4
╰─── 1.5
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Compact example
using RenderOptions.Compact()
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
┌ ROOT
└─┬ 1
├─┬ 1.1
│ ├── 1.1.1
│ └── 1.1.2
├─┬ 1.2
│ └── 1.2.1
├─┬ 1.3
│ ├── 1.3.1
│ ├─┬ 1.3.2
│ │ ├── 1.3.2.1
│ │ └── 1.3.2.2
│ └── 1.3.3
├── 1.4
└── 1.5
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Directory listing example
using TreeFromDir()
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
┌ ./snapshots
│
├─── basic.snap
├─── dotted.snap
└─── rounded.snap
Related Skills
node-connect
349.9kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
xurl
349.9kA CLI tool for making authenticated requests to the X (Twitter) API. Use this skill when you need to post tweets, reply, quote, search, read posts, manage followers, send DMs, upload media, or interact with any X API v2 endpoint.
frontend-design
109.8kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
349.9kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).

