Formatting Console Output¶
A collection of utilities for formatting console output with colours.
This module is mostly used in the inner workings of atlasplots utility functions but you can use it in your plotting scripts too!
Supported Colours
Colour |
Command |
---|---|
Red |
|
Green |
|
Yellow |
|
Blue |
|
Magenta |
|
Cyan |
|
White |
|
Colour aliases
Command |
Colour |
---|---|
|
Blue |
|
Green |
|
Yellow |
|
Red |
|
Red |
Pre-formatted Strings
Command |
Returns |
---|---|
|
|
|
|
|
|
Other Text Formatting
Style |
Command |
---|---|
Bold |
|
Faint Text |
|
Italic |
|
Underline |
|
Note
Always end the string you want formatted with bcolor.end
.
Examples
Import the bcolor
class:
>>> from atlasplots.console import bcolor
Print text with colour:
>>> print(bcolor.blue + "Blue" + bcolor.end)
>>> print(bcolor.red + "Red " + bcolor.green + "Green" + bcolor.end)
You can also use colour aliases for printing OK/Warning/Error messages:
>>> print(bcolor.OK + "OK" + bcolor.end)
>>> print(bcolor.WARNING + "Warning" + bcolor.end)
>>> print(bcolor.ERROR + "Error" + bcolor.end)
Or similarly using Python’s string formatting:
>>> print("{} Something went wrong!".format(bcolor.ERROR + "Error" + bcolor.end))
Or you can use the pre-formatted strings as a shortcut:
>>> print("{} Something went wrong!".format(bcolor.error()))