Skip to main content

Command line utility to colorize other commands output

Project description


Give some color to your (remote) TTY!!

============== =============== ========= ============
============== =============== ========= ============
|pip version| |pip downloads| |travis| |coveralls|
============== =============== ========= ============

And it is free. Checkout the `Source code`_.

Installation and Usage

Two options: to install it in your system/project::

pip install colorize

And you can use it with::

python -m colorize -h

Or just `download the lastest zip`_ and use it with::

python -h

Now, you have two ways to use it:

Rendering the output

Just execute::

$ command to execute | python -m colorize

If you need to render both the stdout and the stderr::

$ command to execute |& python -m colorize

This method works well with too long outputs

As runner

Other way to use it:

$ python -m colorize command to execute

This method can do disgusting things with too long outputs.


You can change the output format with the argument :code:`-f` or :code:`--format`. It uses the same format that ``logging``, so you can use any of its special variables, like:

- :code:`%(asctime)s`, to show the time.
- :code:`%(message)s`, to show the message itself.
- :code:`%(msecs)d`, to show the relative time.
- `Any other output format allowed by logging`_.

You can combine them as you wish. Example::

$ python -m colorize -- echo foo
$ python -m colorize -f "%(asctime)s - %(levelname).2s: %(message)s" -- echo foo
05-29 08:43:09 - IN: foo
$ python -m colorize -f "%(levelname).2s %(asctime)s - %(message)s" -- echo foo
IN 05-29 08:44:17 - foo

Default date format is :code:`%m-%d %H:%M:%S`, but you can change it with :code:`--date-format`::

$ python -m colorize -f "%(asctime)s" --date-format="%H:%M:%S" -- echo foo
$ python -m colorize -f "%(asctime)s" --date-format="%H %M %S" -- echo foo
08 44 17

Configuration File

It will find a configuration file in the current directory, in the home directory or in the default path directory. The first one found will be used. So, it will search for:

- ``./.colorize.conf``
- ``$HOME/.configuration/colorize/colorize.conf``
- ``/etc/colorize/colorize.conf``

The format for this file is very easy: it is a CSV file with next fields::

# regular expression to highlight (quoted) , bold output , foreground color , background color
"^=+$" , 1 , white ,
"^=+$" , true , white , black
"^=+$" , 0 , red , white
"^=+$" , false , brown , magenta

Available colors:

- :code:`black`
- :code:`white`
- :code:`red`
- :code:`green`
- :code:`blue`
- :code:`brown`
- :code:`gray`
- :code:`magenta`
- :code:`cyan`

And that's all.

Example to simulate colordiff

To emulate colordiff, just use this configuration file::

"^>.*", 0, blue
"^<.*", 0, red
"^\d+,?\d*c\d+,?\d*$", 0, magenta

That's enough :D

.. |travis| image::
:target: `Travis`_
:alt: Travis results

.. |coveralls| image::
:target: `Coveralls`_
:alt: Coveralls results_

.. |pip version| image::
:target: `project`_
:alt: Latest PyPI version

.. |pip downloads| image::
:target: `project`_
:alt: Number of PyPI downloads

.. _Travis:
.. _Coveralls:
.. _project:
.. _download the lastest zip:
.. _Source code:
-- _Any other output format allowed by logging:

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for colorize, version 1.0.0
Filename, size File type Python version Upload date Hashes
Filename, size colorize-1.0.0.tar.gz (7.0 kB) File type Source Python version None Upload date Hashes View
Filename, size (11.9 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page