created on | October 8, 2025 |
ANSI escape codes (more formally, ANSI escape sequences) are in-band signaling codes to control cursor location, color, and a bunch of other options on command line terminals.
The escape codes are prefixed with the escape char, ASCII/ANSI code (hexadecimal ) hence the name ’escape codes'.
The ANSI escape code , ‘reset’, restores the defaults.
This, as an example, is needed at the end of a prompt config line for a colored prompt to reset all attributes to their defaults.
foreground color | ANSI escape code |
---|---|
black | %[%033[1;30m%] |
red | %[%033[1;31m%] |
green | %[%033[0;32m%] |
yellow | %[%033[1;33m%] |
blue | %[%033[1;34m%] |
magenta | %[%033[1;35m%] |
cyan | %[%033[1;36m%] |
white | %[%033[0;37m%] |
background color | ANSI escape code |
---|---|
black | %[%033[1;40m%] |
red | %[%033[1;41m%] |
green | %[%033[0;42m%] |
yellow | %[%033[1;43m%] |
blue | %[%033[1;44m%] |
magenta | %[%033[1;45m%] |
cyan | %[%033[1;46m%] |
white | %[%033[0;47m%] |