Terminal Tips
Colors in Terminal
Basically, you need to use the following pattern for output string that need colors. For exact color code, see below:
printf("\x1b[%sm%s\x1b[0m", color_code, str-content);
Simple table
The colors in the table below should be useful in most terminals.
Black 0;30 Dark Gray 1;30 Blue 0;34 Light Blue 1;34 Green 0;32 Light Green 1;32 Cyan 0;36 Light Cyan 1;36 Red 0;31 Light Red 1;31 Purple 0;35 Light Purple 1;35 Brown 0;33 Yellow 1;33 Light Gray 0;37 White 1;37 and for background colors, the num is 40 to 47
A simple python script to show what's possible
def print_format_table(): """ prints table of formatted text format options """ for style in xrange(8): for fg in xrange(30,38): s1 = '' for bg in xrange(40,48): format = ';'.join([str(style), str(fg), str(bg)]) s1 += '\x1b[%sm %s \x1b[0m' % (format, format) print s1 print '\n' print_format_table()
References
- Reader-friendly Reference Color in Terminal
- The Authortive Source ANSI Escape Code
∎