lipgloss-tree
A tree component for Terminal UIs, styled with Lip Gloss. This crate is part of the lipgloss-rs ecosystem and targets 1:1 API and rendering parity with Charm's Go implementation.
- Render hierarchical trees using box-drawing characters (├──, └──, │)
- Style roots, branch prefixes, and items independently
- Support for custom enumerators and indenters
- Multiline content with correct indentation and alignment
Installation
Use the batteries-included facade (recommended):
[]
= { = "0.1.0", = ["trees"] }
Or depend directly on the component (add lipgloss
if you want styling):
[]
= "0.1.0"
= "0.1.0"
Quick start
use ;
let t = new.root
.child;
println!;
Output:
.
├── macOS
└── Linux
├── NixOS
└── Arch Linux (btw)
Styling
You can style the root, enumerators (branch prefixes), and items. Styles are from the lipgloss
crate.
use ;
use ;
let t = new
.root
.root_style
.enumerator_style
.item_style
.child;
println!;
Dynamic styling per item is also supported via functions:
use ;
use Tree;
let t = new
.root
.child
.item_style_func;
println!;
Custom enumerators and indenters
Use built-ins or supply your own.
use ;
let t = new
.root
.enumerator
.indenter
.child;
println!;
Custom functions receive the visible children and the current index.
use ;
let t = new
.root
.enumerator
.indenter
.child;
println!;
Advanced: Renderer API
For full control, render with Renderer
and TreeStyle
.
use ;
use ;
let style = TreeStyle ;
let tree = new.root.child;
let renderer = new_renderer.style;
println!;
Multiline content
Items can contain newlines. Indentation is extended to match height.
use Tree;
let tree = new.root.child;
println!;
Demos
Run the included demos from the repository root:
Documentation
- API docs:
https://docs.rs/lipgloss-tree
- Project:
https://github.com/whit3rabbit/lipgloss-rs
License
MIT