[IPython-user] terminal colour howto request.
Tue Dec 9 03:32:33 CST 2008
On Mon, Dec 8, 2008 at 11:55 AM, mark starnes
> Hi everyone,
> Embarrassed to ask this as I'm sure it's detailed in a manual somewhere
> (but I can't find it!) but....
> How can I write to the terminal in colour? I've looked through some of
> the IPython code but couldn't spot the info I needed. I tried importing
> curses; I don't seem to have it installed, and IPython is using colour
> so I imagine there is another way.
> A short example would be appreciated!
> Best regards,
Your question prompted me to poke around the source, and I found
IPython.ColorANSI. Here's an example that print the available colours:
from IPython.ColorANSI import TermColors
colors = TermColors()
print 'IPython Colors:'
for color in dir(colors):
if not color.startswith('_'):
print getattr(colors, color), color
print colors.Blue, 'blue', colors.Red, 'green'
I hope this helps,
Matt Foster | http://hackerific.net
More information about the IPython-user