tcolorpy
tcolorpy is a Python library designed to apply true color (24-bit RGB) for terminal text, providing a rich set of methods to style strings with foreground, background, and various ANSI effects. The current version is 0.1.7, and the project maintains an active, though not rapid, release cadence with a focus on Python version compatibility and packaging improvements.
Warnings
- breaking Support for Python 3.7 and 3.8 was dropped in version 0.1.7. Users on these Python versions must upgrade their Python interpreter or pin 'tcolorpy' to a version less than 0.1.7.
- breaking Support for Python 3.6 was dropped in version 0.1.3. Users on Python 3.6 must install 'tcolorpy' to a version less than 0.1.3.
- gotcha The `tcolorpy.disable()` and `tcolorpy.enable()` functions globally control whether colors are rendered. If you find colors are unexpectedly not appearing, verify that coloring hasn't been disabled.
- gotcha Terminal true color (24-bit RGB) support is not universal across all terminal emulators and operating systems. While `tcolorpy` includes `is_true_color_terminal()` for detection, colors may not render as intended if the user's terminal lacks full support.
Install
-
pip install tcolorpy
Imports
- Color
from tcolorpy import Color
- RgbColor
from tcolorpy import RgbColor
- AnsiFgColor
from tcolorpy import AnsiFgColor
- tcolorpy (as color)
import tcolorpy as color
Quickstart
import tcolorpy as color
# Basic red text
print(color.RED('Hello, tcolorpy!'))
# Custom RGB color with bold style
print(color.RgbColor(255, 100, 0, 'Orange Bold Text').bold())
# 256-color foreground and background
print(color.AnsiFgColor(27, 'Deep Green FG') + color.AnsiBgColor(235, ' Dark Gray BG'))
# Check if the terminal supports true colors
if color.is_true_color_terminal():
print(color.BLUE('Your terminal supports true colors!'))
else:
print(color.YELLOW('True color support not detected.'))