GithubHelp home page GithubHelp logo

colorize's Introduction

Colorize

Give some color to your (remote) TTY!!

VERSION DOWNLOADS TESTS COVERAGE WHEEL
Latest PyPI version Number of PyPI downloads Travis results Coveralls results_ Wheel Status

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

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.

Options

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

You can combine them as you wish. Example:

$ python -m colorize -- echo foo
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 %m-%d %H:%M:%S, but you can change it with --date-format:

$ python -m colorize -f "%(asctime)s" --date-format="%H:%M:%S" -- echo foo
08:44:17
$ 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

For example, you can configure it to colorize the go test output:

"^PASS", 1, white, green
"^ok", 1, white, green
"^FAIL", 1, white, red
"^--- FAIL:", 1, white, red

Available colors:

  • black
  • white
  • red
  • green
  • blue
  • brown
  • gray
  • magenta
  • 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

colorize's People

Contributors

magmax avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.