[IPython-user] terminal colour howto request.

mark starnes m.starnes05@imperial.ac...
Wed Dec 10 05:07:35 CST 2008


Hi Fernando,

Thanks for the tip, I'm updating my code now....  :)

BR,

Mark.

Fernando Perez 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...
> 
> HTH,
> 
> f
> 


More information about the IPython-user mailing list