How to Print Background Colors#
Introduction#
When you want to print colored backgrounds in the terminal, Colorist offers two ways of doing so:
- Full text functions: Print a full line of colored text with the
bg_green()
,bg_yellow()
,bg_red()
, etc. functions. - Custom string styling: Mix colors to any part of a string with the
BgColor
andBgBrightColor
classes.
Print Line of Text with Background Color#
How to print a full line of colored text in the terminal:
Python | |
---|---|
How it appears in the terminal:
% This is GREEN background!
% This is YELLOW background!
% This is RED background!
Print Mixed Colors in Text#
Background colors can also be mixed inside a paragraph:
Python | |
---|---|
How it appears in the terminal:
% Put red background color inside this paragraph
% Both green...
% ... and yellow are nice background colors
Tip
Remember to turn off a color with BgColor.OFF
or BgBrightColor.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 | |
---|---|
How it appears in the terminal:
% Add cyan background color
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 |
---|---|---|
BgColor.GREEN | This is GREEN background! | |
BgColor.YELLOW | This is YELLOW background! | |
BgColor.RED | This is RED background! | |
BgColor.MAGENTA | This is MAGENTA background! | |
BgColor.BLUE | This is BLUE background! | |
BgColor.CYAN | This is CYAN background! | |
BgColor.WHITE | This is WHITE background! | |
BgColor.BLACK | This is BLACK background! | |
- | BgColor.DEFAULT | - |
- | BgColor.OFF | - |
Bright Colors#
Color | Color Code | Example |
---|---|---|
BgBrightColor.GREEN | This is BRIGHT GREEN background! | |
BgBrightColor.YELLOW | This is BRIGHT YELLOW background! | |
BgBrightColor.RED | This is BRIGHT RED background! | |
BgBrightColor.MAGENTA | This is BRIGHT MAGENTA background! | |
BgBrightColor.BLUE | This is BRIGHT BLUE background! | |
BgBrightColor.CYAN | This is BRIGHT CYAN background! | |
BgBrightColor.WHITE | This is BRIGHT WHITE background! | |
BgBrightColor.BLACK | This is BRIGHT BLACK background! | |
- | BgBrightColor.DEFAULT | - |
- | BgBrightColor.OFF | - |