Expand description
§lipgloss-tree
A Rust library for rendering styled tree structures in terminal applications. This crate is part of the lipgloss-rs ecosystem, providing a 1:1 Rust port of the Go lipgloss/tree library from Charm.
§Features
- Rich tree rendering with customizable branch characters (├──, └──, etc.)
- Custom enumerators supporting Roman numerals, bullet points, or any custom format
- Advanced styling with colors, padding, borders, and text formatting
- Multi-line content support with proper indentation
- Style inheritance from parent to child nodes
- Alignment control for mixed-width enumerators
§Quick Start
use lipgloss_tree::Tree;
let tree = Tree::new()
.root("My Project")
.child(vec![
"src/".into(),
"README.md".into(),
Tree::new()
.root("docs/")
.child(vec!["guide.md".into(), "api.md".into()])
.into(),
]);
println!("{}", tree);
This produces:
My Project
├── src/
├── README.md
├── docs/
│ ├── guide.md
│ └── api.md
§Advanced Usage
§Custom Styling
use lipgloss::{Style, Color};
use lipgloss_tree::{Tree, Renderer};
use lipgloss_tree::renderer::TreeStyle;
let custom_style = TreeStyle {
enumerator_func: |_, _| Style::new().foreground(Color::from("blue")),
item_func: |_, _| Style::new().foreground(Color::from("green")),
root: Style::new().bold(true).foreground(Color::from("magenta")),
..TreeStyle::default()
};
let tree = Tree::new()
.root("Styled Tree")
.child(vec!["Item 1".into(), "Item 2".into()]);
let renderer = Renderer::new().style(custom_style);
// Use renderer.render(&tree, true, "") for custom rendering
§Custom Enumerators
use lipgloss_tree::Tree;
let tree = Tree::new()
.root("Roman List")
.child(vec!["First".into(), "Second".into(), "Third".into()])
.enumerator(|_, i| match i + 1 {
1 => "I".to_string(),
2 => "II".to_string(),
3 => "III".to_string(),
n => n.to_string(),
});
§Architecture
The crate is organized into three main modules:
children
- Node and tree data structuresenumerator
- Functions for generating branch characters and indentationrenderer
- Core rendering engine with styling support
Re-exports§
pub use children::new_string_data;
pub use children::root;
pub use children::Children;
pub use children::Filter;
pub use children::Leaf;
pub use children::Node;
pub use children::NodeChildren;
pub use children::Tree;
pub use enumerator::default_enumerator;
pub use enumerator::default_indenter;
pub use enumerator::rounded_enumerator;
pub use enumerator::Enumerator;
pub use enumerator::Indenter;
pub use enumerator::StyleFunc;
pub use renderer::Renderer;
pub use Children as ChildrenTrait;
pub use Leaf as LeafType;
pub use NodeChildren as NodeChildrenType;
pub use Tree as TreeType;
Modules§
- children
- Node and tree data structures for building hierarchical content. Node and tree data structures for building hierarchical content.
- enumerator
- Functions for generating branch characters and indentation strings. Enumerator functions for tree branch characters and indentation.
- renderer
- Core rendering engine with styling and formatting support. Tree rendering engine for lipgloss-tree.
Functions§
- new
- Creates a new empty tree.
- new_
with_ root - Creates a new tree with a root value.