less than 1 minute read

This post explains how to control colors in your terminal / shell

In shell

From a shell prompt, to print in various colors:

echo "\033[1;31m" hello "\033[1;37m" world # prints hello in red, world in white

In Python

In python, when performing a print statement which gets sent to stdout, you can perform the following:

color_red = "\[\033[1;31m\]"
color_off="\[\033[0m\]" 
print(f'this is some {color_red}important text{color_off}.  This is not important text.')

Short list of colors

# Reset
Color_Off="\[\033[0m\]"       # Text Reset

# Regular Colors
Black="\[\033[0;30m\]"        # Black
Red="\[\033[0;31m\]"          # Red
Green="\[\033[0;32m\]"        # Green
Yellow="\[\033[0;33m\]"       # Yellow
Blue="\[\033[0;34m\]"         # Blue
Purple="\[\033[0;35m\]"       # Purple
Cyan="\[\033[0;36m\]"         # Cyan
White="\[\033[0;37m\]"        # White

Long list of colors