object-colors
Object-oriented library for stylizing terminal output
Installation
$ pip install object-colors
Usage
Import the Color object from object_colors
>>> from object_colors import Color
Args can be provided as strings or as indices corresponding to their index in an ANSI escape sequence
>>> Color(effect="bold", fore="red", back="green")
Color(effect=1, fore=1, back=2, objects())
The following would yield the same result
>>> Color(effect=1, fore=1, back=2)
Color(effect=1, fore=1, back=2, objects())
The above options are part of the below mapping
>>> for i, c in enumerate(Color.colors):
... print(i, c)
0 black
1 red
2 green
3 yellow
4 blue
5 magenta
6 cyan
7 white
>>> for i, e in enumerate(Color.effects):
... print(i, e)
0 none
1 bold
2 dim
3 italic
4 underline
5 blink
6 blinking
7 negative
8 empty
9 strikethrough
To configure the current object either effect, fore, or back can be provided
They must be an int, str, or None type
>>> c = Color()
>>> c.set(effect="bold", fore="red", back="red")
>>> c
Color(effect=1, fore=1, back=1, objects())
Create new objects with by providing a dict object with any keyword argument
Use set to set multiple parameters
>>> c = Color()
>>> c.set(bold_green=dict(effect="bold", fore="green"))
>>> c
Color(effect=None, fore=None, back=None, objects(bold_green))
Return str or tuple using get
>>> c = Color()
>>> c.set(red=dict(fore="red"))
>>> c.set(yellow=dict(fore="yellow"))
>>> f"{c.red.get('*')} {c.yellow.get('Warning')}"
'\x1b[31m*\x1b[0;0m \x1b[33mWarning\x1b[0;0m'
>>> c = Color()
>>> c.set(red=dict(fore="red"))
>>> xyz = c.red.get("x", "y", "z")
>>> xyz
('\x1b[31mx\x1b[0;0m', '\x1b[31my\x1b[0;0m', '\x1b[31mz\x1b[0;0m')
>>> x, y, z = xyz
>>> f"{x} {y} {z}"
'\x1b[31mx\x1b[0;0m \x1b[31my\x1b[0;0m \x1b[31mz\x1b[0;0m'
Print the result using print
>>> c = Color(effect="bold", fore="cyan")
>>> # doctest strips ansi codes from print
>>> c.print("bold cyan") # '\x1b[1;36mbold cyan\x1b[0;0m'
bold cyan
Load all effect, fore, or back elements using populate()
>>> c = Color()
>>> c.populate("fore")
>>> c
Color(effect=None, fore=None, back=None, objects(black, red, green, yellow, blue, magenta, cyan, white))
>>> c = Color()
>>> c.set(red=dict(fore="red"))
>>> c.red.populate("effect")
>>> c.red
Color(effect=None, fore=1, back=None, objects(none, bold, dim, italic, underline, blink, blinking, negative, empty, strikethrough))
>>> # doctest strips ansi codes from print
>>> c.red.strikethrough.print("strikethrough red") # '\x1b[9;31mstrikethrough red\x1b[0;0m'
strikethrough red
Metadata
Release files for object-colors 2.3.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| object_colors-2.3.1.tar.gz | 6.8 kB | Without provenance | Details for object_colors-2.3.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| object_colors-2.3.1-py3-none-any.whl | Python 3 | none | any | Details for object_colors-2.3.1-py3-none-any.whl |
Total release size: 13.9 kB
Release files / object_colors-2.3.1.tar.gz
| Download URL | object_colors-2.3.1.tar.gz |
|---|---|
| Size | 6.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
05edbd30bb3adc8257c804162df0acb05191d3237786e528801f4aba048205b9
|
|
BLAKE2b-256 checksum How to use checksums |
a36abab560526a8749cf62c4c8d4f83c62358a8c46786966eb19af30329145bc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.5.1 CPython/3.8.13 Darwin/22.6.0
|
Release files / object_colors-2.3.1-py3-none-any.whl
| Download URL | object_colors-2.3.1-py3-none-any.whl |
|---|---|
| Size | 7.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
be4484add2dcc380a3bef6f19684a96b2a0a578285453fa2a44b9e37949d4f84
|
|
BLAKE2b-256 checksum How to use checksums |
051608bb4bf77b7c5f1ce9fe2111cefedb7afa9f7fa5a4327a1a9e82db15c342
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.5.1 CPython/3.8.13 Darwin/22.6.0
|
Security for object-colors 2.3.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.