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
//! # Text Processing Engine
//!
//! This module provides a comprehensive text processing system for the boxen library,
//! handling text measurement, alignment, wrapping, and formatting operations with
//! Unicode awareness and terminal-optimized algorithms.
//!
//! ## Overview
//!
//! The text processing engine is responsible for transforming raw text input into
//! properly formatted, aligned, and sized content that fits perfectly within box
//! constraints. It handles complex text operations while maintaining visual consistency
//! and optimal performance.
//!
//! ## Core Components
//!
//! ### Text Measurement (`measurement`)
//! - **Unicode-Aware Width Calculation**: Accurate character width detection
//! - **Line Length Analysis**: Determines visual width of text lines
//! - **Content Sizing**: Calculates space requirements for text blocks
//!
//! ### Text Alignment (`alignment`)
//! - **Horizontal Alignment**: Left, center, and right text positioning
//! - **Vertical Alignment**: Content positioning within height constraints
//! - **Padding Application**: Consistent spacing around text content
//!
//! ### Text Wrapping (`wrapping`)
//! - **Intelligent Line Breaking**: Smart word wrapping with overflow handling
//! - **Width Constraint Handling**: Ensures text fits within specified bounds
//! - **Preserve Formatting**: Maintains intentional line breaks and spacing
//!
//! ## Quick Start
//!
//! ```rust
//! use ::boxen::text::{wrap_text, align_lines, text_width};
//! use ::boxen::TextAlignment;
//!
//! // Wrap text to fit within width constraints
//! let wrapped = wrap_text("Long text that needs wrapping", 20).unwrap();
//!
//! // Align text lines within a container
//! let aligned = align_lines(&wrapped, TextAlignment::Center, 30);
//!
//! // Measure text dimensions
//! let width = text_width("Sample text");
//! ```
//!
//! ## Text Measurement System
//!
//! The measurement system provides accurate text dimension calculations:
//!
//! ### Unicode Support
//! Handles complex Unicode characters including:
//! - **Combining Characters**: Properly measures accented characters
//! - **Wide Characters**: Accounts for CJK characters (2-column width)
//! - **Zero-Width Characters**: Ignores non-printing characters
//! - **Emoji Support**: Correctly measures emoji width
//!
//! ```rust
//! use ::boxen::text::text_width;
//!
//! // Accurate width calculation for various text types
//! assert_eq!(text_width("Hello"), 5);
//! assert_eq!(text_width("こんにちは"), 10); // Wide characters
//! assert_eq!(text_width("café"), 4); // Combining characters
//! ```
//!
//! ### Line Analysis
//! Analyzes text blocks to determine optimal layout:
//!
//! ```rust
//! use ::boxen::text::{max_line_width, line_widths};
//!
//! let text = "Line 1\nLonger line 2\nShort";
//! let lines: Vec<&str> = text.lines().collect();
//! let max_width = max_line_width(&lines);
//! let widths = line_widths(text);
//! let line_count = widths.len();
//! ```
//!
//! ## Text Alignment System
//!
//! The alignment system provides flexible text positioning within containers:
//!
//! ### Horizontal Alignment
//! - **Left**: Text aligned to the left edge (default)
//! - **Center**: Text centered within available width
//! - **Right**: Text aligned to the right edge
//!
//! ```rust
//! use ::boxen::text::align_line;
//! use ::boxen::TextAlignment;
//!
//! let line = "Centered text";
//! let width = 20;
//!
//! let left = align_line(line, TextAlignment::Left, width);
//! let center = align_line(line, TextAlignment::Center, width);
//! let right = align_line(line, TextAlignment::Right, width);
//! ```
//!
//! ### Vertical Alignment
//! Controls text positioning within height constraints:
//!
//! ```rust
//! use ::boxen::text::apply_height_constraints;
//!
//! let lines = vec!["Line 1".to_string(), "Line 2".to_string()];
//! let constrained = apply_height_constraints(&lines, 5); // Pad to 5 lines
//! ```
//!
//! ### Padding Integration
//! Applies consistent spacing around text content:
//!
//! ```rust
//! use ::boxen::text::apply_padding;
//! use ::boxen::Spacing;
//!
//! let lines = vec!["Content".to_string()];
//! let padding = Spacing::from((1, 2, 1, 2)); // top, right, bottom, left
//! let padded = apply_padding(&lines, &padding, 20);
//! ```
//!
//! ## Text Wrapping System
//!
//! The wrapping system intelligently breaks text to fit within width constraints:
//!
//! ### Smart Word Breaking
//! - **Word Boundaries**: Prefers breaking at word boundaries
//! - **Hyphenation**: Handles long words that don't fit
//! - **Preserve Breaks**: Maintains intentional line breaks
//! - **Overflow Handling**: Gracefully handles edge cases
//!
//! ```rust
//! use ::boxen::text::wrap_text;
//!
//! // Intelligent word wrapping
//! let text = "This is a long sentence that needs to be wrapped";
//! let wrapped = wrap_text(text, 15).unwrap();
//!
//! // Result: ["This is a long", "sentence that", "needs to be", "wrapped"]
//! ```
//!
//! ### Constraint Handling
//! Ensures text fits within specified bounds while maintaining readability:
//!
//! ```rust
//! use ::boxen::text::wrap_text_preserve_words;
//!
//! // Advanced wrapping with word preservation
//! let wrapped = wrap_text_preserve_words(
//! "Very long text content",
//! 20 // max width
//! ).unwrap();
//! ```
//!
//! ## Performance Optimizations
//!
//! The text processing engine is optimized for performance:
//!
//! ### Efficient Algorithms
//! - **Linear Complexity**: Most operations scale linearly with text length
//! - **Minimal Allocations**: Reuses buffers where possible
//! - **Unicode Optimization**: Efficient character width calculations
//! - **Caching**: Memoizes expensive calculations
//!
//! ### Memory Management
//! - **String Reuse**: Minimizes string allocations
//! - **Lazy Processing**: Only processes text when needed
//! - **Streaming Support**: Handles large text blocks efficiently
//!
//! ## Error Handling
//!
//! Text processing operations include comprehensive error handling:
//!
//! ### Common Error Scenarios
//! - **Width Constraints**: When text cannot fit in specified width
//! - **Invalid Input**: Malformed or problematic text content
//! - **Resource Limits**: When text exceeds reasonable size limits
//!
//! ```rust
//! use ::boxen::text::wrap_text;
//!
//! match wrap_text("Content", 0) {
//! Ok(lines) => println!("Wrapped: {:?}", lines),
//! Err(e) => println!("Error: {}", e), // Width too small
//! }
//! ```
//!
//! ## Integration with Boxen
//!
//! The text processing system integrates seamlessly with boxen's rendering pipeline:
//!
//! ### Automatic Processing
//! Text is automatically processed during box rendering:
//!
//! ```rust
//! use ::boxen::BoxenBuilder;
//! use ::boxen::TextAlignment;
//!
//! // Text is automatically measured, wrapped, and aligned
//! let result = BoxenBuilder::new()
//! .width(30)
//! .text_alignment(TextAlignment::Center)
//! .render("This text will be automatically processed")
//! .unwrap();
//! ```
//!
//! ### Custom Processing
//! Advanced users can access text processing functions directly:
//!
//! ```rust
//! use ::boxen::text::{wrap_text, align_lines, apply_padding};
//! use ::boxen::{TextAlignment, Spacing};
//!
//! // Manual text processing pipeline
//! let wrapped = wrap_text("Custom processing", 20).unwrap();
//! let aligned = align_lines(&wrapped, TextAlignment::Center, 25);
//! let padded = apply_padding(&aligned, &Spacing::from(1), 27);
//! ```
//!
//! ## Thread Safety
//!
//! All text processing operations are thread-safe and can be used in concurrent environments.
//! The functions are pure and don't maintain internal state, making them safe for parallel processing.
/// Text alignment functionality
/// Text measurement and width calculation
/// Unicode width caching for performance
/// Text wrapping and line breaking
pub use ;
pub use *;
pub use cached_unicode_width;
pub use *;
pub use ;