Skip to content

Text Foreground Colors#

Introduction#

When you want to print colored text in the terminal, Colorist offers two ways of doing so:

  • Full text functions: Print a full line of colored text with the green(), yellow(), red(), etc. functions.
  • Custom string styling: Mix colors to any part of a string with the Color and BrightColor classes.

How to print a full line of colored text in the terminal:

Python
1
2
3
4
5
from colorist import green, yellow, red

green("This is GREEN!")
yellow("This is YELLOW!")
red("This is RED!")

How it appears in the terminal:

% This is GREEN!
% This is YELLOW!
% This is RED!

How to customize colors inside a paragraph and print it in the terminal:

Python
1
2
3
4
5
from colorist import Color

print(f"I want {Color.RED}red{Color.OFF} color inside this paragraph")

print(f"Both {Color.GREEN}green{Color.OFF} and {Color.YELLOW}yellow{Color.OFF} are nice colors")

How it appears in the terminal:

% I want red color inside this paragraph
% Both green and yellow are nice colors

Tip

Remember to turn off a color with Color.OFF or BrightColor.OFF every time you want to revert back to the default terminal text style. Otherwise, the effect may spill over and into other terminal messages.

Bright Colors#

Most terminals support bright colors that stand more out:

Python
1
2
3
from colorist import BrightColor

print(f"Put {BrightColor.CYAN}cyan{BrightColor.OFF} inside this paragraph")

How it appears in the terminal:

% Put cyan inside this paragraph

Refer to the documentation for a complete list of full line text color functions and custom string styling.