Standard escape codes are prefixed with Escape
:
-
Ctrl-Key:
^[
-
Octal:
\033
-
Unicode:
\u001b
-
Hexadecimal:
\x1B
-
Decimal:
27
-
CSI
- Control Sequence Introducer: sequence starting withESC [
or CSI (\x9B
)
Followed by the command, somtimes delimited by opening square bracket ([
), known as a Control Sequence Introducer (CSI), optionally followed by arguments and the command itself.
Arguments are delimeted by semi colon (;
).
For example:
\x1b[1;31m # Set style to bold, red foreground.
- Any whitespaces between sequences and arguments should be ignored. They are present for improved readability.
ESC Code Sequence | Description |
---|---|
ESC[H |
moves cursor to home position (0, 0) |
ESC[{line};{column}H ESC[{line};{column}f |
moves cursor to line #, column # |
ESC[#A |
moves cursor up # lines |
ESC[#B |
moves cursor down # lines |
ESC[#C |
moves cursor right # columns |
ESC[#d |
moves cursor to an absolute # line |
ESC[#D |
moves cursor left # columns |
ESC[#E |
moves cursor to beginning of next line, # lines down |
ESC[#F |
moves cursor to beginning of previous line, # lines up |
ESC[#G |
moves cursor to column # |
ESC[#S |
scrolls down # lines |
ESC[#T |
scrolls up # lines |
ESC Code Sequence | Description |
---|---|
ESC[J |
erase in display (same as ESC[0J) |
ESC[0J |
erase from cursor until end of screen |
ESC[1J |
erase from cursor to beginning of screen |
ESC[2J |
erase entire screen (set position:0,0) |
ESC[K |
erase in line (same as ESC[0K) |
ESC[0K |
erase from cursor to end of line |
ESC[1K |
erase start of line to the cursor |
ESC[2K |
erase the entire line |
ESC Code Sequence | Reset Sequence | Description |
---|---|---|
ESC[1;34;{...}m |
Set graphics modes for cell, separated by semicolon (; ). |
|
ESC[0m |
reset all modes (styles and colors) | |
ESC[7m |
ESC[27m |
set inverse/reverse mode |
Note: Colors are not supported and are ignored by terminal.
- Main Reference
- Wikipedia: ANSI escape code
- Build your own Command Line with ANSI escape codes
- ascii-table: ANSI Escape sequences
- bluesock: ansi codes
- bash-hackers: Terminal Codes (ANSI/VT100) introduction
- XTerm Control Sequences
- VT100 – Various terminal manuals
- xterm.js – Supported Terminal Sequences
- Microsoft Learn - Console virtual terminal sequences