Playing with ANSI colors and python with Couleur

Last night I’ve just released the first version of Couleur, which is (or at least try to be) a simple and awesome tool for using ANSI colors with python.

Couleur indeed turns very easy to handle shell colors in python.

In action

import time
import couleur

sh = couleur.Shell(linebreak=True)
for mood in ["bad", "awful", "normal", "nice", "awesome"]:
  sh.red_on_black(mood, replace=True)
  time.sleep(1)

Couleur creates colored output dinamically, so that you can mix colors and modifiers at will:

import couleur
sh = couleur.Shell(linebreak=True)
sh.bold_black_and_bold_yellow_on_red("Gray | Yellow")

And even use “static” output, let’s simulate the output of a “git clone”:

import time
import couleur

sh = couleur.Shell(linebreak=True)
for x in range(101):
  if x is 0:
    print
  sh.normal_and_bold_green(
    "Counting objects: |%d%%" % x,
    replace=True
  )
  time.sleep(0.08)

Installation

user@machine:~$ sudo pip install couleur

Full Documentation

Available here

Contributing

Fork me on github, write tests, write code, make it pass, send a pull request :)

One Response to “Playing with ANSI colors and python with Couleur”

Leave a Response