Main Page | See live article | Alphabetical index

ANSI escape code

ANSI escape codes are used to specify visual effects on text terminals. They are typically initiated with the characters \\e (backslash-'e') and [ (left bracket). From the MS-DOS prompt command, the escape character can be specified as $e, e.g. prompt $e[44m;... would specify a blue background as part of the prompt. DOS systems need a driver for the ANSI codes - typically ansi.sys, but there are others used.

Some ANSI codes
CodeEffect
ESC [nAMoves the cursor up n rows. If the cursor is already at the top of the screen, this has no effect. If n is not given, 1 is used.
ESC [nBMoves the cursor down n rows. If the cursor is already at the bottom of the screen, this has no effect. If n is not given, 1 is used.
ESC [nCMoves the cursor right n rows. If the cursor is already at the edge of the screen, this has no effect. If n is not given, 1 is used.
ESC [nDMoves the cursor left n rows. If the cursor is already at the edge of the screen, this has no effect. If n is not given, 1 is used.
ESC [n;mfMoves the cursor to row n, column m. If n is not given, 1 is used.
ESC [n;mHMoves the cursor to row n, column m. If n is not given, 1 is used.
ESC [=nhSet screen mode.
ESC [2JClears screen and sends cursor home.
ESC [KErases to end of the line.
ESC [=nlReset screen mode.
ESC [n...kmSets graphics parameters.
ESC [code;param[;param]pRedefines a key.
ESC [n;mRSets the cursor to row n, column m, and reports this to the system.
ESC [sSaves the cursor position.
ESC [uRestores the cursor position.

Screen modes
CodeEffect
040 x 25 mono
140 x 25 colour
280 x 25 mono
380 x 25 colour
4320 x 200 colour
5320 x 200 mono
6640 x 200 mono
7Wrap at end of line

Graphics parameters
CodeEffect
0All attributes off
1Bold
2Faint
3Italic
5Blink
6Rapid blink
7Reverse video
8Concealed
30Black foreground
31Red foreground
32Green foreground
33Yellow foreground
34Blue foreground
35Magenta foreground
36Cyan foreground
37White foreground
40Black background
41Red background
42Green background
43Yellow background
44Blue background
45Magenta background
46Cyan background
47White background
48Subscript
49Superscript