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
// Copyright (c) 2025 R3BL LLC. Licensed under Apache License, Version 2.0.
//! This module contains all the constant values used in CSI (Control Sequence Introducer)
//! sequences, organized by functional category.
// CSI sequence components.
/// CSI sequence start: ESC [
pub const CSI_START: &str = "\x1b[";
/// Private mode prefix for CSI sequences
pub const CSI_PRIVATE_MODE_PREFIX: char = '?';
/// Parameter separator in CSI sequences (semicolon)
///
/// Used to separate top-level parameters in CSI sequences:
/// - `ESC[1;5H` - Cursor position (row 1, column 5)
/// - `ESC[1;31m` - Bold + red foreground
pub const CSI_PARAM_SEPARATOR: char = ';';
/// Sub-parameter separator in CSI sequences (colon)
///
/// Used to separate sub-parameters within a single CSI parameter:
/// - `ESC[38:5:196m` - 256-color foreground (38 = fg extended, 5 = palette mode, 196 =
/// index)
/// - `ESC[48:2:255:128:0m` - RGB background (48 = bg extended, 2 = RGB mode, 255:128:0 =
/// RGB)
///
/// Per [ITU-T Rec. T.416] (ISO 8613-6), the colon (`:`) is the recommended modern format
/// for sub-parameters, while semicolon (`;`) is supported for legacy compatibility.
///
/// [ITU-T Rec. T.416]: https://www.itu.int/rec/T-REC-T.416-199303-I
pub const CSI_SUB_PARAM_SEPARATOR: char = ':';
// Cursor Movement.
/// CSI A: Cursor Up (CUU)
/// Moves cursor up by n lines (default 1)
pub const CUU_CURSOR_UP: char = 'A';
/// CSI B: Cursor Down (CUD)
/// Moves cursor down by n lines (default 1)
pub const CUD_CURSOR_DOWN: char = 'B';
/// CSI C: Cursor Forward/Right (CUF)
/// Moves cursor forward by n columns (default 1)
pub const CUF_CURSOR_FORWARD: char = 'C';
/// CSI D: Cursor Backward/Left (CUB)
/// Moves cursor backward by n columns (default 1)
pub const CUB_CURSOR_BACKWARD: char = 'D';
/// CSI E: Cursor Next Line (CNL)
/// Moves cursor to beginning of line n lines down (default 1)
pub const CNL_CURSOR_NEXT_LINE: char = 'E';
/// CSI F: Cursor Previous Line (CPL)
/// Moves cursor to beginning of line n lines up (default 1)
pub const CPL_CURSOR_PREV_LINE: char = 'F';
/// CSI G: Cursor Horizontal Absolute (CHA)
/// Moves cursor to column n (default 1)
pub const CHA_CURSOR_COLUMN: char = 'G';
/// CSI H: Cursor Position (CUP)
/// Moves cursor to row n, column m (default 1,1)
pub const CUP_CURSOR_POSITION: char = 'H';
/// CSI f: Horizontal and Vertical Position (HVP)
/// Same as CUP - moves cursor to row n, column m (default 1,1)
pub const HVP_CURSOR_POSITION: char = 'f';
// Erasing.
/// CSI J: Erase in Display (ED)
/// 0 = erase from cursor to end of screen (default)
/// 1 = erase from start of screen to cursor
/// 2 = erase entire screen
/// 3 = erase entire screen and scrollback
pub const ED_ERASE_DISPLAY: char = 'J';
/// CSI K: Erase in Line (EL)
/// 0 = erase from cursor to end of line (default)
/// 1 = erase from start of line to cursor
/// 2 = erase entire line
pub const EL_ERASE_LINE: char = 'K';
// Erase Display Parameters (ED).
/// Erase from cursor to end of screen (default for ED)
pub const ED_ERASE_TO_END: u16 = 0;
/// Erase from start of screen to cursor
pub const ED_ERASE_FROM_START: u16 = 1;
/// Erase entire screen
pub const ED_ERASE_ALL: u16 = 2;
/// Erase entire screen and scrollback
pub const ED_ERASE_ALL_AND_SCROLLBACK: u16 = 3;
// Erase Line Parameters (EL).
/// Erase from cursor to end of line (default for EL)
pub const EL_ERASE_TO_END: u16 = 0;
/// Erase from start of line to cursor
pub const EL_ERASE_FROM_START: u16 = 1;
/// Erase entire line
pub const EL_ERASE_ALL: u16 = 2;
// Scrolling.
/// CSI S: Scroll Up (SU)
/// Scrolls text up by n lines (default 1)
pub const SU_SCROLL_UP: char = 'S';
/// CSI T: Scroll Down (SD)
/// Scrolls text down by n lines (default 1)
pub const SD_SCROLL_DOWN: char = 'T';
/// DECSTBM - Set Top and Bottom Margins - ESC [ top ; bottom r
pub const DECSTBM_SET_MARGINS: char = 'r';
// Line Operations.
/// CSI L: Insert Line (IL)
/// Inserts one or more blank lines, starting at the cursor
/// Lines below cursor and in scrolling region move down
pub const IL_INSERT_LINE: char = 'L';
/// CSI M: Delete Line (DL)
/// Deletes one or more lines in the scrolling region, starting with cursor line
/// Lines below cursor move up, blank lines added at bottom
pub const DL_DELETE_LINE: char = 'M';
// Character Operations.
/// CSI P: Delete Character (DCH)
/// Deletes one or more characters on current line
/// Characters to the right shift left, blanks inserted at end
pub const DCH_DELETE_CHAR: char = 'P';
/// CSI @: Insert Character (ICH)
/// Inserts one or more blank characters at cursor position
/// Characters to the right shift right, rightmost characters lost
pub const ICH_INSERT_CHAR: char = '@';
/// CSI X: Erase Character (ECH)
/// Erases one or more characters at cursor position
/// Characters are replaced with blanks, no shifting occurs
pub const ECH_ERASE_CHAR: char = 'X';
// Additional Cursor Positioning.
/// CSI d: Vertical Position Absolute (VPA)
/// Moves cursor to specified row (default 1)
/// Horizontal position unchanged
pub const VPA_VERTICAL_POSITION: char = 'd';
// Text Formatting (SGR).
/// CSI m: Select Graphic Rendition (SGR)
/// Sets colors and text attributes
pub const SGR_SET_GRAPHICS: char = 'm';
// SGR Parameters.
/// Reset all attributes
pub const SGR_RESET: u16 = 0;
/// Bold/Bright
pub const SGR_BOLD: u16 = 1;
/// Dim/Faint
pub const SGR_DIM: u16 = 2;
/// Italic
pub const SGR_ITALIC: u16 = 3;
/// Underline
pub const SGR_UNDERLINE: u16 = 4;
/// Slow Blink
pub const SGR_BLINK: u16 = 5;
/// Rapid Blink
pub const SGR_RAPID_BLINK: u16 = 6;
/// Reverse/Inverse
pub const SGR_REVERSE: u16 = 7;
/// Hidden/Conceal
pub const SGR_HIDDEN: u16 = 8;
/// Strikethrough
pub const SGR_STRIKETHROUGH: u16 = 9;
/// Reset Bold/Dim
pub const SGR_RESET_BOLD_DIM: u16 = 22;
/// Reset Italic
pub const SGR_RESET_ITALIC: u16 = 23;
/// Reset Underline
pub const SGR_RESET_UNDERLINE: u16 = 24;
/// Reset Blink
pub const SGR_RESET_BLINK: u16 = 25;
/// Reset Reverse
pub const SGR_RESET_REVERSE: u16 = 27;
/// Reset Hidden
pub const SGR_RESET_HIDDEN: u16 = 28;
/// Reset Strikethrough
pub const SGR_RESET_STRIKETHROUGH: u16 = 29;
// Foreground Colors (30-37, 90-97).
/// Black foreground
pub const SGR_FG_BLACK: u16 = 30;
/// Red foreground
pub const SGR_FG_RED: u16 = 31;
/// Green foreground
pub const SGR_FG_GREEN: u16 = 32;
/// Yellow foreground
pub const SGR_FG_YELLOW: u16 = 33;
/// Blue foreground
pub const SGR_FG_BLUE: u16 = 34;
/// Magenta foreground
pub const SGR_FG_MAGENTA: u16 = 35;
/// Cyan foreground
pub const SGR_FG_CYAN: u16 = 36;
/// White/Gray foreground
pub const SGR_FG_WHITE: u16 = 37;
/// Default foreground
pub const SGR_FG_DEFAULT: u16 = 39;
/// Bright Black foreground
pub const SGR_FG_BRIGHT_BLACK: u16 = 90;
/// Bright Red foreground
pub const SGR_FG_BRIGHT_RED: u16 = 91;
/// Bright Green foreground
pub const SGR_FG_BRIGHT_GREEN: u16 = 92;
/// Bright Yellow foreground
pub const SGR_FG_BRIGHT_YELLOW: u16 = 93;
/// Bright Blue foreground
pub const SGR_FG_BRIGHT_BLUE: u16 = 94;
/// Bright Magenta foreground
pub const SGR_FG_BRIGHT_MAGENTA: u16 = 95;
/// Bright Cyan foreground
pub const SGR_FG_BRIGHT_CYAN: u16 = 96;
/// Bright White foreground
pub const SGR_FG_BRIGHT_WHITE: u16 = 97;
// Background Colors (40-47, 100-107).
/// Black background
pub const SGR_BG_BLACK: u16 = 40;
/// Red background
pub const SGR_BG_RED: u16 = 41;
/// Green background
pub const SGR_BG_GREEN: u16 = 42;
/// Yellow background
pub const SGR_BG_YELLOW: u16 = 43;
/// Blue background
pub const SGR_BG_BLUE: u16 = 44;
/// Magenta background
pub const SGR_BG_MAGENTA: u16 = 45;
/// Cyan background
pub const SGR_BG_CYAN: u16 = 46;
/// White/Gray background
pub const SGR_BG_WHITE: u16 = 47;
/// Default background
pub const SGR_BG_DEFAULT: u16 = 49;
/// Bright Black background
pub const SGR_BG_BRIGHT_BLACK: u16 = 100;
/// Bright Red background
pub const SGR_BG_BRIGHT_RED: u16 = 101;
/// Bright Green background
pub const SGR_BG_BRIGHT_GREEN: u16 = 102;
/// Bright Yellow background
pub const SGR_BG_BRIGHT_YELLOW: u16 = 103;
/// Bright Blue background
pub const SGR_BG_BRIGHT_BLUE: u16 = 104;
/// Bright Magenta background
pub const SGR_BG_BRIGHT_MAGENTA: u16 = 105;
/// Bright Cyan background
pub const SGR_BG_BRIGHT_CYAN: u16 = 106;
/// Bright White background
pub const SGR_BG_BRIGHT_WHITE: u16 = 107;
// Extended Color Support (256-color and RGB).
/// Extended foreground color (SGR 38)
///
/// Used in sequences like:
/// - `ESC[38:5:nM` - 256-color foreground (n = 0-255)
/// - `ESC[38:2:r:g:bM` - RGB foreground (r,g,b = 0-255)
pub const SGR_FG_EXTENDED: u16 = 38;
/// Extended background color (SGR 48)
///
/// Used in sequences like:
/// - `ESC[48:5:nM` - 256-color background (n = 0-255)
/// - `ESC[48:2:r:g:bM` - RGB background (r,g,b = 0-255)
pub const SGR_BG_EXTENDED: u16 = 48;
/// 256-color mode indicator
///
/// Second parameter in 256-color sequences:
/// - `ESC[38:5:nM` - 256-color foreground
/// - `ESC[48:5:nM` - 256-color background
pub const SGR_COLOR_MODE_256: u16 = 5;
/// RGB color mode indicator
///
/// Second parameter in RGB color sequences:
/// - `ESC[38:2:r:g:bM` - RGB foreground
/// - `ESC[48:2:r:g:bM` - RGB background
pub const SGR_COLOR_MODE_RGB: u16 = 2;
// Cursor Save/Restore (CSI versions).
/// CSI s: Save Cursor Position (SCP)
/// Alternative to ESC 7
pub const SCP_SAVE_CURSOR: char = 's';
/// CSI u: Restore Cursor Position (RCP)
/// Alternative to ESC 8
pub const RCP_RESTORE_CURSOR: char = 'u';
// Device Status.
/// CSI n: Device Status Report (DSR)
/// 5 = request status
/// 6 = request cursor position
pub const DSR_DEVICE_STATUS: char = 'n';
// Mode Setting.
/// CSI h: Set Mode (SM)
/// Sets various terminal modes
pub const SM_SET_MODE: char = 'h';
/// CSI l: Reset Mode (RM)
/// Resets various terminal modes
pub const RM_RESET_MODE: char = 'l';
// Private Mode Setting (with ? prefix).
/// CSI ? h: Set Private Mode
/// Sets DEC private modes
pub const SM_SET_PRIVATE_MODE: char = 'h';
/// CSI ? l: Reset Private Mode
/// Resets DEC private modes
pub const RM_RESET_PRIVATE_MODE: char = 'l';
// Common Private Mode Numbers.
/// Show cursor (DECTCEM)
pub const DECTCEM_SHOW_CURSOR: u16 = 25;
// NOTE: General terminal mode constants (DEC modes 1-7, alternate screen buffer,
// mouse tracking, bracketed paste, etc.) are defined in the parent `protocols`
// module constants file (`protocols/generic_ansi_constants.rs`) rather than here.
//
// This separation reflects the architectural distinction:
// - **This file (`csi_codes/csi_constants.rs`)**: CSI-specific sequencing details
// - **Parent file (`protocols/generic_ansi_constants.rs`)**: General ANSI/terminal
// feature constants