Terminal color styling: compose ANSI escapes for foreground/background and text attributes.
Project description
colortty
A tiny Python helper to build ANSI escape sequences for terminal styling. It composes colors and text attributes and returns the styled string. Output/printing is up to you.
- English | 中文说明
Requirements
- Python 3.11+
Install
- From PyPI (once published):
pip install colortty
- From source (in this repository):
pip install .
Usage
Two common ways to use it:
- Build and immediately style a string:
from src.colortty import colortty, ColorTTY
print(
colortty("Hello")
.set(ColorTTY.Color.red())
.set(ColorTTY.BackgroundColor.blue())
.make()
)
# -> "\033[31;44mHello\033[0m"
- Build a reusable style and apply it later:
from src.colortty import colortty, ColorTTY
red_text = colortty().set(ColorTTY.Color.red())
print(red_text.make("Error:"))
print(red_text.set(ColorTTY.BackgroundColor.white(lighter=True)).make("Critical"))
More examples
- Bright 8‑color variant:
colortty("Bright red").set(ColorTTY.Color.red(lighter=True)).make()
- 256‑color index and truecolor (RGB):
colortty("Indexed").set(ColorTTY.Color.color_256(208)).make()
colortty("RGB").set(ColorTTY.Color.color(255, 128, 64)).make()
- Text attributes and background:
from src.colortty import bold, underline, sparking, inverse, invisible
colortty("Styled").set(bold()).set(underline()).set(sparking()).set(inverse()).set(invisible(False)).make()
colortty("Warn").set(ColorTTY.BackgroundColor.yellow(lighter=True)).set(bold()).make()
API (brief)
colortty(s: str | None = None) -> StatementStatement.set(step) -> StatementStatement.make(s: str | None = None) -> strColorTTY.Color:.black/.red/.green/.yellow/.blue/.magenta/.cyan/.white(lighter=False),.color_256(index),.color(r,g,b)ColorTTY.BackgroundColor: same asColorTTY.Color- Attributes:
bold(enable=True),underline(enable=True),sparking(enable=True),inverse(enable=True),invisible(enable=True)
License
MIT. See LICENSE.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
colortty-0.1.0.tar.gz
(14.2 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
colortty-0.1.0-py3-none-any.whl
(12.5 kB
view details)
File details
Details for the file colortty-0.1.0.tar.gz.
File metadata
- Download URL: colortty-0.1.0.tar.gz
- Upload date:
- Size: 14.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
29d9896b1336db62de6a267ebeec7ea69728ae170c5f809d731c6fe592c6e376
|
|
| MD5 |
44b6933ef25954cc5f5fbd402fedc0c4
|
|
| BLAKE2b-256 |
f718be6f59f8958fde31ae8411aa03ce5c9193f51629f4b84e67d246b835f964
|
File details
Details for the file colortty-0.1.0-py3-none-any.whl.
File metadata
- Download URL: colortty-0.1.0-py3-none-any.whl
- Upload date:
- Size: 12.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a5bedf649c5618fe6b779ea8e6f62a7a59713845e830ad43c4cba1ce1b09825b
|
|
| MD5 |
97943ffae6bd5f2551a3bc8b4d343700
|
|
| BLAKE2b-256 |
396ed4e10bdcd38c40c75d42e898b39c6879c03aff626830893c44f0e3b2f377
|