Colorful worry-free console applications for Linux, Mac OS X, and Windows.
Project description
#colorclass
Yet another ANSI color text library for Python. Provides "auto colors" for dark/light terminals. Works on Linux, OS X,
and Windows. For Windows support you just need to call Windows.enable()
in your application.
On Linux/OS X autocolors
are toggled by calling set_light_background()
and set_dark_background()
. On Windows
this can be done automatically if you call Windows.enable(auto_colors=True)
. Even though the latest Windows 10 does
support ANSI color codes natively, you still need to run Windows.enable() to take advantage of automatically detecting
the console's background color.
In Python2.x this library subclasses unicode
, while on Python3.x it subclasses str
.
- Python 2.6, 2.7, PyPy, PyPy3, 3.3, 3.4, and 3.5 supported on Linux and OS X.
- Python 2.6, 2.7, 3.3, 3.4, and 3.5 supported on Windows (both 32 and 64 bit versions of Python).
.. image:: https://img.shields.io/coveralls/Robpol86/colorclass/master.svg?style=flat-square&label=Coveralls :target: https://coveralls.io/github/Robpol86/colorclass :alt: Coverage Status
.. image:: https://img.shields.io/pypi/v/colorclass.svg?style=flat-square&label=Latest :target: https://pypi.python.org/pypi/colorclass :alt: Latest Version
.. image:: https://img.shields.io/pypi/dm/colorclass.svg?style=flat-square&label=PyPI%20Downloads :target: https://pypi.python.org/pypi/colorclass :alt: Downloads
Quickstart
Install:
pip install colorclass
Piped Command Line
It is possible to pipe curly-bracket tagged (or regular ANSI coded) text to Python in the command line to produce color text. Some examples:
echo "{red}Red{/red}" |python -m colorclass # Red colored text.
echo -e "\033[31mRed\033[0m" | COLOR_DISABLE=true python -m colorclass # Strip colors
echo -e "\033[31mRed\033[0m" | COLOR_ENABLE=true python -m colorclass &> file.txt # Force colors.
Export these environment variables as "true" to enable/disable some features:
=============== ============================================
Env Variable Description
=============== ============================================
COLOR_ENABLE Force colors even when piping to a file.
COLOR_DISABLE Strip all colors from incoming text.
COLOR_LIGHT Use light colored text for dark backgrounds.
COLOR_DARK Use dark colored text for light backgrounds.
=============== ============================================
Example Implementation
======================
Source code for the example code is: example.py
Usage
Different colors are chosen using curly-bracket tags, such as {red}{/red}
. For a list of available colors, call
colorclass.list_tags()
.
The available "auto colors" tags are:
- autoblack
- autored
- autogreen
- autoyellow
- autoblue
- automagenta
- autocyan
- autowhite
- autobgblack
- autobgred
- autobggreen
- autobgyellow
- autobgblue
- autobgmagenta
- autobgcyan
- autobgwhite
Methods of Class instances try to return sane data, such as:
from colorclass import Color
color_string = Color('{red}Test{/red}')
>>> color_string
u'\x1b[31mTest\x1b[39m'
>>> len(color_string)
4
>>> color_string.istitle()
True
There are also a couple of helper attributes for all Color instances:
>>> color_string.value_colors
'\x1b[31mTest\x1b[39m'
>>> color_string.value_no_colors
'Test'
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 colorclass-2.2.1.tar.gz
.
File metadata
- Download URL: colorclass-2.2.1.tar.gz
- Upload date:
- Size: 16.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.6.0 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.8.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f8435bff93eb1f77c41f8363f1ff8a8bb1b1fe1e459eb6482a3542a4018b5f31 |
|
MD5 | ca746c9d606df2b4a457b0f0c491051d |
|
BLAKE2b-256 | 1ca1933e1ad1e4199bbccf44e55ee91f568954c47af151c7ba2036f7761afeea |
File details
Details for the file colorclass-2.2.1-py2.py3-none-any.whl
.
File metadata
- Download URL: colorclass-2.2.1-py2.py3-none-any.whl
- Upload date:
- Size: 19.1 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.6.0 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.8.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c2119a86fcca29e7a62e156a7aa3b5f333eb7f1ea099364ee3efd6f1fc27905a |
|
MD5 | ae08208d2b6ce14af5f366d637ccdccc |
|
BLAKE2b-256 | 4a6ecb053d73698e449e2f6d48bed5b0f3f1da1bd2d620afb5a811cc1ce749d0 |