-
Notifications
You must be signed in to change notification settings - Fork 16
/
ansi_sequences.theory.txt
490 lines (427 loc) · 28.6 KB
/
ansi_sequences.theory.txt
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
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
ANSI_SEQUENCES
Left to document:
- https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h3-Controls-beginning-with-ESC
- VT525 manual
- look at standards
- including reading their Wikipedia page first
- then try in different terminals and add support in this documentation
/=+===============================+=\
/ : : \
)==: SUPPORT :==(
\ :_______________________________: /
\=+===============================+=/
STANDARDS ==> #First implemented by VT*:
# - Line of computers from DEC which introduced the now-standardized ANSI sequences
# - Starting with VT52 in 1974, until VT525 in 1995
#Then standardized by:
# - ECMA-6, ISO/IEC 646, ASCII
# - ECMA-35, ISO/IEC 2022, JIS-X-0211
# - ECMA-48, ISO/IEC 6429, ANSI X3.64, FIPS-86
SUPPORT ==> #Symbols means not supported on:
~# - Gnome VTE (this doc does not check for support on other terminals then)
C# - Windows Console Host
E# - ConEmu
T# - terminal.app
#Windows support is rather recent (2016-2019)
ANSI.SYS ==> #MS-DOS library supporting a subset of ANSI sequences.
/=+===============================+=\
/ : : \
)==: OUTPUT SEQUENCES :==(
\ :_______________________________: /
\=+===============================+=/
CONTROL CHARACTERS ==> #Non-printing characters for in-band signaling, i.e. controls terminal behavior using input characters
#Types:
# - C0: \x00 to \x1f, also \x7f (DEL)
# - C1: \x80 to \x9f
#Unicode categories:
# - "Cc": C0|C1 control characters
# - "Cf": Unicode-specific control characters
NOTATIONS ==> #Representation for control characters:
# - caret notation (C0)
# - meant for terminal input with CTRL-CHAR
# - SHIFT usually optional
# - CTRL-V CTRL-CHAR: input the character, but without any behavior
# - backslash sequence (C0 partial):
# - introduced by C, meant for source code.
# - Fe escape sequence (C1)
#ANSI escape sequences:
# - perform a terminal control function
# - not a "character", but a magic sequence interpreted by terminals
# - commonly supported:
# - Fp escape sequence
# - Fs escape sequence
# - nF escape sequence
# - control sequence
# - device control string (DCS)
# - operating system command (OSC)
# - usually not supported:
# - control string
# - application program command (APC)
# - privacy message (PM)
#Notations:
#
# NAME START PARAMETERS INTERMEDIATE FINAL ANY TERMINATING
#
# Caret notation ^ @A-Z[\]^_
# backslash sequence \ a-z
# Fe escape sequence \e @A-Z[\]^_
# Fp escape sequence \e 0-9:;<=>?
# Fs escape sequence \e `a-z{|}~
# nF escape sequence \e SPC!"#$%&'()*+,-./ 0-9:;<=>?@A-Z[\]^_`a-z{|}~
# Control sequence \e[ 0-9:;<=>? SPC!"#$%&'()*+,-./ @A-Z[\]^_`a-z{|}~
# Device control string \eP 0-9:;<=>? SPC!"#$%&'()*+,-./ @A-Z[\]^_`a-z{|}~ any \e\
# Operating system command \e] Ascii\b\t\n\v\f\r \e\ \a
# Control string \eX any \e\
# Application program command \e_ any \e\
# Privacy message \e^ any \e\
#
#Start:
# - single byte
# - declare the sequence type
# - \e. are Fp escape sequences themselves, i.e. can be replaced by character directly
# - \e \e[ \eP \e] \eX \e_ \e^ -> \x1b (ESC) \x9b (CSI) \x90 (DCS) \x9D (OSC) \x98 (SOS) \9f (APC) \9e (PM)
#Parameters:
# - 0-n characters
# - for parameters|arguments
# - ;-separated list
# - except OSC:
# - often use digits
# - with default 0
# - <=>? are for "private sequences", i.e. terminal specific
# - ? is often used: "VT parameters"
#Intermediate bytes:
# - 0-n characters
# - 1-n charcters for nF
# - sub-action
#Final byte:
# - single character
# - main action
# - 0-9:;<=>? and p-z{|}~ are for "private sequences", i.e. terminal-specific
#Any characters:
# - ;-separated list of arbitrary strings
#Terminating byte:
# - \e\ is Fp escape sequence, i.e. can replace by \x9C (ST)
/=+===============================+=\
/ : : \
)==: INPUT SEQUENCES :==(
\ :_______________________________: /
\=+===============================+=/
TERMINAL INPUT SEQUENCE ==> #Input sequence which behaves like a specific key.
#Is \e[.~ where . is 0-n characters among 0-9A-Z
#Not ANSI sequences, just key shortcuts
READLINE SHORTCUTS ==> #Use CTRL-CHAR, but are not related to ANSI sequences nor control characters
SIGNALS ==> #Some CTRL-CHAR are listened by programs for signaling.
#On input, not output.
#Related to control characters, but are only CTRL-CHAR shortcuts.
#List:
# - CTRL-C (ETX): sends SIGINT to process, terminating it
# - CTRL-D (EOD): tells program that input ended, often causing input-reading programs to end
~# - CTRL-T (DC4): sends SIGINFO, i.e. ask for information about process
# - CTRL-Z (SUB): sends SIGTSTP to process, i.e. stop
# - CTRL-\ (FS): sends SIGQUIT to process, i.e. terminate with core dump
/=+===============================+=\
/ : : \
)==: CONTROL CHARACTERS :==(
\ :_______________________________: /
\=+===============================+=/
FORMAT EFFECTORS ==> #
09 HT ^I \t #Horizontal Tab
#Tab key.
08 BS ^H \b #Backspace
#Same line, previous column.
#Backspace key.
94 CCH \eT ~#Cancel character
~#Like \b
7F DEL ^? ~#Delete.
~#Erase current character
~#DEL key.
0D CR ^M \r #Carriage return.
#Same line, first column.
0B VT ^K \v C#Vertical Tab
C#Next line (tab), same column.
0C FF ^L \f C#Form feed
C#Either:
C# - end of page:
C# - clear screen (as input)
C# - next line (single), same column (as output)
C#Often not considered a newline nor whitepsace.
84 IND \eD C#Index
C#Like \f (next line, same column)
0A LF ^J \n #Line feed.
#Next line (single):
# - first column (Unix)
# - same column (Windows)
#Enter key.
85 NEL \eE C#Next Line
C#Like \n (next line, first column)
2028 LS ~#Line Separator
~#Like \n (next line, first column)
2029 PS #Paragraph Separator
#Like \n (next line, first column) but meant between paragraphs
#Sometimes printed as single space
8D RI \eM C#Reverse Index
C#Previous line, same column
88 HTS \eH ~#Horizontal Tabulation Set
~#Set a horizontal tabulation point.
89 HTJ \eI C#Horizontal Tabulation With Justification
8A VTS \eJ ~#Vertical Tabulation Set
~#Set a vertical tabulation point.
LINE BREAKS ==> #
82 BPH \eB ~#Break Permitted Here
~#Indicates line breaking can happen here.
83 NBH \eC ~#No Break Here
~#Indicates line breaking cannot happen here.
STYLING ==> #
8B PLD \eK ~#Partial Line Down
~#Subscript
8C PLU \eL ~#Partial Line Up
~#Superscript
80 PAD \e@ ~#Padding Character
NOOP ==> #
00 NUL ^@ #Null
#Meant for noop, padding, delimiter or reserved spaces.
# - ends a null-terminated-string.
# - used by some Unix commands to replace newlines.
16 SYN ^V ~#Synchronous Idle
~#Sent when there is no data
NOTIFICATION ==> #
07 BEL ^G \a #Bell
#Emit a sound. Often disabled.
ESCAPING ==> #
1B ESC ^[ \e #Escape.
#Start an escape sequence.
#If another escape sequence is ongoing, stop it
#ESC key.
1A SUB ^Z E#Substitute.
E#Can be:
E# - stop current escape sequence, printing an error character (question mark)
E# - EOF on Windows
~# - Next character should be minus 64, e.g. A -> ^A, etc.
~# Meant as a way to input caret notation with printable characters
18 CAN ^X E#Cancel.
E#Can be:
E# - stop current escape sequence, without making it an error
~# - Undo previous message
10 DLE ^P ~#Data Link Escape
~#Means next character should be escaped
81 HOP \eA ~#High Octet Preset
~#Changes encoding of next character
9B CSI \e[ T#Control Sequence Introducer
T#Start a control sequence
90 DCS \eP C#Device Control String
C#Start a device control string
9D OSC \e] C#Operating System Command
C#Start an operating system command
98 SOS \eX C#Start of String
C#Start a control string
9E PM \e^ C#Privacy Message
C#Start a privacy message
9F APC \e_ C#Application Program Command
C#Start an Application program command
9C ST \e\ C#String Terminator
C#Terminates a DCS, OSC, SOS, PM or APC
99 SGC \eY ~#Single Graphic Character Introducer
~#Start a multi-byte characters sequence
9A SCI \eZ ~#Single Character Introducer
~#Start a single character sequence
ALTERNATE ENCODING ==> #
0E SO ^N C#Shift Out
C#Enable alternate encoding G1
0F SI ^O C#Shift In
C#Forces default encoding G0
8E SS2 \eN ~#Single-Shift 2
~#Enable alternate encoding G2
8F SS3 \eO ~#Single-Shift 3
~#Enable alternate encoding G3
TRANSMISSION CONTROLS ==> #
05 ENQ ^E ~#Enquiry
~#Ask sender to start sending
04 EOT ^D ~#End of Transmission
~#Tell receiver that request ended
06 ACK ^F ~#Acknowledgment
~#Tell sender that request succeeded
15 NAK ^U ~#Negative Acknowledgement
~#Tell sender that request failed
93 STS \eS ~#Set Transmit State
95 MW \eU ~#Message Waiting
MESSAGE CONTROLS ==> #
01 SOH ^A ~#Start of Header
~#Starts metadata
02 STX ^B ~#Start of Text
~#Starts data
03 ETX ^C ~#End of Text
~#Ends data
17 ETB ^W ~#End of Transmission Block.
~#Ends metadata+data
INFORMATION SEPARATORS ==> #
19 EM ^Y ~#End of Medium
~#When terminal has no more available space.
1C FS ^\ ~#File Separator
~#Delimiters between files
1D GS ^] ~#Group Separator
~#Delimiters between group of records in a file (e.g. OBJ_ARR)
1E RS ^^ ~#Record Separator
~#Delimiters between records (e.g. OBJ)
1F US ^_ ~#Unit Separator
~#Delimiters between units (e.g. OBJ properties)
BLOCK-ORIENTED TERMINALS ==> #
86 SSA \eF ~#Start of Selected Area
~#Meant for block-oriented terminals.
87 ESA \eG ~#End of Selected Area
96 SPA \eV ~#Start of Protected Area
~#Meant for block-oriented terminals.
97 EPA \eW ~#End of Protected Area
APPLICATION-SPECIFIC ==> #
11 DC1 ^Q C#Device Control 1
C#Meant to be terminal-specific
C#Often implemented as XON, i.e. can receive data again (for stream buffering)
12 DC2 ^R ~#Device Control 2
13 DC3 ^S C#Device Control 3
C#Often implemented as XOFF, i.e. stop receiving (for stream buffering)
14 DC4 ^T ~#Device Control 4
91 PU1 \eQ ~#Private Use 1
~#Application-specific
92 PU2 \eR ~#Private Use 2
~#Application-specific
BIDIRECTIONAL ==> #
061c
200e
200f
202a-202f
2066-2069 #Change directionality of text
VARIATION SELECTORS ==> #Indicates a variation on the previous character
#Only for specific preceding character
#For example:
# - '\u25ab' ▫
# - '\u25ab\ufe0f' ▫️
fe00 #Serifs or alternate form
fe00-fe02 #Used with some CJK compatibility code points
fe03-fe0d #Unused
fe0e #Text|monochrome style
fe0f #Emoji|color style
e0100-e01ef #Variation selectors supplements
180b-180d #Mongolian letter forms
LANGUAGE TAGS ==> ~#Meant to indicate the current language
~#Discouraged by Unicode unless really needed by application
e0001 ~#Start language tag
~#Must contain the language name, e.g. "en-US" using e0020-e007e
e007f ~#End language tag
e0020-e007e ~#Like ASCII 20-7e, but not shown in output, because part of language tag
RUBY CHARACTER ==> #
fff9 ~#Start Ruby sequence, i.e. character on top of another in Asian languages
fffa ~#Start Ruby character
fffb ~#End Ruby sequence
/=+===============================+=\
/ : : \
)==: SEQUENCES :==(
\ :_______________________________: /
\=+===============================+=/
~ #Represents any number
#Defaults to 0
# - except CUU|CUD|CUF|CUB|CNL|CPL|CHA|CP|SU|SD, which defaults to 1
SCREEN EDGES ==> #Moves stops at edges of screen
#Index is 1-based
CURSOR POSITION ==> #Unless specified, the cursor position is not changed.
\e[~A
\e[~B
\e[~C #Cursor Up|Down|Forward|Back (CUU|CUD|CUF|CUB)
\e[~D #Move cursor up|down|right|left by ~ characters
\e[~E #Cursor Next|Previous Line (CNL|CPL)
\e[~F #Move cursor up|down by ~ characters then goes to start of line
\e[~G #Cursor Horizontal Absolute (CHA)
#Move cursor to column ~
\e[~;~H #Cursor Position (CP)
#Move cursor to row ~, column ~
\e[s #Save|Restore Current Cursor Position (SCOSC|SCORC or SCP|RCP)
\e[u #Save|restore cursor position
\e7 #DEC Save|Restore Cursor (DECSC|DECRC)
\e8 #Save|restore cursor position + styling
\ec #Reset to Initial State (RIS)
#Reset any terminal settings (including cursor position and clearing screen)
\e[~J #Erase in Display (ED)
#Clear lines:
# - 0: after current line (excluded)
# - 1: before current line (included)
# - 2: all lines
# - 3: all lines, and removes scrollback buffer (previous lines that can be scrolled to)
# - non-standard
# - on Windows Console Host, also moves cursor position to first line|column
\e[~K #Erase in Line (EL)
#Clear characters in current line:
# - 0: after cursor (included)
# - 1: before cursor (included)
# - 2: whole line
\e[~S #Scroll Up|Down (SU|SD)
\e[~T #Move all lines ~ up|down
#Lines going out of screen are gone. Does not actually scroll the terminal GUI.
\e[?25l #Text Cursor Enable Mode (DECTCEM)
\e[?25h #Show|hide cursor
\e[?1049h #Enable alternative screen buffer.
#I.e. saves the current screen, then clears it.
\e[?1049l #Restore saved screen.
\e[?2004h C#Enable|disable bracketed paste mode.
\e[?2004l C#Surround any pasted characters by \e[200~ and \e[201~
C#Some programs (like Vim) will detect these characters to know the text was entered as paste, not input
\e[~;...m #Select Graphic Rendition NUM (SGR NUM)
#Colors|style
#Remains in effect until reset by another SGR
\e[0m #Reset SGR
\e[1m C#Bold
C#On Windows: only use bright colors
\e[2m C#Dim
\e[3m C#Italic
\e[4m #Underline
\e[5m C#Slow blink
\e[6m ~#Fast blink. Often shown as slow blink instead.
\e[7m #Invert foreground|background color. Named "Reverse|invert video" (as opposed to "true video")
\e[8m C#Hidden, i.e. foreground has same color as background
\e[9m C#Strikethrough
\e[20m ~#Blackletter
\e[21m C#Double underline
\e[22m #Reset dim|bold
\e[23m C#Reset italic|blackletter
\e[24m #Reset underline
\e[25m C#Reset blink
\e[26m ~#Proportional spacing
\e[27m #Reset inverted
\e[28m C#Reset hide
\e[29m C#Reset strikethrough
\e[50m ~#Disable proportional spacing
\e[51m ~#Framed
\e[52m ~#Encircled
\e[53m C#Overlined
\e[54m ~#Reset framed|encircled
\e[55m C#Reset overlined
\e[60m ~#Ideogram underline
\e[61m ~#Ideogram double underline
\e[62m ~#Ideogram overline
\e[63m ~#Ideogram double overline
\e[64m ~#Ideogram stress marking
\e[65m ~#Reset ideogram underline|overline
\e[73m ~#Superscript
\e[74m ~#Subscript
\e[30-37m
\e[40-47m #Foreground|background 4-bits color: black|red|green|yellow|blue|magenta|cyan|white
\e[90-97m
\e[100-107m #Same for bright foreground|background 4-bits colors
\e[38;5;~m #Foreground|background 8-bits colors, using 0-255:
\e[48;5;~m # - 0-15: same as 4-bits colors
# - 16-231: 216 colors
# - 232-255: 24 grayscales
\e[38;2;~;~;~m
\e[48;2;~;~;~m #Foreground|background 24-bits colors, using reg|green|blue 0-255 ("true color")
\e[39m
\e[49m #Reset foreground|background color
\e[58;5;~m
\e[58;2;~;~;~m
\e[59m C#Like \e[3*m but for underline color
\e[10-19m C~#Choose between 10 user-chosen fonts.
\e[3h ~#Enable|disable "Control Representation Mode" (CRM)
\e[3l ~#Print control characters and make them have no behavior.
\e(0 #Select character set (SCS)
#Switch alternate encoding G1 to DEC special graphics, which replaces
# _ ` a b c d e f g h i j k l m n o p q r s t u v w x y z { | } ~
# by ◆ ▒ ␉ ␌ ␍ ␊ ° ±  ␋ ┘ ┐ ┌ └ ┼ ⎺ ⎻ ─ ⎼ ⎽ ├ ┤ ┴ ┬ │ ≤ ≥ π ≠ £ ·
\e(B #Set alternative encoding G1 to normal encoding