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
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
//! Property keys and constants for tracking which style properties are set.
//!
//! This module defines a bitfield-based system for efficiently tracking which
//! style properties have been explicitly set on a `Style` instance. Each property
//! is represented by a unique bit position, allowing for fast set/get operations
//! and compact storage.
//!
//! The system uses two main approaches:
//! - **Property Keys (`PropKey`)**: 64-bit values where each bit represents a specific property
//! - **Attribute Flags**: 32-bit values for boolean attributes that are stored as a bitfield
//!
//! # Design Rationale
//!
//! This approach allows the Style system to:
//! - Distinguish between "not set" and "set to default value"
//! - Efficiently check if a property has been explicitly configured
//! - Support style inheritance and composition
//! - Minimize memory usage through compact bitfield storage
//!
//! # Examples
//!
//! ```rust,ignore
//! // Internal usage - checking if a property is set
//! if self.props & BOLD_KEY != 0 {
//! // Bold property has been explicitly set
//! }
//!
//! // Setting a property
//! self.props |= FOREGROUND_KEY;
//! ```
/// Type alias for property keys used in the Style bitfield system.
///
/// Each `PropKey` represents a unique bit position in a 64-bit integer,
/// allowing up to 64 different style properties to be tracked. The keys
/// are used with bitwise operations to efficiently set, check, and clear
/// property flags.
///
/// # Usage
///
/// ```rust,ignore
/// // Check if a property is set
/// let is_set = (style.props & SOME_PROPERTY_KEY) != 0;
///
/// // Set a property
/// style.props |= SOME_PROPERTY_KEY;
///
/// // Clear a property
/// style.props &= !SOME_PROPERTY_KEY;
/// ```
pub type PropKey = u64;
// Text attribute properties - These track styling attributes that affect text rendering
/// Property key for bold text attribute.
///
/// When set, indicates that the bold styling has been explicitly configured,
/// regardless of whether it's enabled or disabled.
pub const BOLD_KEY: PropKey = 1 << 0;
/// Property key for italic text attribute.
///
/// When set, indicates that the italic styling has been explicitly configured,
/// regardless of whether it's enabled or disabled.
pub const ITALIC_KEY: PropKey = 1 << 1;
/// Property key for underline text attribute.
///
/// When set, indicates that the underline styling has been explicitly configured,
/// regardless of whether it's enabled or disabled.
pub const UNDERLINE_KEY: PropKey = 1 << 2;
/// Property key for strikethrough text attribute.
///
/// When set, indicates that the strikethrough styling has been explicitly configured,
/// regardless of whether it's enabled or disabled.
pub const STRIKETHROUGH_KEY: PropKey = 1 << 3;
/// Property key for reverse video text attribute.
///
/// When set, indicates that the reverse video styling (swapped foreground and background)
/// has been explicitly configured, regardless of whether it's enabled or disabled.
pub const REVERSE_KEY: PropKey = 1 << 4;
/// Property key for blinking text attribute.
///
/// When set, indicates that the blinking text styling has been explicitly configured,
/// regardless of whether it's enabled or disabled. Note that many modern terminals
/// don't support blinking text.
pub const BLINK_KEY: PropKey = 1 << 5;
/// Property key for faint (dim) text attribute.
///
/// When set, indicates that the faint/dim text styling has been explicitly configured,
/// regardless of whether it's enabled or disabled.
pub const FAINT_KEY: PropKey = 1 << 6;
/// Property key for underline spaces attribute.
///
/// When set, indicates that the "underline spaces" option has been explicitly configured.
/// This controls whether whitespace characters are also underlined when underline is enabled.
pub const UNDERLINE_SPACES_KEY: PropKey = 1 << 7;
/// Property key for strikethrough spaces attribute.
///
/// When set, indicates that the "strikethrough spaces" option has been explicitly configured.
/// This controls whether whitespace characters are also struck through when strikethrough is enabled.
pub const STRIKETHROUGH_SPACES_KEY: PropKey = 1 << 8;
/// Property key for color whitespace attribute.
///
/// When set, indicates that the "color whitespace" option has been explicitly configured.
/// This controls whether whitespace characters inherit foreground/background colors.
pub const COLOR_WHITESPACE_KEY: PropKey = 1 << 9;
// Color properties - These track whether colors have been explicitly set
/// Property key for foreground color.
///
/// When set, indicates that a foreground color has been explicitly configured,
/// even if it's set to a "no color" value.
pub const FOREGROUND_KEY: PropKey = 1 << 10;
/// Property key for background color.
///
/// When set, indicates that a background color has been explicitly configured,
/// even if it's set to a "no color" value.
pub const BACKGROUND_KEY: PropKey = 1 << 11;
// Size and alignment properties - These track dimensions and positioning
/// Property key for explicit width setting.
///
/// When set, indicates that a specific width has been explicitly configured,
/// overriding automatic width calculation.
pub const WIDTH_KEY: PropKey = 1 << 12;
/// Property key for explicit height setting.
///
/// When set, indicates that a specific height has been explicitly configured,
/// overriding automatic height calculation.
pub const HEIGHT_KEY: PropKey = 1 << 13;
/// Property key for horizontal alignment.
///
/// When set, indicates that horizontal alignment (left, center, right, or custom position)
/// has been explicitly configured.
pub const ALIGN_HORIZONTAL_KEY: PropKey = 1 << 14;
/// Property key for vertical alignment.
///
/// When set, indicates that vertical alignment (top, center, bottom, or custom position)
/// has been explicitly configured.
pub const ALIGN_VERTICAL_KEY: PropKey = 1 << 15;
// Padding properties - These track internal spacing configuration
/// Property key for top padding.
///
/// When set, indicates that top padding (space above content) has been
/// explicitly configured, even if set to zero.
pub const PADDING_TOP_KEY: PropKey = 1 << 16;
/// Property key for right padding.
///
/// When set, indicates that right padding (space to the right of content) has been
/// explicitly configured, even if set to zero.
pub const PADDING_RIGHT_KEY: PropKey = 1 << 17;
/// Property key for bottom padding.
///
/// When set, indicates that bottom padding (space below content) has been
/// explicitly configured, even if set to zero.
pub const PADDING_BOTTOM_KEY: PropKey = 1 << 18;
/// Property key for left padding.
///
/// When set, indicates that left padding (space to the left of content) has been
/// explicitly configured, even if set to zero.
pub const PADDING_LEFT_KEY: PropKey = 1 << 19;
// Margin properties - These track external spacing configuration
/// Property key for top margin.
///
/// When set, indicates that top margin (space above the styled box) has been
/// explicitly configured, even if set to zero.
pub const MARGIN_TOP_KEY: PropKey = 1 << 20;
/// Property key for right margin.
///
/// When set, indicates that right margin (space to the right of the styled box) has been
/// explicitly configured, even if set to zero.
pub const MARGIN_RIGHT_KEY: PropKey = 1 << 21;
/// Property key for bottom margin.
///
/// When set, indicates that bottom margin (space below the styled box) has been
/// explicitly configured, even if set to zero.
pub const MARGIN_BOTTOM_KEY: PropKey = 1 << 22;
/// Property key for left margin.
///
/// When set, indicates that left margin (space to the left of the styled box) has been
/// explicitly configured, even if set to zero.
pub const MARGIN_LEFT_KEY: PropKey = 1 << 23;
/// Property key for margin background color.
///
/// When set, indicates that a background color for margin areas has been
/// explicitly configured.
pub const MARGIN_BACKGROUND_KEY: PropKey = 1 << 24;
// Border properties - These track border configuration
/// Property key for border style.
///
/// When set, indicates that a border style (normal, rounded, thick, etc.) has been
/// explicitly configured.
pub const BORDER_STYLE_KEY: PropKey = 1 << 25;
// Border edge properties - These track which border edges are enabled
/// Property key for top border edge.
///
/// When set, indicates that the top border edge visibility has been
/// explicitly configured (enabled or disabled).
pub const BORDER_TOP_KEY: PropKey = 1 << 26;
/// Property key for right border edge.
///
/// When set, indicates that the right border edge visibility has been
/// explicitly configured (enabled or disabled).
pub const BORDER_RIGHT_KEY: PropKey = 1 << 27;
/// Property key for bottom border edge.
///
/// When set, indicates that the bottom border edge visibility has been
/// explicitly configured (enabled or disabled).
pub const BORDER_BOTTOM_KEY: PropKey = 1 << 28;
/// Property key for left border edge.
///
/// When set, indicates that the left border edge visibility has been
/// explicitly configured (enabled or disabled).
pub const BORDER_LEFT_KEY: PropKey = 1 << 29;
// Border foreground color properties - These track border text colors
/// Property key for top border foreground color.
///
/// When set, indicates that the foreground color for the top border edge
/// has been explicitly configured.
pub const BORDER_TOP_FOREGROUND_KEY: PropKey = 1 << 30;
/// Property key for right border foreground color.
///
/// When set, indicates that the foreground color for the right border edge
/// has been explicitly configured.
pub const BORDER_RIGHT_FOREGROUND_KEY: PropKey = 1 << 31;
/// Property key for bottom border foreground color.
///
/// When set, indicates that the foreground color for the bottom border edge
/// has been explicitly configured.
pub const BORDER_BOTTOM_FOREGROUND_KEY: PropKey = 1 << 32;
/// Property key for left border foreground color.
///
/// When set, indicates that the foreground color for the left border edge
/// has been explicitly configured.
pub const BORDER_LEFT_FOREGROUND_KEY: PropKey = 1 << 33;
// Border background color properties - These track border background colors
/// Property key for top border background color.
///
/// When set, indicates that the background color for the top border edge
/// has been explicitly configured.
pub const BORDER_TOP_BACKGROUND_KEY: PropKey = 1 << 34;
/// Property key for right border background color.
///
/// When set, indicates that the background color for the right border edge
/// has been explicitly configured.
pub const BORDER_RIGHT_BACKGROUND_KEY: PropKey = 1 << 35;
/// Property key for bottom border background color.
///
/// When set, indicates that the background color for the bottom border edge
/// has been explicitly configured.
pub const BORDER_BOTTOM_BACKGROUND_KEY: PropKey = 1 << 36;
/// Property key for left border background color.
///
/// When set, indicates that the background color for the left border edge
/// has been explicitly configured.
pub const BORDER_LEFT_BACKGROUND_KEY: PropKey = 1 << 37;
// Other properties - Miscellaneous style configuration flags
/// Property key for inline rendering mode.
///
/// When set, indicates that inline rendering mode has been explicitly configured.
/// Inline mode affects how the styled content is rendered in relation to surrounding text.
pub const INLINE_KEY: PropKey = 1 << 38;
/// Property key for maximum width constraint.
///
/// When set, indicates that a maximum width limit has been explicitly configured.
/// Content will be wrapped or truncated to fit within this width.
pub const MAX_WIDTH_KEY: PropKey = 1 << 39;
/// Property key for maximum height constraint.
///
/// When set, indicates that a maximum height limit has been explicitly configured.
/// Content will be truncated to fit within this height.
pub const MAX_HEIGHT_KEY: PropKey = 1 << 40;
/// Property key for tab width setting.
///
/// When set, indicates that a custom tab width has been explicitly configured,
/// overriding the default tab width for tab character rendering.
pub const TAB_WIDTH_KEY: PropKey = 1 << 41;
/// Property key for text transform function.
///
/// When set, indicates that a text transformation function has been explicitly configured.
/// This function will be applied to the content during rendering.
pub const TRANSFORM_KEY: PropKey = 1 << 42;
// Default values - These define standard default values for properties
/// Default tab width in characters.
///
/// This is the standard width used for tab characters when no custom tab width
/// has been configured. The value of 4 is commonly used in many text editors
/// and terminals.
pub const TAB_WIDTH_DEFAULT: i32 = 4;
// Attribute bitfield constants for Style struct - These store the actual boolean values
//
// Unlike the PropKey constants above (which track whether a property has been SET),
// these ATTR constants store the actual boolean values of attributes in a compact bitfield.
// They are used in the Style struct's `attrs` field for efficient storage and fast access.
/// Attribute flag for bold text.
///
/// When this bit is set in the Style's `attrs` field, bold text rendering is enabled.
pub const ATTR_BOLD: u32 = 1 << 0;
/// Attribute flag for italic text.
///
/// When this bit is set in the Style's `attrs` field, italic text rendering is enabled.
pub const ATTR_ITALIC: u32 = 1 << 1;
/// Attribute flag for underlined text.
///
/// When this bit is set in the Style's `attrs` field, underlined text rendering is enabled.
pub const ATTR_UNDERLINE: u32 = 1 << 2;
/// Attribute flag for strikethrough text.
///
/// When this bit is set in the Style's `attrs` field, strikethrough text rendering is enabled.
pub const ATTR_STRIKETHROUGH: u32 = 1 << 3;
/// Attribute flag for reverse video text.
///
/// When this bit is set in the Style's `attrs` field, reverse video (inverted colors) is enabled.
pub const ATTR_REVERSE: u32 = 1 << 4;
/// Attribute flag for blinking text.
///
/// When this bit is set in the Style's `attrs` field, blinking text rendering is enabled.
/// Note that many modern terminals don't support or ignore blinking text.
pub const ATTR_BLINK: u32 = 1 << 5;
/// Attribute flag for faint (dim) text.
///
/// When this bit is set in the Style's `attrs` field, faint/dim text rendering is enabled.
pub const ATTR_FAINT: u32 = 1 << 6;
/// Attribute flag for underlining whitespace characters.
///
/// When this bit is set in the Style's `attrs` field, whitespace characters (spaces, tabs)
/// will also be underlined when underline is enabled.
pub const ATTR_UNDERLINE_SPACES: u32 = 1 << 7;
/// Attribute flag for striking through whitespace characters.
///
/// When this bit is set in the Style's `attrs` field, whitespace characters (spaces, tabs)
/// will also be struck through when strikethrough is enabled.
pub const ATTR_STRIKETHROUGH_SPACES: u32 = 1 << 8;
/// Attribute flag for coloring whitespace characters.
///
/// When this bit is set in the Style's `attrs` field, whitespace characters will inherit
/// the foreground and background colors of the style.
pub const ATTR_COLOR_WHITESPACE: u32 = 1 << 9;
/// Attribute flag for inline rendering mode.
///
/// When this bit is set in the Style's `attrs` field, the content will be rendered
/// inline without adding extra whitespace or line breaks.
pub const ATTR_INLINE: u32 = 1 << 10;
/// Attribute flag for top border visibility.
///
/// When this bit is set in the Style's `attrs` field, the top border edge is visible.
pub const ATTR_BORDER_TOP: u32 = 1 << 11;
/// Attribute flag for right border visibility.
///
/// When this bit is set in the Style's `attrs` field, the right border edge is visible.
pub const ATTR_BORDER_RIGHT: u32 = 1 << 12;
/// Attribute flag for bottom border visibility.
///
/// When this bit is set in the Style's `attrs` field, the bottom border edge is visible.
pub const ATTR_BORDER_BOTTOM: u32 = 1 << 13;
/// Attribute flag for left border visibility.
///
/// When this bit is set in the Style's `attrs` field, the left border edge is visible.
pub const ATTR_BORDER_LEFT: u32 = 1 << 14;