[IPython-user] terminal colour howto request.
Matt Foster
matt.p.foster@gmail....
Wed Dec 10 02:20:23 CST 2008
On Wed, Dec 10, 2008 at 7:37 AM, Fernando Perez <fperez.net@gmail.com> wrote:
> Hi Mark,
>
> On Tue, Dec 9, 2008 at 2:02 AM, mark starnes <m.starnes05@imperial.ac.uk> 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
> with c.Normal:
>
> In [9]: print c.Blue,'hello',c.Red,'world',c.Normal
> hello world
>
> 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 [1]: %colors nocolor
>
> In [2]: from IPython.ColorANSI import TermColors
>
> In [3]: c = TermColors()
>
> In [4]: print c.Blue,'hello',c.Red,'world'
> hello world
>
> # now all your prompts and text are red...
I wondered about that, then promptly forgot!
Thanks for the clarification,
Matt
--
Matt Foster | http://hackerific.net
More information about the IPython-user
mailing list