A command line tool for drawing tree structures with ascii characters.
Install from crates.io https://crates.io/crates/astree:
cargo install astree
Check out the help message:
```
$ astree -h
A command line tool for drawing tree structures with ascii characters
Usage: astree
Commands: vertical Print the tree virtually horizontal Print the tree horizontally help Print this message or the help of the given subcommand(s)
Options:
-h, --help Print help information (use --help
for more detail)
-V, --version Print version information
```
For example, we can use it like this:
``` astree horizontal -i "$(cat << 'EOF'
EOF )" ```
Here, each additional #
indicates a nested child.
Output:
Root
└─ Child 1
├─ Grandchild 1
└─ Grandchild 2
Alternatively, we can also save the markdown file, such as tree.md
.
```
```
And invoke the command like so:
astree horizontal -i tree.md
Output:
Root
└─ Child 1
├─ Grandchild 1
└─ Grandchild 2
Example of drawing a horizontal tree:
$ astree horizontal -i examples/with_grandchildren_0.md
Root
├─ Child 1
│ ├─ Grandchild 1.1
│ └─ Grandchild 1.2
├─ Child 2
│ └─ Child 2.1
└─ Child 3
Example of drawing a tree with multiple root nodes:
$ astree horizontal -i examples/multi_tree.md
.
├─ Root 1
│ ├─ Child 1.1
│ │ ├─ Grandchild 1.1.1
│ │ └─ Grandchild 1.1.2
│ └─ Child 1.2
└─ Root 2
└─ Child 2.1
Example of drawing a vertical tree:
astree vertical --input examples/with_grandchildren_1.md
┌──────â”
│ Root │
└──┬───┘
┌────┴────â”
│ Child 1 │
└────┬────┘
┌────────┴────────â”
┌──────┴───────┠┌──────┴───────â”
│ Grandchild 1 │ │ Grandchild 2 │
└──────────────┘ └──────────────┘
Example of drawing a forest with multiple root nodes:
$ astree vertical -i examples/multi_tree.md
┌────────â”
│ Root 1 │
└───┬────┘
┌──────────────┴──────────────â”
┌─────┴─────┠┌─────┴─────â”
│ Child 1.1 │ │ Child 1.2 │
└─────┬─────┘ └───────────┘
┌──────────┴──────────â”
┌────────┴─────────┠┌────────┴─────────â”
│ Grandchild 1.1.1 │ │ Grandchild 1.1.2 │
└──────────────────┘ └──────────────────┘
┌────────â”
│ Root 2 │
└───┬────┘
┌─────┴─────â”
│ Child 2.1 │
└───────────┘
With thick lines:
astree vertical --input examples/with_grandchildren_1.md --style thick
â”â”â”â”â”â”â”┓
┃ Root ┃
â”—â”â”┳â”â”â”â”›
â”â”â”â”â”â”»â”â”â”â”┓
┃ Child 1 ┃
â”—â”â”â”â”┳â”â”â”â”â”›
â”â”â”â”â”â”â”â”â”â”»â”â”â”â”â”â”â”â”┓
â”â”â”â”â”â”â”â”»â”â”â”â”â”â”â”┓ â”â”â”â”â”â”â”â”»â”â”â”â”â”â”â”┓
┃ Grandchild 1 ┃ ┃ Grandchild 2 ┃
â”—â”â”â”â”â”â”â”â”â”â”â”â”â”â”â”› â”—â”â”â”â”â”â”â”â”â”â”â”â”â”â”â”›
With double lines:
astree vertical --input examples/with_grandchildren_1.md --style double
â•”â•â•â•â•â•â•â•—
â•‘ Root â•‘
â•šâ•â•â•¦â•â•â•â•
â•”â•â•â•â•â•©â•â•â•â•â•—
â•‘ Child 1 â•‘
â•šâ•â•â•â•â•¦â•â•â•â•â•
â•”â•â•â•â•â•â•â•â•â•©â•â•â•â•â•â•â•â•â•—
â•”â•â•â•â•â•â•â•©â•â•â•â•â•â•â•â•— â•”â•â•â•â•â•â•â•©â•â•â•â•â•â•â•â•—
â•‘ Grandchild 1 â•‘ â•‘ Grandchild 2 â•‘
â•šâ•â•â•â•â•â•â•â•â•â•â•â•â•â•â• â•šâ•â•â•â•â•â•â•â•â•â•â•â•â•â•â•
With chest style:
astree vertical --input examples/with_grandchildren_2.md --style chest
â•”â”â”â”â”â”â”â•—
┃ Root ┃
â•šâ”â”┳â”â”â”â•
â•”â”â”â”â”â”â”â”â”â”â”â”â”»â”â”â”â”â”â”â”â”â”â”â”â•—
â•”â”â”â”â”»â”â”â”â•— â•”â”â”â”â”»â”â”â”â•—
┃ Left ┃ ┃ Right ┃
┃ Child ┃ ┃ Child ┃
â•šâ”â”â”┳â”â”â”â• â•šâ”â”â”┳â”â”â”â•
â•”â”â”â”â”â”â”â”â”»â”â”â”â”â”â”â”â•— â•”â”â”â”â”â”â”»â”â”â”â”â”â”â•—
â•”â”â”â”â”â”â”»â”â”â”â”â”â”â•— â•”â”â”â”â”â”â”»â”â”â”â”â”â”â•— ┃ Right ┃
┃ Grandchild ┃ ┃ Grandchild ┃ ┃ Grandchild ┃
┃ (1) ┃ ┃ (2) ┃ â•šâ”â”â”â”â”â”â”â”â”â”â”â”â•
â•šâ”â”â”â”â”â”â”â”â”â”â”â”â• â•šâ”â”â”â”â”â”â”â”â”â”â”â”â•
With balloon style:
astree vertical --input examples/with_children_2.md --style balloon2
â•â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â•®
│ Root Node │
╰─────¤─────╯
â•â”€â”€â”€â”€â”´â”€â”€â”€â”€â”€â•®
â•â”€â”€â”€Â¤â”€â”€â”€â•® â•â”€â”€â”€Â¤â”€â”€â”€â•®
│ Child │ │ Child │
│ (1) │ │ (2) │
╰───────╯ ╰───────╯
To specify the maximum width of the label with --width <WIDTH>
. For example:
astree vertical --input examples/with_long_label.md --width 10
┌──────────â”
│ A Simple │
│ Root │
└────┬─────┘
┌─────┴──────â”
┌───┴────┠┌────┴────â”
│ A long │ │ Another │
│ child │ │ long │
└────────┘ │ child │
└─────────┘
See development.md.