10 releases

0.5.2 Nov 28, 2024
0.5.0 Jul 31, 2024
0.4.0 Oct 27, 2021
0.3.2 Mar 13, 2021
0.2.1 Sep 12, 2018

#48 in Command-line interface

Download history 8635/week @ 2024-08-23 10067/week @ 2024-08-30 9177/week @ 2024-09-06 7020/week @ 2024-09-13 6306/week @ 2024-09-20 6325/week @ 2024-09-27 7404/week @ 2024-10-04 9352/week @ 2024-10-11 10101/week @ 2024-10-18 12947/week @ 2024-10-25 12289/week @ 2024-11-01 12162/week @ 2024-11-08 14559/week @ 2024-11-15 12777/week @ 2024-11-22 14737/week @ 2024-11-29 9939/week @ 2024-12-06

53,584 downloads per month
Used in 194 crates (42 directly)

MIT/Apache

89KB
1K SLoC

Pretty-print tree-like structures

The ptree crate supports output formatting due to a user-provided configuration file and/or environment variables. Different output styles

Usage

[dependencies]
ptree = "0.5"

Constructing a tree

There are two main ways of using ptree to print a tree-like data structure. The first is to implement TreeItem for your structure. The second is to create a new tree, either using TreeBuilder or by manually constructing StringItems.

The ptree crate includes implementations of TreeItem for some common types, including a custom StringItem and petgraph::Graph.

Printing the tree

A tree can be printed to standard output using print_tree, or to an arbitrary writer using write_tree. Both functions have variants which take a PrintConfig that controls the output. Text is formatted using ansi-term, which allows changing colors and styles of the printed text.

User configuration

By default, ptree loads configuration from a user configuration file. This allows end users to globally configure the output format for all applications using ptree. Applications can use this configuration directly, modify it, or ignore it altogether.

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Dependencies

~2–13MB
~102K SLoC