``ANSI escape sequences'' are special sequences of characters which do not print but which rather affect a display in some way. The basic syntax of an ANSI escape sequence is
ESC [ parameter(s) code
where
ESC is the ASCII ``Escape'' character (
'\033' or
'\x1B'),
[ is a single open square bracket character,
parameter(s) is a numeric parameter or semicolon-separated list of numeric parameters, and
code is a single character indicating the action to be performed. A (brief and incomplete) list of codes is:
| H
| move cursor; the two parameters are the row and column to move to
|
| J
| clear screen; the parameter 2 means clear the whole screen
|
| m
| set graphic rendition (see parameter list below) |
The graphic rendition codes include:
| 0
| return to normal (no attributes)
|
| 1
| bold
|
| 4
| underline
|
| 7
| inverse video
|
| 31
| red
|
| 32
| green
|
| 33
| yellow
|
| 34
| blue
|
| 35
| magenta
|
| 36
| cyan |
There are also codes in the 40's for setting the background color, e.g. 41 sets the background to red.
Several codes may appear at once, separated by semicolons.
printf("\033[2J"); /* clear screen */
printf("\033[%d;%dH", 10, 20); /* move cursor (row 10, col 20) */
printf("Hello, ");
printf("\033[7mworld\033[0m!"); /* inverse video */