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
//! Unicode and text handling
//!
//! This module provides utilities for working with text in a terminal context,
//! including bidirectional text support, character width calculation, and text wrapping.
//!
//! # Features
//!
//! | Feature | Description | Use Case |
//!|---------|-------------|----------|
//! | **Bidirectional Text** | RTL/LTR text detection and rendering | Arabic, Hebrew |
//! | **Character Width** | Display width calculation | Layout, alignment |
//! | **Text Wrapping** | Word/character wrapping with overflow | Truncation, wrapping |
//! | **Grapheme Clusters** | Unicode-aware text operations | Emoji, CJK |
//!
//! # Quick Start
//!
//! ## Character Width
//!
//! ```rust,ignore
//! use revue::text::char_width;
//!
//! // ASCII characters are width 1
//! assert_eq!(char_width('A'), 1);
//!
//! // Wide characters (CJK, emoji) are width 2
//! assert_eq!(char_width('中'), 2);
//! assert_eq!(char_width('🎨'), 2);
//!
//! // Combining characters are width 0
//! assert_eq!(char_width('\u{0300}'), 0);
//! ```
//!
//! ## Text Wrapping
//!
//! ```rust,ignore
//! use revue::text::{wrap_text, wrap_words, truncate};
//!
//! // Wrap text to fit width
//! let wrapped = wrap_text("Hello world!", 5);
//! // ["Hello", "world!"]
//!
//! // Wrap by words
//! let wrapped = wrap_words("The quick brown fox", 10);
//! // ["The quick", "brown fox"]
//!
//! // Truncate with ellipsis
//! let truncated = truncate("Long text here", 10);
//! // "Long text ..."
//! ```
//!
//! ## Bidirectional Text
//!
//! ```rust,ignore
//! use revue::text::{detect_direction, contains_rtl, mirror_char};
//!
//! // Detect text direction
//! assert_eq!(detect_direction("Hello"), TextDirection::LTR);
//! assert_eq!(detect_direction("مرحبا"), TextDirection::RTL);
//!
//! // Check for RTL
//! assert!(contains_rtl("Hello مرحبا World"));
//!
//! // Mirror characters for RTL display
//! assert_eq!(mirror_char('('), ')');
//! assert_eq!(mirror_char('<'), '>');
//! ```
//!
//! # Bidi (Bidirectional Text)
//!
//! Supports proper rendering of mixed LTR/RTL text:
//!
//! ```rust,ignore
//! use revue::text::{BidiInfo, BidiConfig};
//!
//! let text = "Hello مرحبا World";
//! let config = BidiConfig::default();
//! let bidi = BidiInfo::new(text, &config);
//!
//! // Get visual runs for rendering
//! for run in bidi.visual_runs() {
//! println!("{:?}: {}", run.dir, &text[run.start..run.end]);
//! }
//! ```
//!
//! # Text Overflow
//!
//! Handle text that exceeds available space:
//!
//! ```rust,ignore
//! use revue::text::{truncate, truncate_middle, Overflow};
//!
//! // Truncate at end
//! truncate("Very long text", 10, &Overflow::Ellipsis);
//! // "Very long ..."
//!
//! // Truncate in middle
//! truncate_middle("Very long text here", 10);
//! // "Very ... here"
//!
//! // Truncate without indicator
//! truncate("Very long text", 10, &Overflow::Clip);
//! // "Very long "
//! ```
//!
//! # Character Width Tables
//!
//! Uses Unicode standard width assignments:
//!
//! | Category | Width | Examples |
//!|----------|-------|----------|
//! | ASCII | 1 | A-Z, a-z, 0-9, punctuation |
//! | Wide (East Asian) | 2 | CJK, Hangul, fullwidth |
//! | Ambiguous | 1 (or 2 in East Asian context) | Greek, Cyrillic (some) |
//! | Combining | 0 | Accents, diacritics |
//! | Zero-width | 0 | Zero-width joiner, non-joiner |
//!
//! # Text Alignment
//!
//! ```rust,ignore
//! use revue::text::{TextAlign, calculate_alignment};
//!
//! let text = "Hello";
//! let width = 10;
//!
//! // Left align
//! let aligned = calculate_alignment(text, width, TextAlign::Left);
//! // "Hello "
//!
//! // Center align
//! let aligned = calculate_alignment(text, width, TextAlign::Center);
//! // " Hello "
//!
//! // Right align
//! let aligned = calculate_alignment(text, width, TextAlign::Right);
//! // " Hello"
//! ```
pub use ;
pub use ;
pub use ;