termcolour - Easily add colour to terminal output
- Purpose:
This module contains basic and bright (16 colours) text and background ANSI colour codes for colouring Linux and Windows terminal output.
- Platform:
Linux/Windows | Python 3.6+
- Developer:
J Berendt
- Email:
- Comments:
If used on Windows, the
colorama.init()
method is called by theutils4.__init__
module to configure Windows to handle CLI colouring.- Example:
Print red text to the terminal:
>>> from utils4.termcolour import Text >>> print(f'{Text.RED}ALERT! This is red text.{Text.RESET}') ALERT! This is red text.
Print red text on a white background to the terminal:
>>> from utils4.termcolour import Back, Text >>> print(f'{Text.RED}{Back.BRIGHTWHITE}ALERT! This is red text on white.{Text.RESET}') ALERT! This is red text on white.
Print bold yellow text on a black background to the terminal:
>>> from utils4.termcolour import Back, Text, Style >>> print(f'{Text.YELLOW}{Back.BLACK}{Style.BOLD}Bold yellow text.{Text.RESET}') Bold yellow text.
- class termcolour.AnsiBack[source]
ANSI background colour codes.
Note
The bright colours have been included, but are not always supported.
- BLACK = 40
- BLUE = 44
- BRIGHTBLACK = 100
- BRIGHTBLUE = 104
- BRIGHTCYAN = 106
- BRIGHTGREEN = 102
- BRIGHTMAGENTA = 105
- BRIGHTRED = 101
- BRIGHTWHITE = 107
- BRIGHTYELLOW = 103
- CYAN = 46
- GREEN = 42
- MAGENTA = 45
- RED = 41
- WHITE = 47
- YELLOW = 43
- class termcolour.AnsiStyle[source]
ANSI style codes.
- BOLD = 1
- DIM = 2
- NORMAL = 22
- UNDERLINE = 4
- __annotations__ = {}
- class termcolour.AnsiText[source]
ANSI foreground (text) colour codes.
Note
The bright colours have been included, but are not always supported.
- BLACK = 30
- BLUE = 34
- BRIGHTBLACK = 90
- BRIGHTBLUE = 94
- BRIGHTCYAN = 96
- BRIGHTGREEN = 92
- BRIGHTMAGENTA = 95
- BRIGHTRED = 91
- BRIGHTWHITE = 97
- BRIGHTYELLOW = 93
- CYAN = 36
- GREEN = 32
- MAGENTA = 35
- RED = 31
- WHITE = 37
- YELLOW = 33
- __annotations__ = {}