1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
//! # 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].
//!
//! [lipgloss/tree]: https://github.com/charmbracelet/lipgloss/tree/main/tree
//! [Charm]: https://charm.sh
//!
//! ## 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
//!
//! ```rust
//! 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:
//!
//! ```text
//! My Project
//! ├── src/
//! ├── README.md
//! ├── docs/
//! │ ├── guide.md
//! │ └── api.md
//! ```
//!
//! ## Advanced Usage
//!
//! ### Custom Styling
//!
//! ```rust
//! 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
//!
//! ```rust
//! 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
/// Node and tree data structures for building hierarchical content.
/// Functions for generating branch characters and indentation strings.
/// Core rendering engine with styling and formatting support.
// Re-export the main types and functions
pub use ;
pub use ;
pub use Renderer;
// Go API compatibility aliases
/// Trait alias for `Children` - provides compatibility with Go naming conventions
pub use Children as ChildrenTrait;
/// Type alias for `Leaf` - provides compatibility with Go naming conventions
pub use Leaf as LeafType;
/// Type alias for `NodeChildren` - provides compatibility with Go naming conventions
pub use NodeChildren as NodeChildrenType;
/// Type alias for `Tree` - provides compatibility with Go naming conventions
pub use Tree as TreeType;
/// Creates a new empty tree.
///
/// This is a convenience function equivalent to `Tree::new()`.
/// The tree starts with no root value and no children.
///
/// # Returns
///
/// A new empty `Tree` instance
///
/// # Examples
///
/// ```rust
/// use lipgloss_tree;
///
/// let tree = lipgloss_tree::new();
/// assert!(tree.to_string().is_empty());
/// ```
/// Creates a new tree with a root value.
///
/// This is a convenience function that creates a new tree and immediately
/// sets its root value, equivalent to `Tree::new().root(root)`.
///
/// # Arguments
///
/// * `root` - The root value for the tree (anything that can be converted to a String)
///
/// # Returns
///
/// A new `Tree` instance with the specified root value
///
/// # Examples
///
/// ```rust
/// use lipgloss_tree;
///
/// let tree = lipgloss_tree::new_with_root("My Root");
/// println!("{}", tree); // Outputs: "My Root"
/// ```