[IPython-dev] Patch for IPython with color on Windows

Gary Bishop gb at cs.unc.edu
Wed Nov 19 16:09:16 EST 2003


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 >>ColorTerm.out, header,output,

These send prints that could contain color escapes explicitly to a file 
object instead of relying on sys.stdout. ColorTerm.out and 
ColorTerm.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.ColorTerm.out = out
IPython.genutils.ColorTerm.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.

The second change included in these patches makes "less" work properly 
as the pager on Windows. I'm using the cygwin port of less. It doesn't 
want to work properly with popen2 so I added a clause to "page" in 
genutils to make it page from a file.

I'll be happy to help in any way I can to get these or some better 
variant into IPython.

gb


-------------- next part --------------
A non-text attachment was scrubbed...
Name: gbpatch
Type: application/octet-stream
Size: 8896 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/ipython-dev/attachments/20031119/f90608c0/attachment.obj>


More information about the IPython-dev mailing list