Skip to content

How to Print Foreground Text 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.

Cheat Sheets#

Normal Colors#

Color Color Code Example
Green Color.GREEN This is GREEN!
Yellow Color.YELLOW This is YELLOW!
Red Color.RED This is RED!
Magenta Color.MAGENTA This is MAGENTA!
Blue Color.BLUE This is BLUE!
Cyan Color.CYAN This is CYAN!
White Color.WHITE This is WHITE!
Black Color.BLACK This is BLACK!
- Color.DEFAULT -
- Color.OFF -

Bright Colors#

Color Color Code Example
Bright green BrightColor.GREEN This is BRIGHT GREEN!
Bright yellow BrightColor.YELLOW This is BRIGHT YELLOW!
Bright red BrightColor.RED This is BRIGHT RED!
Bright magenta BrightColor.MAGENTA This is BRIGHT MAGENTA!
Bright blue BrightColor.BLUE This is BRIGHT BLUE!
Bright cyan BrightColor.CYAN This is BRIGHT CYAN!
Bright white BrightColor.WHITE This is BRIGHT WHITE!
Bright black BrightColor.BLACK This is BRIGHT BLACK!
- BrightColor.DEFAULT -
- BrightColor.OFF -