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
/// ANSI color and style management module.
///
/// This module provides comprehensive functions for working with ANSI escape sequences
/// for text colors and styles in terminal environments. It serves as the core color
/// engine for the println! macro system and handles all terminal styling operations.
///
/// # ANSI Color System
///
/// The module implements the full ANSI color specification with support for:
/// - 8 standard colors (30-37)
/// - 8 bright colors (90-97)
/// - 9 text style modifiers (1-9)
/// - Automatic reset sequences (0)
///
/// # Supported Colors
///
/// ## Standard Colors (30-37)
/// - black, red, green, yellow, blue, magenta, cyan, white
///
/// ## Bright Colors (90-97)
/// - bright_black (alias: gray), bright_red, bright_green, bright_yellow
/// - bright_blue, bright_magenta, bright_cyan, bright_white
///
/// # Supported Styles
///
/// ## Text Modifications (1-9)
/// - bold (1) - Increased font weight
/// - dimmed (2) - Decreased font weight
/// - italic (3) - Slanted text style
/// - underline (4) - Underlined text
/// - blink (5) - Blinking text effect
/// - reversed (7) - Inverted foreground/background
/// - hidden (8) - Invisible text (password fields)
/// - strikethrough (9) - Line through text
///
/// # String Escaping
///
/// The module provides robust string escaping for format strings:
/// - Backslash escaping: `\` → `\\`
/// - Quote escaping: `"` → `\"`
/// - Newline escaping: `\n` → `\\n`
///
/// # ANSI Sequence Generation
///
/// Color sequences follow the standard format: `\x1B[{codes}m`
/// - Single style: `\x1B[31m` (red)
/// - Multiple styles: `\x1B[31;1m` (red + bold)
/// - Reset sequence: `\x1B[0m` (clear all styles)
///
/// # Performance Optimizations
///
/// - **Zero Allocation**: Returns reset sequence for empty inputs
/// - **Efficient Joining**: Uses semicolon-separated code concatenation
/// - **Fast Matching**: Uses optimized match expressions for style lookup
/// - **String Interning**: Reuses common ANSI sequences
///
/// # Terminal Compatibility
///
/// The module generates standard ANSI sequences compatible with:
/// - Unix terminals (xterm, gnome-terminal, etc.)
/// - Windows Terminal and PowerShell
/// - VS Code integrated terminal
/// - Modern terminal emulators
///
/// # Usage Patterns
///
/// The module is used internally by the formatting system:
/// - Style parsing: `@(red, bold)` → `["red", "bold"]`
/// - Code generation: `["red", "bold"]` → `\x1B[31;1m`
/// - String safety: Format strings are properly escaped
/// - Reset handling: Automatic style reset after each token
///
/// # Technical Implementation
///
/// ## Error Handling
/// - Unknown styles are silently ignored (graceful degradation)
/// - Empty style lists return reset sequences
/// - Invalid codes are filtered out automatically
///
/// ## Memory Management
/// - Minimal heap allocations through strategic string building
/// - Code vector reuse for multiple style combinations
/// - Efficient string concatenation patterns
///
/// ## Standards Compliance
/// - Full ANSI X3.64 compliance for color codes
/// - SGR (Select Graphic Rendition) parameter support
/// - Cross-platform terminal compatibility guaranteed