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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
//! Enumerator functions for tree branch characters and indentation.
//!
//! This module provides the core functions for generating tree branch
//! characters (├──, └──, etc.) and indentation strings for nested content.
//! It includes both built-in enumerators with box-drawing characters and
//! type definitions for custom enumerator functions.
use crateChildren;
use Style;
/// Function type for generating tree branch characters.
///
/// An `Enumerator` takes a children collection and an index, then returns
/// the appropriate branch character string for that position. Typically,
/// the last child in a sequence gets a different character (└──) than
/// intermediate children (├──).
///
/// # Arguments
///
/// * `children` - The children collection being enumerated
/// * `index` - The zero-based index of the current child
///
/// # Returns
///
/// A string representing the branch character(s) for this position
///
/// # Examples
///
/// ```rust
/// use lipgloss_tree::{Children, Enumerator};
///
/// let custom_enumerator: Enumerator = |children, index| {
/// if index == children.length() - 1 {
/// "└──".to_string() // Last child
/// } else {
/// "├──".to_string() // Intermediate child
/// }
/// };
/// ```
pub type Enumerator = fn ;
/// Function type for generating indentation strings for nested tree content.
///
/// An `Indenter` generates the indentation used for child nodes that appear
/// below their parent. This creates the visual connection lines between
/// parent and nested content. The indentation typically differs based on
/// whether there are more siblings following (│ continues the line) or if
/// this is the last child (spaces for clean termination).
///
/// # Arguments
///
/// * `children` - The children collection being indented
/// * `index` - The zero-based index of the current child
///
/// # Returns
///
/// A string representing the indentation for nested content under this child
///
/// # Examples
///
/// ```rust
/// use lipgloss_tree::{Children, Indenter};
///
/// let custom_indenter: Indenter = |children, index| {
/// if index == children.length() - 1 {
/// " ".to_string() // Spaces for last child
/// } else {
/// "│ ".to_string() // Vertical line for continuing branches
/// }
/// };
/// ```
pub type Indenter = fn ;
/// Function type for generating styles based on child position.
///
/// A `StyleFunc` dynamically determines the styling to apply to tree elements
/// based on the child's position within its parent's children collection.
/// This allows for positional styling like alternating colors, highlighting
/// specific indices, or applying different styles to first/last children.
///
/// # Arguments
///
/// * `children` - The children collection containing the styled element
/// * `index` - The zero-based index of the current child being styled
///
/// # Returns
///
/// A `Style` object with the desired formatting for this position
///
/// # Examples
///
/// ```rust
/// use lipgloss::{Style, Color};
/// use lipgloss_tree::{Children, StyleFunc};
///
/// // Alternating colors based on index
/// let alternating_style: StyleFunc = |_, index| {
/// if index % 2 == 0 {
/// Style::new().foreground(Color::from("blue"))
/// } else {
/// Style::new().foreground(Color::from("green"))
/// }
/// };
///
/// // Highlight first and last items
/// let highlight_ends: StyleFunc = |children, index| {
/// if index == 0 || index == children.length() - 1 {
/// Style::new().bold(true).foreground(Color::from("red"))
/// } else {
/// Style::new()
/// }
/// };
/// ```
pub type StyleFunc = fn ;
/// Default tree enumerator using standard box-drawing characters.
///
/// This enumerator generates the classic tree structure using Unicode
/// box-drawing characters. Intermediate children get "├──" and the
/// last child gets "└──" to properly terminate the branch.
///
/// # Arguments
///
/// * `children` - The children collection being enumerated
/// * `index` - The zero-based index of the current child
///
/// # Returns
///
/// "├──" for intermediate children, "└──" for the last child
///
/// # Output Example
///
/// ```text
/// ├── Foo
/// ├── Bar
/// ├── Baz
/// └── Qux
/// ```
///
/// # Examples
///
/// ```rust
/// use lipgloss_tree::{default_enumerator, new_string_data};
///
/// let children = new_string_data(&["Foo", "Bar", "Qux"]);
/// assert_eq!(default_enumerator(&children, 0), "├──"); // First child
/// assert_eq!(default_enumerator(&children, 1), "├──"); // Middle child
/// assert_eq!(default_enumerator(&children, 2), "└──"); // Last child
/// ```
/// Tree enumerator using rounded box-drawing characters for the last child.
///
/// Similar to the default enumerator, but uses a rounded corner character
/// (╰──) for the last child instead of the standard corner (└──). This
/// provides a softer, more modern aesthetic while maintaining the same
/// tree structure.
///
/// # Arguments
///
/// * `children` - The children collection being enumerated
/// * `index` - The zero-based index of the current child
///
/// # Returns
///
/// "├──" for intermediate children, "╰──" for the last child
///
/// # Output Example
///
/// ```text
/// ├── Foo
/// ├── Bar
/// ├── Baz
/// ╰── Qux
/// ```
///
/// # Examples
///
/// ```rust
/// use lipgloss_tree::{rounded_enumerator, new_string_data};
///
/// let children = new_string_data(&["Foo", "Bar", "Qux"]);
/// assert_eq!(rounded_enumerator(&children, 0), "├──"); // First child
/// assert_eq!(rounded_enumerator(&children, 1), "├──"); // Middle child
/// assert_eq!(rounded_enumerator(&children, 2), "╰──"); // Last child (rounded)
/// ```
/// Default tree indenter for nested content and multiline text.
///
/// This indenter creates the visual connection lines for nested tree content.
/// It uses a vertical line (│) with spaces for continuing branches and
/// plain spaces for content under the last child. The spacing is carefully
/// calculated to align with the default enumerator characters.
///
/// # Arguments
///
/// * `children` - The children collection being indented
/// * `index` - The zero-based index of the current child
///
/// # Returns
///
/// "│ " (vertical line + 3 spaces) for continuing branches,
/// " " (4 spaces) for content under the last child
///
/// # Output Example
///
/// ```text
/// ├── Foo
/// ├── Bar
/// │ ├── Qux
/// │ ├── Quux
/// │ │ ├── Foo
/// │ │ └── Bar
/// │ └── Quuux
/// └── Baz
/// ```
///
/// # Examples
///
/// ```rust
/// use lipgloss_tree::{default_indenter, new_string_data};
///
/// let children = new_string_data(&["Foo", "Bar", "Baz"]);
/// assert_eq!(default_indenter(&children, 0), "│ "); // Continuing branch
/// assert_eq!(default_indenter(&children, 1), "│ "); // Continuing branch
/// assert_eq!(default_indenter(&children, 2), " "); // Last child (spaces only)
/// ```
///
/// # Design Notes
///
/// The spacing is designed to align with standard enumerator widths:
/// - "├── " is 4 characters wide
/// - "└── " is 4 characters wide
/// - "│ " provides continuing vertical line + 3 spaces = 4 total
/// - " " provides 4 spaces for clean termination