Skip to main content

Raffaello output colorizer

Project description

What is it?

Raffaello is a powerful, yet simple to use, output colorizer.

What does that mean? Let say you have a CLI tool that prints out lot of information you have to read carefully (gcc, g++, dmesg, etc.), how hard is that? And how easier would it be if some keywords were highlighted with meaningful colors? Well, Raffaello does just that.

Installation

Install Raffaello with pip:

# pip install raffaello

or using setuptools:

# python setup.py install

Command line usage

Raffaello is simple to use. It just needs to know which keywords you want to colorize using simple words as well as regular expressions (using Python’s syntax) and which colors.

The basic syntax is the following:

raffaello <arguments> --- command-line-tool [command-line-tool-arguments]

OR using pipe:

command-line-tool [command-line-tool-arguments] | raffaello <arguments>

Color configuration can be provided direclty through command line with arguments:

$ raffaello "pattern1=>colorA" "pattern2=>colorB" "pattern3=>colorA" ... --- command [arguments]

e.g.:

$ raffaello "error=>red" "Error=>red" --- dmesg     # this will highlight the word error in a messages in red
$ raffaello '[Ee]rror=>red' --- dmesg               # this does the same highlight but with regex

Configuration can also be provided through a config file like the following:

$ raffaello --file=dmesg.cfg --- dmesg
$ dmesg | raffaello --file=dmesg.cfg

where the configuration file is:

$ cat dmesg.cfg

# Dmesg config file example. Comment lines will be ignored
.*[Ee]rror.*=>red_bold
.*ERROR.*=>red_bold
timed\sout=>red
.*[Ww]arning.*=>yellow

Note that:

  1. no spaces are allowed at both sides of => sign:

    error => red            WRONG
    error=> red             WRONG
    error =>red             WRONG
    error=>red              OK
  2. if a pattern contains spaces, they must be defined using “s” symbol, for example:

    could not=>red_bold     WRONG
    could\snot=>red_bold    OK

To avoid long file paths, it is possible to put your config files under <HOME>/.raffaello hidden directory.

Since version 2.1.0 Raffaello’s configuration files support include directive in order to extend configuration color codes with the ones already defined in other configuration files.

e.g.:

$ cat dmesg.cfg

# Dmesg config file example. Comment lines will be ignored

include someOtherConfFile

.*[Ee]rror.*=>red_bold
.*ERROR.*=>red_bold
timed\sout=>red
.*[Ww]arning.*=>yellow

Raffaello configuration reader can expand home alias (e.g. ~) and looks in the hidden directory also for the included configuration files.

Use Raffaello in your own code

Since version 1.3.0, Raffaello can be used as python module in a source code.

Once imported the module, use raffaello.parse_color_option or raffallo.parse_config_file to get the color configuration, and then use raffaello.paint (<string>, configuration) to apply the color codes to your text.

e.g.

import raffaello
configuration = raffaello.parse_color_option ('this=>red')
print (raffaello.paint ('I want to highlight this in red', configuration))

Project details


Download files

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

Source Distribution

raffaello-2.2.0.tar.gz (1.7 MB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page