Make colorful strings.
Project description
colorfulstring
colorfulstring is a lightweight Python utility for building ANSI-colored terminal strings with a fluent, chainable API.
Installation
pip install colorfulstring
Quick Start
from colorfulstring import c
print(c.r << "Error:" << " something went wrong")
print(c.g("OK"))
Usage
1) Color Shortcuts
Available color properties are d/r/g/y/b/p/c/w, which map to dark, red, green, yellow, blue, purple, cyan, and white.
print(c.y << "Warning")
2) Pipe-Style Chaining
Use << (or @) to append fragments in sequence:
print(c.b << "[INFO]" << " service started")
3) Conditional Output
iftrue(condition): include the next fragment only whenconditionisTrue.ifnot(condition): include the next fragment only whenconditionisFalse.ifelse(condition): choose between the next two fragments.
ok = True
line = c << "status: " << c.ifelse(ok) << c.g("success") << c.r("failed")
print(line)
4) Immediate Printing
c.print outputs each generated fragment immediately (without an automatic newline). It can be combined with c.endl.
line = c.print << "hello" << c.endl
See Also
Github repository
PyPI project
License
This project falls under the BSD 3-Clause License.
History
v0.0.0
- Initial release.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
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
File details
Details for the file colorfulstring-0.0.0.tar.gz.
File metadata
- Download URL: colorfulstring-0.0.0.tar.gz
- Upload date:
- Size: 7.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
daef49003e56506771f0e5fa5c90640fc3adc574b7d0e54f0b3334ed4710f4c4
|
|
| MD5 |
de9737169c96e83c3ff84544d6af99b5
|
|
| BLAKE2b-256 |
4bf45c5783f3a7f3233f30f570e37a02972592f2fdbbca1b2796b1140c619d60
|
File details
Details for the file colorfulstring-0.0.0-py3-none-any.whl.
File metadata
- Download URL: colorfulstring-0.0.0-py3-none-any.whl
- Upload date:
- Size: 6.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
529a04378adaeebff90d30b6c9f9fd92a4b8a969a9bd8fecc75bbe6cce619d5f
|
|
| MD5 |
7e804e8f5a85d2132c8812b1b2191f83
|
|
| BLAKE2b-256 |
4026431f2180d59dffa2b718adb53c07cfcb465c48d76ae6693ad14a4e65d7bc
|