Skip to content

Instantly share code, notes, and snippets.

@sam-roth
Last active September 26, 2018 17:23
Show Gist options
  • Save sam-roth/2b0cf0a88efcb99970b39bdb3cdd8e39 to your computer and use it in GitHub Desktop.
Save sam-roth/2b0cf0a88efcb99970b39bdb3cdd8e39 to your computer and use it in GitHub Desktop.
How to Remember ANSI Escape Codes for Color

How to Remember ANSI Escape Codes for Color

ANSI escape codes set the attributes and positioning of text in a terminal. A common use of these codes is to set the text color.

The code "\033[3xm" sets the foreground color x. These values are the decimal representation of a three-bit BGR color:

blue green red binary decimal (x) color
0 0 0 000 0 black
0 0 1 001 1 red
0 1 0 010 2 green
0 1 1 011 3 yellow (green+red)
1 0 0 100 4 blue
1 0 1 101 5 magenta (blue+red)
1 1 0 110 6 cyan (blue+green)
1 1 1 111 7 white (blue+green+red)

For example, to set the foreground color red, use "\033[31m".

To reset all text attributes, use "\033[0m".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment