Announcing colour-text and colour-print

Barry Scott barry at barrys-emacs.org
Mon Sep 30 07:59:19 EDT 2019


See https://pypi.org/project/colour-text/ for documentation
with colourful examples.

Install using pip:

	python -m pip install colour-text


Many command line tools now colour there output to make it
easier to pick out important details.

I want to do the same for my commands that I tend to write in
Python, bash and Windows CMD. The solution needs to work
for Unix, macOS and Windows.

Embedding escape sequences I found to be too low level.
And the existing python libraries a bit too verbose.

My solution is to use a simple markup for adding
colour to text. The markup delimited defaults to "<>".
Names of colours include semantic names like, info, error
and em.

Here is an example:

from colour_text import ColourText
ct = ColourText()
ct.initTerminal()

print( ct( "The next section is in green: <>green example<>." ) )

I also want to be able to add colour output to shell scripts and
Windows CMD scripts. When pip installs colour-text it also installs
the colour-print command for use from scripts.

For example:

$ colour-print "<>info Info:<> this is an <>em informational<> message"
$ colour-print "<>error Error: This is an error message<>"

And you can also pass in arguments in a printf or python % style,
only %s is supported.

$ colour-print "<>info Info:<> Home folder is %s" "$HOME"

Barry




More information about the Python-list mailing list