Since Audacious crashes in Ubuntu 9.10 when playing NSF files, I was compelled to compile a newer version for personal use, and I noticed that their build system is tricked out with very little extraneous geek-cred output and some colored output. I have been writing lots of little one-off bulk job scripts lately, and when I realized the answer to the question "Why don't I do this?" was "I don't know how", I decided to do some google jump roping and figure it out.

I've been playing around with my PS1 recently and had some idea of what I was looking for. Of course, the answer can always be found on PyPi and the termcolor seems like it'd do quite nicely. However, for the simple uses I required, 3 little lines of python were enough:

white, black, red, green, yellow, blue, purple = range(89, 96)
def color(string, color=green, bold=True):
    return '\033[%s%sm' % ('01;' if bold else '', color) + str(string) + '\033[0m'

For quick one off jobs, this is probably all you need. The termcolor module is a good bet if you are going to be writing lots of these, as import termcolor is obviously shorter still, and it is less likely to break dramatically and illegibly on stranger software configurations.

Jan 20 2010