[IPython-user] terminal colour howto request.
Wed Dec 10 01:37:31 CST 2008
On Tue, Dec 9, 2008 at 2:02 AM, mark starnes <firstname.lastname@example.org> wrote:
> It does help, thanks Matt.
> Some context: I'm printing output from the engines I have, with different
> colours. Obvious, I guess but I'm still learning......
Just to add to Matt's great little example, so you understand how ANSI
colors work: in general you want to end every color print statement
In : print c.Blue,'hello',c.Red,'world',c.Normal
so that the terminal state returns to normal. Each ansi escape sets
the color until it gets reset, so it's good practice to reset it to
the default state. In ipython that doesn't matter because the default
prompts reset the colors, but you can try this to see what I mean:
In : %colors nocolor
In : from IPython.ColorANSI import TermColors
In : c = TermColors()
In : print c.Blue,'hello',c.Red,'world'
# now all your prompts and text are red...
More information about the IPython-user