0
# Color and Style Constants
1
2
ANSI color code constants and keyword mappings for direct access to escape sequence values. These constants provide the low-level codes used by HueString and console classes to generate colored terminal output.
3
4
## Capabilities
5
6
### Foreground Color Constants
7
8
Standard ANSI foreground colors (codes 30-37).
9
10
```python { .api }
11
FG: namedtuple
12
"""
13
Foreground color constants.
14
15
Fields:
16
black (int): 30
17
red (int): 31
18
green (int): 32
19
yellow (int): 33
20
blue (int): 34
21
magenta (int): 35
22
cyan (int): 36
23
white (int): 37
24
"""
25
```
26
27
**Usage:**
28
```python
29
from hues.colortable import FG
30
31
print(FG.red) # 31
32
print(FG.green) # 32
33
print(FG.blue) # 34
34
```
35
36
### Background Color Constants
37
38
Standard ANSI background colors (codes 40-47).
39
40
```python { .api }
41
BG: namedtuple
42
"""
43
Background color constants.
44
45
Fields:
46
black (int): 40
47
red (int): 41
48
green (int): 42
49
yellow (int): 43
50
blue (int): 44
51
magenta (int): 45
52
cyan (int): 46
53
white (int): 47
54
"""
55
```
56
57
**Usage:**
58
```python
59
from hues.colortable import BG
60
61
print(BG.black) # 40
62
print(BG.white) # 47
63
```
64
65
### High Intensity Foreground Colors
66
67
Bright/high intensity foreground colors (codes 90-97).
68
69
```python { .api }
70
HI_FG: namedtuple
71
"""
72
High intensity foreground color constants.
73
74
Fields:
75
black (int): 90
76
red (int): 91
77
green (int): 92
78
yellow (int): 93
79
blue (int): 94
80
magenta (int): 95
81
cyan (int): 96
82
white (int): 97
83
"""
84
```
85
86
**Usage:**
87
```python
88
from hues.colortable import HI_FG
89
90
print(HI_FG.red) # 91
91
print(HI_FG.green) # 92
92
```
93
94
### High Intensity Background Colors
95
96
Bright/high intensity background colors (codes 100-107).
97
98
```python { .api }
99
HI_BG: namedtuple
100
"""
101
High intensity background color constants.
102
103
Fields:
104
black (int): 100
105
red (int): 101
106
green (int): 102
107
yellow (int): 103
108
blue (int): 104
109
magenta (int): 105
110
cyan (int): 106
111
white (int): 107
112
"""
113
```
114
115
**Usage:**
116
```python
117
from hues.colortable import HI_BG
118
119
print(HI_BG.red) # 101
120
print(HI_BG.yellow) # 103
121
```
122
123
### Style Constants
124
125
Text style and formatting codes.
126
127
```python { .api }
128
STYLE: namedtuple
129
"""
130
Text style constants.
131
132
Fields:
133
reset (int): 0 - Reset all formatting
134
bold (int): 1 - Bold text
135
italic (int): 3 - Italic text
136
underline (int): 4 - Underlined text
137
defaultfg (int): 39 - Default foreground color
138
defaultbg (int): 49 - Default background color
139
"""
140
```
141
142
**Usage:**
143
```python
144
from hues.colortable import STYLE
145
146
print(STYLE.bold) # 1
147
print(STYLE.italic) # 3
148
print(STYLE.reset) # 0
149
```
150
151
### Unified Keyword Mapping
152
153
Combined mapping of all color and style keywords to their numeric codes.
154
155
```python { .api }
156
KEYWORDS: namedtuple
157
"""
158
Unified keyword mapping for all colors and styles.
159
160
Contains all fields from STYLE, FG, plus prefixed versions:
161
- bg_* for background colors (from BG)
162
- bright_* for high intensity foreground (from HI_FG)
163
- bg_bright_* for high intensity background (from HI_BG)
164
"""
165
```
166
167
**Usage:**
168
```python
169
from hues.colortable import KEYWORDS
170
171
# Direct color access
172
print(KEYWORDS.red) # 31 (same as FG.red)
173
print(KEYWORDS.bg_red) # 41 (same as BG.red)
174
print(KEYWORDS.bright_red) # 91 (same as HI_FG.red)
175
print(KEYWORDS.bg_bright_red) # 101 (same as HI_BG.red)
176
177
# Style access
178
print(KEYWORDS.bold) # 1 (same as STYLE.bold)
179
print(KEYWORDS.reset) # 0 (same as STYLE.reset)
180
```
181
182
### ANSI Sequence Format
183
184
Template string for generating ANSI escape sequences.
185
186
```python { .api }
187
SEQ: str
188
"""
189
ANSI escape sequence format string: '\\033[%sm'
190
Used to format numeric codes into escape sequences.
191
"""
192
```
193
194
**Usage:**
195
```python
196
from hues.colortable import SEQ, FG
197
198
# Create ANSI escape sequence
199
red_sequence = SEQ % FG.red
200
print(repr(red_sequence)) # '\\033[31m'
201
202
# Multiple codes
203
codes = [FG.red, STYLE.bold]
204
multi_sequence = SEQ % ';'.join(map(str, codes))
205
print(repr(multi_sequence)) # '\\033[31;1m'
206
```
207
208
## Usage Examples
209
210
### Direct Color Code Access
211
212
```python
213
from hues.colortable import FG, BG, STYLE, SEQ
214
215
# Build escape sequence manually
216
def make_colored(text, fg_color, bg_color=None):
217
codes = [fg_color]
218
if bg_color:
219
codes.append(bg_color)
220
221
start = SEQ % ';'.join(map(str, codes))
222
end = SEQ % STYLE.reset
223
return start + text + end
224
225
# Use it
226
colored = make_colored('Hello', FG.red, BG.white)
227
print(colored) # Red text on white background
228
```
229
230
### Keyword-Based Access
231
232
```python
233
from hues.colortable import KEYWORDS
234
235
# Access any color/style by name
236
def get_code(name):
237
return getattr(KEYWORDS, name)
238
239
red_code = get_code('red') # 31
240
bg_blue_code = get_code('bg_blue') # 44
241
bold_code = get_code('bold') # 1
242
```
243
244
### Integration with HueString
245
246
These constants are used internally by HueString when you access color attributes:
247
248
```python
249
from hues import huestr
250
from hues.colortable import KEYWORDS
251
252
text = huestr('Hello')
253
254
# When you do text.red, it internally uses:
255
# KEYWORDS.red (which equals 31)
256
257
# When you do text.bg_green, it uses:
258
# KEYWORDS.bg_green (which equals 42)
259
```
260
261
## Constants Reference
262
263
### All Available Colors
264
265
**Standard Colors** (FG 30-37, BG 40-47):
266
- black, red, green, yellow, blue, magenta, cyan, white
267
268
**High Intensity Colors** (HI_FG 90-97, HI_BG 100-107):
269
- Same names as standard, accessed via KEYWORDS as bright_*
270
271
**Keyword Prefixes**:
272
- No prefix: foreground colors (FG)
273
- `bg_`: background colors (BG)
274
- `bright_`: high intensity foreground (HI_FG)
275
- `bg_bright_`: high intensity background (HI_BG)
276
277
**Styles**:
278
- reset (0), bold (1), italic (3), underline (4)
279
- defaultfg (39), defaultbg (49)