undefined behavior

tb;dr - too boring; don’t read

Recent All Posts Categories Tags About Search

ANSI Escape Code Collection

The information in this collection is from Internet, which is collected for my personal convenience.

CSI sequences

CodeNameEffect
CSI n ACUU – Cursor UpMoves the cursor n (default 1) cells in the given direction. If the cursor is already at the edge of the screen, this has no effect.
CSI n BCUD – Cursor Down
CSI n CCUF – Cursor Forward
CSI n DCUB – Cursor Back
CSI n ECNL – Cursor Next LineMoves cursor to beginning of the line n (default 1) lines down. (not ANSI.SYS)
CSI n FCPL – Cursor Previous LineMoves cursor to beginning of the line n (default 1) lines up. (not ANSI.SYS)
CSI n GCHA – Cursor Horizontal AbsoluteMoves the cursor to column n (default 1). (not ANSI.SYS)
CSI n ; m HCUP – Cursor PositionMoves the cursor to row n, column m. The values are 1-based, and default to 1 (top left corner) if omitted. A sequence such as CSI ;5H is a synonym for CSI 1;5H as well as CSI 17;H is the same as CSI 17H and CSI 17;1H
CSI n JED – Erase in DisplayClears part of the screen. If n is 0 (or missing), clear from cursor to end of screen. If n is 1, clear from cursor to beginning of the screen. If n is 2, clear entire screen (and moves cursor to upper left on DOS ANSI.SYS). If n is 3, clear entire screen and delete all lines saved in the scrollback buffer (this feature was added for xterm and is supported by other terminal applications).
CSI n KEL – Erase in LineErases part of the line. If n is 0 (or missing), clear from cursor to the end of the line. If n is 1, clear from cursor to beginning of the line. If n is 2, clear entire line. Cursor position does not change.
CSI n SSU – Scroll UpScroll whole page up by n (default 1) lines. New lines are added at the bottom. (not ANSI.SYS)
CSI n TSD – Scroll DownScroll whole page down by n (default 1) lines. New lines are added at the top. (not ANSI.SYS)
CSI n ; m fHVP – Horizontal Vertical PositionSame as CUP
CSI n mSGR – Select Graphic RenditionSets the appearance of the following characters, see SGR parameters below.
CSI 5iAUX Port OnEnable aux serial port usually for local serial printer
CSI 4iAUX Port OffDisable aux serial port usually for local serial printer
CSI 6nDSR – Device Status ReportReports the cursor position (CPR) to the application as (as though typed at the keyboard) ESC[n;mR, where n is the row and m is the column.)
CSI sSCP – Save Cursor PositionSaves the cursor position/state.
CSI uRCP – Restore Cursor PositionRestores the cursor position/state.
CodeEffect
CSI ? 25 hDECTCEM Shows the cursor, from the VT320.
CSI ? 25 lDECTCEM Hides the cursor.
CSI ? 1049 hEnable alternative screen buffer
CSI ? 1049 lDisable alternative screen buffer
CSI ? 2004 hTurn on bracketed paste mode. Text pasted into the terminal will be surrounded by ESC [200~ and ESC [201~, and characters in it should not be treated as commands (for example in Vim).[20] From Unix terminal emulators.
CSI ? 2004 lTurn off bracketed paste mode.

SGR parameters

CodeEffectNote
0Reset / Normalall attributes off
1Bold or increased intensity
2Faint (decreased intensity)
3ItalicNot widely supported. Sometimes treated as inverse.
4Underline
5Slow Blinkless than 150 per minute
6Rapid BlinkMS-DOS ANSI.SYS; 150+ per minute; not widely supported
7reverse videoswap foreground and background colors
8ConcealNot widely supported.
9Crossed-outCharacters legible, but marked for deletion.
10Primary(default) font
11–19Alternative fontSelect alternative font {\displaystyle n-10} {\displaystyle n-10}
20FrakturRarely supported
21Doubly underline or Bold offDouble-underline per ECMA-48.[22] See discussion
22Normal color or intensityNeither bold nor faint
23Not italic, not Fraktur
24Underline offNot singly or doubly underlined
25Blink off
27Inverse off
28Revealconceal off
29Not crossed out
30–37Set foreground colorSee color table below
38Set foreground colorNext arguments are 5;n or 2;r;g;b, see below
39Default foreground colorimplementation defined (according to standard)
40–47Set background colorSee color table below
48Set background colorNext arguments are 5;n or 2;r;g;b, see below
49Default background colorimplementation defined (according to standard)
51Framed
52Encircled
53Overlined
54Not framed or encircled
55Not overlined
60ideogram underline or right side lineRarely supported
61ideogram double underline or double line on the right sideRarely supported
62ideogram overline or left side lineRarely supported
63ideogram double overline or double line on the left sideRarely supported
64ideogram stress markingRarely supported
65ideogram attributes offreset the effects of all of 60–64
90–97Set bright foreground coloraixterm (not in standard)
100–107Set bright background coloraixterm (not in standard)

Color code

ColorForegroundBackground
Black\u001b[30m\u001b[40m
Red\u001b[31m\u001b[41m
Green\u001b[32m\u001b[42m
Yellow\u001b[33m\u001b[43m
Blue\u001b[34m\u001b[44m
Magenta\u001b[35m\u001b[45m
Cyan\u001b[36m\u001b[46m
White\u001b[37m\u001b[47m
Bright Black\u001b[30;1m\u001b[40;1m
Bright Red\u001b[31;1m\u001b[41;1m
Bright Green\u001b[32;1m\u001b[42;1m
Bright Yellow\u001b[33;1m\u001b[43;1m
Bright Blue\u001b[34;1m\u001b[44;1m
Bright Magenta\u001b[35;1m\u001b[45;1m
Bright Cyan\u001b[36;1m\u001b[46;1m
Bright White\u001b[37;1m\u001b[47;1m
Reset\u001b[0m\u001b[0m