lipgloss-tree 0.0.6

A tree component for terminal user interfaces, styled with Lip Gloss.
Documentation

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 structures
  • [enumerator] - Functions for generating branch characters and indentation
  • [renderer] - Core rendering engine with styling support