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
| Code | Effect |
| ESC [nA | Moves 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 [nB | Moves 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 [nC | Moves 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 [nD | Moves 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;mf | Moves the cursor to row n, column m. If n is not given, 1 is used. |
| ESC [n;mH | Moves the cursor to row n, column m. If n is not given, 1 is used. |
| ESC [=nh | Set screen mode. |
| ESC [2J | Clears screen and sends cursor home. |
| ESC [K | Erases to end of the line. |
| ESC [=nl | Reset screen mode. |
| ESC [n...km | Sets graphics parameters. |
| ESC [code;param[;param]p | Redefines a key. |
| ESC [n;mR | Sets the cursor to row n, column m, and reports this to the system. |
| ESC [s | Saves the cursor position. |
| ESC [u | Restores the cursor position. |
Screen modes
| Code | Effect |
| 0 | 40 x 25 mono |
| 1 | 40 x 25 colour |
| 2 | 80 x 25 mono |
| 3 | 80 x 25 colour |
| 4 | 320 x 200 colour |
| 5 | 320 x 200 mono |
| 6 | 640 x 200 mono |
| 7 | Wrap at end of line |
Graphics parameters
| Code | Effect |
| 0 | All attributes off |
| 1 | Bold |
| 2 | Faint |
| 3 | Italic |
| 5 | Blink |
| 6 | Rapid blink |
| 7 | Reverse video |
| 8 | Concealed |
| 30 | Black foreground |
| 31 | Red foreground |
| 32 | Green foreground |
| 33 | Yellow foreground |
| 34 | Blue foreground |
| 35 | Magenta foreground |
| 36 | Cyan foreground |
| 37 | White foreground |
| 40 | Black background |
| 41 | Red background |
| 42 | Green background |
| 43 | Yellow background |
| 44 | Blue background |
| 45 | Magenta background |
| 46 | Cyan background |
| 47 | White background |
| 48 | Subscript |
| 49 | Superscript |