ansicolortags, a Python script and module to simply and efficiently use ANSI colors in a command line Python program.
ansicolortags module provides an efficient and useful function
printc) to print colored text in a terminal application with Python 2 and 3, with a HTML-tag like style:
from ansicolortags import printc # Import the function # ... printc("France flag is <blue>blue<reset>, <red>red<reset>, and <white>white<reset> !")
will print the text "France flag is blue, white and red !" with appropriate colors (if the output supports them -- a terminal should but a file or a pipe should not).
All ANSI colors code are defined with this HTML-tag like style:
This point is the main interest of this module,
because all others modules define function to print with some colours.
For instance, the screenshot below shows the module begin used to print a colored text (the help of the script) which looks like this:
Python v2.7+ or Python v3.1+.
This project is hosted on the Pypi package repository.
The complete documentation of the module is available, see here on readthedocs.io.
All the details (installation, options, etc) are in the doc. Anyway, here are some information.
The project consists in just the main script
How to install it
Download the archive from this git repository, extract it, then launch
python setup.py install in the directory.
More details can be found in the INSTALL file.
The project is entirely written in Python, compatible with both version 2.7+ and 3.1+.
For more details about the Python language, see the official site.
The project have been developed on GNU/Linux (Ubuntu 11.10 to 15.10).
Warning : Windows ?
It also have been quickly tested on Windows 7 with the Cygwin environment and Python 2.7.
Warning : Mac OS X ?
It should also work on Mac OS X, but not been tested. Any feedback on this is welcome!
Feel free to contact me, with a Bitbucket message (my profile is lbesson), or via an email at lilian DOT besson AT ens-cachan DOT org.
This project is released under the MIT License.