A simple fstring-friendly string colorizer
Project description
colors
Colors is a simple library that makes it easier to use colors in fstrings. The standard ansi colors are (in order):
- Black
- Red
- Green
- Yellow
- Blue
- Pink
- Cyan
- White
These are accessible in the following variations:
- (f)ore(g)round
- (b)ack(g)round
- (u)nder(line)d
- (bold)ed
- (f)ore(g)round_(hi)lighted
- (b)ack(g)round_(hi)lighted
- (bold)_(hi)lighted
Forground, Background, Underline, and Bold can all be chained together in any order, as:
f"{uline.blue}{bg.red}red underlined text{reset}"
Highlighted colors must be custom-built due to a difference in how their codes are constructed. This can be done as so:
f"{all_hi(Color.Blue, Color.White, bold=0)}this is white on blue text, unbolded{reset}"
While I may end up figuring out a way around this, it will not be soon. Feel free to use these features as-is.
Installation
$ pip3 install colors
or
$ python3 setup.py install
Examples
Hello, World!
from fcolors.fcolors import fg, bg, bold, reset
print(f"{bg.blue}{bold.white}Hello, World!{reset}")
A tree that talks
from fcolors.fcolors import fg, fg_hi, bg, bg_hi, bold, reset, all_hi, Color
canopy = f"{fg.green}"
leaves = f"{fg.green}"
wood = f"{bold.yellow}"
grass = f"{bg_hi.green}"
text = f"{bold.white}"
c = canopy
l = leaves
w = wood
x = reset
t = text
def rgb(string):
chars = [c for c in string]
for index in range(len(chars)):
chars[index] = bold.colors[index % len(bold.colors)-1] + chars[index]
return ''.join(chars) + f'{text}'
picture = (
f"""\
{c}__________{x} {t} ______________________
{l}/ ) \{x} {t} / \
{l}| ( |{x}{t}| Have fun using my |
{l}\________)_/{x} {t}| {rgb('fcolors')} package! |
{w}| || |{x} {t}| - Jayson |
{w}\ -- /{x} {t} \ __________________/
{w}| |{x} {t} | _/
{w}| |{x} {t} <_/
{w}| |{x}
{w}| |{x}
{grass} {reset}""")
print(picture)
License
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
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 fcolors-0.0.3.tar.gz.
File metadata
- Download URL: fcolors-0.0.3.tar.gz
- Upload date:
- Size: 14.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1676b791d302f3b9a9d295a8cc946bcfe8de016e7d80a10360a49962cc470b80
|
|
| MD5 |
db96776ff89cfc162d4894affaccfe83
|
|
| BLAKE2b-256 |
2779c6f0413d0136d272041fe0e16a53fd0f47ed73b4265734d1ffa386ecf3e1
|
File details
Details for the file fcolors-0.0.3-py3-none-any.whl.
File metadata
- Download URL: fcolors-0.0.3-py3-none-any.whl
- Upload date:
- Size: 15.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5d7e590e4fc99321e50bcb8be62ef1c5181b63ffab057e3d2b71a0fd460d35b4
|
|
| MD5 |
d0b00861650cc0fde263c0bac0609116
|
|
| BLAKE2b-256 |
b8412d21a7437a19d3623cbd2fd31e9db90c57458186abcf3a1f943e95a609b4
|