Colorama
Colorama is a Python library that simplifies printing colored text and styles to the terminal, ensuring cross-platform compatibility, especially on Windows. The current version is 0.4.6, released on October 25, 2022. The library has a stable release cadence, with updates addressing compatibility and minor feature enhancements.
Warnings
- gotcha On Windows, failing to call 'init()' may result in ANSI escape sequences being displayed as raw text instead of colored output.
- gotcha Using 'init(autoreset=True)' resets styles after each print statement, which may not be desired in all cases.
- gotcha Colorama's 'Style.DIM' may not be supported on all terminals, leading to inconsistent text appearance.
- gotcha Combining Colorama with other ANSI-based libraries without proper initialization may lead to unexpected behavior.
Install
-
pip install colorama
Imports
- init
from colorama import init
- Fore
from colorama import Fore
- Back
from colorama import Back
- Style
from colorama import Style
Quickstart
from colorama import init, Fore, Back, Style
init(autoreset=True)
print(Fore.RED + 'This is red text')
print(Back.GREEN + 'This has a green background')
print(Style.BRIGHT + 'This is bright text')
print('Back to normal text')