Library with constants and functions for working with colors
Project description
Colex
Library with constants and functions for working with colors
Installation
Install using either pip
or rye
:
pip install colex
rye install colex
Getting started
import colex # Every public namespace is available under `colex`
print(colex.RED + "Hello red!")
print("Still red...")
print(colex.RESET, "Back to normal")
# Optionally, you can import submodules or constants like this
from colex import color, style, RESET
print(style.ITALIC + color.GREEN + "Hello italic green" + RESET)
# You may want to use this helper function to have color param at the end
from colex import colorize
print(colorize("Hello blue!", colex.BLUE))
# Note that `colex` is using ANSI escape codes,
# therefore any string can be annotated with `ColorValue`
from colex import ColorValue
my_color: ColorValue = "\x1b[31m" # The ANSI code for red
print(my_color + "Hello red, again")
Rational
Originally, using colors in my projects was done by simply printing "\x1b[31m"
and such. Eventually, the color strings were assigned to constants with understandable names, like RED
. They were put in a seperate module, a color.py
, that was copied around projects when I needed to do colors. After some time, I found it messy when it ended up looking:
import color
from color import ColorValue
class Color: # This was used as a mixin component
color: ColorValue = color.RED # Too many occurances of "color" for me to stay sane
It was then nice in itself to distinguish the namespace colex
from color
. I then ended up with:
import colex
from colex import ColorValue
class Color:
color: ColorValue = colex.RED
Having a different namespace was nice, but the main advantage was having colex
on PyPI
. This way, I didn't need to copy over a color.py
file everytime, but I could instead just install it using the desired package manager.
It also became easier to develop charz
, as the color aspect was split into it's own package.
Includes
- Annotations
ColorValue
ColorCode
HexCode
- Functions
colorize
from_ansi
from_hex
from_random
from_rgb
- Constants
NONE
RESET
- Modules with constants
color
- HTML/CSS named colors
style
BOLD
FAINT
ITALIC
UNDERLINE
BLINK
RAPID_BLINK
REVERSE
CONCEAL
STRIKETHROUGH
License
MIT
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
File details
Details for the file colex-0.3.1.tar.gz
.
File metadata
- Download URL: colex-0.3.1.tar.gz
- Upload date:
- Size: 8.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.13.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
0231f0b3e621d7fa23201d670405a9b755080261099e26e104956b97de677adb
|
|
MD5 |
5544ba3a33a62f9adfe53a836c82858c
|
|
BLAKE2b-256 |
9801367836de1240de61256ae717ee3bedf7be6b4aa06564458e03e9fa35deb0
|
File details
Details for the file colex-0.3.1-py3-none-any.whl
.
File metadata
- Download URL: colex-0.3.1-py3-none-any.whl
- Upload date:
- Size: 9.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.13.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
d7af2e1ef5a3100fcf06c88c1b01d318a491309b96d9e417ee7c5d206982191e
|
|
MD5 |
8f6582a24eb4beb952bbe162c8ec66c0
|
|
BLAKE2b-256 |
02c1c29e7a2eb5e5358a230ab1ac8d8239211f729d81b0bbf7e59a2a5c97eb17
|