[IPython-user] [IPython-dev] bug in coloured prompt

Thorsten Kampe thorsten@thorstenkampe...
Fri Apr 6 02:36:24 CDT 2007

* Fernando Perez (Thu, 5 Apr 2007 12:18:04 -0600)
> On 4/5/07, Thorsten Kampe <thorsten@thorstenkampe.de> wrote:
> > I now received an answer from Eric Blake, the Cygwin readline
> > maintainer. Basically he says that the Prompt code in IPython (and the
> > other applications that have the problem) is buggy. Here's his main
> > statement:
> >
> > > In other words, the common bug in all three programs you mentioned
> > > is that they copied bash's escape sequences, but NOT bash's round of
> > > internal expansion, prior to calling readline.
> > > [...]
> > > Just because most other terminals (rxvt, xterm, ...) are tolerant of
> > > unknown control characters, and treat spurious invisible \001 as
> > > non-printing characters, doesn't mean that lftp, yafc, or IPython
> > > should assume that all terminals behave that way.
> >
> > Could you have a look at this and see whether he's right or wrong?
> Even without looking, there's a very good chance he's right, for the
> simple reason that he probably knows what he's talking about, while I
> don't :)
> Seriously, I know about the low-level details of readline and ANSI
> terminals as little as possible, and what I learned was just the
> minimum necessary to hack the code into behaving on all terminals I
> had access to.
> So from a 'purity' standpoint, it's *very* likely that what I'm doing
> is highly dubious.  However, it has the minor merit of actually
> working on most terminals (cygwin excepted).
> If anyone can send us patches that are more correct from the
> readline/ANSI perspective, while simultaneously keeping the current
> user-visible correct behavior on all the terminals we work on
> (konsole, gnome-terminal, rxvt, xterm, OSX Terminal, OSX X11 xterm,
> Win32 cmd terminal, probably more), I'm all for it.  Note that the
> behavior with very long lines, wrapping and history needs to be
> checked everywhere as well.

Sending a patch is beyond my capabilities. Eric Blake says (guessing 
from the faulty code of yafc and lftp):
"In other words, I wonder if IPython is adding extra \1 
somewhere else in the sequence of things, which is then resulting in 
the spurious \1 to the cmd terminal."

Therefor I would have to ask you: does IPython just add a single \001/
\002 pair or is the (colour) prompt included in /two/ escapes (like in
"readline("\001\001invisible\001\002plain")" ?!

Also I would like you to consider this: while the \001/\002 pair is in 
class InputTermColors the prompt that gets wrongly displayed is not 
the input prompt but the output prompt! Sounds not logical but that's 
the way it is.

I would like to urge you strongly to consider having a look at the 
thread mentioned (or at least at Eric's reply).

If the IPython code is wrong like Eric thinks then the correct prompt 
output from IPython relies on the undocumented behaviour of standard 
Linux consoles not to output extra \001 characters (which might 
"Just because most other terminals (rxvt, xterm, ...) are tolerant of 
unknown control characters, and treat spurious invisible \001 as non-
printing characters [...]"


More information about the IPython-user mailing list