[IPython-dev] pyreadline

Walter Dörwald walter at livinglogic.de
Thu Mar 27 04:57:42 EDT 2008

Jörgen Stenarson wrote:

> Hi all,
> I have been thinking about the future of pyreadline considering the work 
>   on ipython1.
>   * ANSI color escapes. In trunk ansi color escapes are used to handle 
> color in prompts. This is convenient(for the programmer) when the 
> terminal understands these escapes. But on windows this is not the case, 
> I imagine a few of the guis proposed for ipython1 would also have 
> trouble with them. In pyreadline we have code for parsing this. So it 
> would probably make sense to have this functionality available for 
> ipython1 as well. From a users point of view I think we should consider 
> figuring out a way that is easier to understand and expand for the 
> future. We could include ways to use boldface, italics, underline etc.

What I did for the ipipe stuff is that the output for an object comes 
from a generator that looks like this:

def repr_list(obj):
     yield (normal, '[')
     for (i, child) in enumerate(obj):
         if i:
             yield (normal, ', ')
         for (color, part) in specialrepr(child):
             yield (color, part)
     yield (normal, '[')

i.e. the generator produces tuples with a string and a color object for 
that string. The advantage of a generator is that you can cancel the 
generator once the screen is filled, so you don't have to produce output
that you are not displaying anyway.

Currently in ipipe this color object is a wrapper for curses/ANSI 
colors, i.e. it knows about 8 foreground colors, 8 background colors, 
bold and underline.

I have a half finished version lying around, where forground and 
background color are three floats (i.e. Color(0., 0., 0.) is black, 
Color(1., 1., 1.) is white). For terminal and curses output this gets 
mapped to the nearest of the 16 ANSI colors (it also supports 256 color 

For this to be usable we probably would need theme support, because for 
terminal output you might very well have a black background, for GUIs 
you almost never have.


More information about the IPython-dev mailing list