[IPython-dev] Updates to CVS: tab completion and Windows coloring

Fernando Perez fperez at colorado.edu
Mon Dec 1 16:49:41 EST 2003


Hi all,

today I've committed a fair amount of changes to CVS, mainly from the 
contributions of Jeff Collins and Gary Bishop.  I'd like to give all a brief 
update on this, since it would be great to see some testing of this code as I 
start cleaning things up for a new release.

- Jeff's work: it fixes tab completion for filenames under python 2.3, which 
broke because the python developers changed the hardcoded behavior of the 
readline library.

One small caveat:  under redhat 8.0, I am seeing an extraneous space appended 
to completed filenames.  Jeff helped me track its source, and it is an 
improperly built readline.so by redhat, which is missing the 
rl_completion_append_character variable.  This variable can NOT be set via 
python code, so there's nothing I can do about it.  Redhat 9's python, and 
almost any correctly built python, should not exhibit this small annoyance.

- Gary's work:  this allows coloring under Windows, with some extra code 
provided by Gary.  Please note that I modified his patches somewhat, in 
particular I renamed ColorTerm to Term because in the future I'll be using 
this facility for all I/O, not just coloring.  So I'm reposting his 
instructions here with the necessary changes for the benefit of Windows users:

################################# Gary's instructions for Windows, modified to 
work with the current CVS ipython:

I have attached a patch for IPython 0.5-cvs that, along with my
readline package, will make IPython on Windows work like it does on
more capable systems.

My readline code is available via CVS from
http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/uncpythontools/readline/
I use it inside and outside IPython and it seems to work fine.

I don't think these changes impact other platforms but I certainly
could be wrong since I haven't tested anywhere else.

Most of the changes are of the form:

- print header,output,
+ print >>Term.out, header,output,

These send prints that could contain color escapes explicitly to a file
object instead of relying on sys.stdout. Term.out and
Term.err are initialized to sys.stdout and sys.stderr, so
everything should work the same. On Windows, a user may optionally
include the following in his IPYTHONDIR

enable_color.py
--------------------------------------------------------------------------------

'''Turn on the translation of ANSI color escapes for Windows'''

import IPython
import readline

out = readline.GetOutputFile()
IPython.genutils.Term.out = out
IPython.genutils.Term.err = out
del out
del readline
del IPython
--------------------------------------------------------------------------------

and this line in ipythonrc.ini

execfile enable_color.py

To translate ANSI color escapes into the proper colors on the Windows
console. Without this it will work fine without color.

#################################

Gary:  I'd also like you to help me with a couple of things concerning this code.

1.  You made changes to page(), to make it work with 'less' under 
windows+cygwin.  I want to be sure that users who DON'T have cygwin are still 
ok.  Is that the case?

2.  The code below is around line 913 of genutils.py.  Do you know which 
exceptions can this trigger under Windows, so we only trap those?  I don't 
like blanket except clauses (ipython has many, but I'm trying to clean them up 
as much as possible).  I also added the inner try/finally to ensure proper 
cleanup.


             try:
                 try:
                     tmpname = tempfile.mktemp('.txt')
                     tmpfile = file(tmpname,'wt')
                     tmpfile.write(strng)
                     tmpfile.close()
                     cmd = pager_cmd + ' < ' + tmpname
                     os.system(cmd)
                     retval = None
                 finally:
                     os.remove(tmpname)
             except:  # FIXME: trap only the reasonable exceptions
                 retval = 1

You can send me any new patches against current CVS.

Ok folks, I'll be working some more on ipython over the next few weeks, to 
finish cleaning up some other things.  But these two big changes are important 
enough that I'd really like to hear some feedback, especially if there are 
problems.

Many thanks to Jeff and Gary, both for their work and for their patience with 
my sloooow response.

Regards,

Fernando.



More information about the IPython-dev mailing list