| Crates.io | quercus |
| lib.rs | quercus |
| version | 0.1.1 |
| created_at | 2025-06-08 17:58:41.344378+00 |
| updated_at | 2025-06-09 21:14:08.416592+00 |
| description | Easy to use CLI tree for your branchy info. |
| homepage | |
| repository | https://gitlab.com/jevgarrido/quercus |
| max_upload_size | |
| id | 1705120 |
| size | 30,290 |
quercus is the scientific genus name for oak trees.
This crate was inspired by ptree.
This crate allows you to create trees with many roots.
This crate does not have a syntax distinction for the first node/branch of a given root.
The crate also does not have a syntax distinction for nodes that do not have branches (leaves) or nodes that do.
This makes it easy to create a tree recursively, as the information is not needed when adding a new node.
This crate also provides a (small) variety of branch styles and a versatile indentation option that may be invoked spontaneously during the construction of the tree.
The following code
let mut tree = Tree::new();
tree.node("Root");
tree.begin_branches();
tree.node("Branch 1");
tree.node("Branch 2");
tree.end_branches();
tree.prune();
println!("{tree}");
results in:
Root
├── Branch 1
└── Branch 2
For a node with many lines use the node_many_lines() command.
For example, the code
let mut tree = Tree::new().style(PipeStyle::Double).indent(5);
tree.node("Root");
tree.begin_branches();
tree.node_many_lines(&["Branch 1", "Some", "more", "information"]);
tree.begin_branches();
tree.node("Autumn leaf");
tree.node("Spring leaf");
tree.end_branches();
tree.indent(0); // Change indentation
tree.node("Branch 2");
tree.begin_branches();
tree.node("Summer leaf");
tree.node("Winter (no leaf) :(");
tree.end_branches();
tree.end_branches();
tree.prune_and_print();
results in:
Root
╠═════ Branch 1
║ Some
║ more
║ information
║ ╠═════ Autumn leaf
║ ╚═════ Spring leaf
╚ Branch 2
╠ Summer leaf
╚ Winter (no leaf) :(
The indentation of the branches can be set through the indent() command, which expects a usize integer.
This command can be invoked anywhere during the construction of the tree.
The style of the branches can be set through the style() command, which expects a PipeStyle enum variant.
Currently, the following variants are available:
PipeStyle::Simple : │ ─ ├ └PipeStyle::Curvy : │ ─ ├ ╰PipeStyle::Double : ║ ═ ╠ ╚PipeStyle::Thick : ┃ ━ ┣ ┗This command, however, may only be invoked at the root level of the tree.
For an example that builds a tree recursively, run
$ cargo run --release --example fibonacci
This should yield the following output:
5
├─ 3
│ ├─ 2
│ │ ├─ 1
│ │ │ ├─ 1
│ │ │ ╰─ 0
│ │ ╰─ 1
│ ╰─ 1
│ ├─ 1
│ ╰─ 0
╰─ 2
├─ 1
│ ├─ 1
│ ╰─ 0
╰─ 1
For an example that uses the colored crate as well as the node_many_lines() command, run
$ cargo run --release --example hierarchy
This project is licensed under either