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)
.
In Python2.x this library subclasses unicode
, while on Python3.x it subclasses str
.
- Python 2.6, 2.7, PyPy, PyPy3, 3.3, and 3.4 supported on Linux and OS X.
- Python 2.7, 3.3, and 3.4 supported on Windows (both 32 and 64 bit versions of Python).
Tested on Windows XP and Windows 10 technical preview.
Install:
pip install colorclass
Source code for the example code is: example.py
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'
This project adheres to Semantic Versioning.
- Added
- Convenience single-color methods by Marc Abramowitz.
- Fixed
- Maintaining
Color
type through.encode()
and.decode()
chains.
- Maintaining
- Fixed
- Python 2.7 64-bit original colors bug on Windows.
- resetting colors when
reset_atexit
is True. - Improved sorting of
list_tags()
.
- Added
- Native Windows support and automatic background colors.
- Added
- Ability to disable/strip out all colors.
- Fixed
splitlines()
method.
- Initial release.