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

Gary Bishop gb at cs.unc.edu
Mon Jun 2 14:37:57 EDT 2003


I have attached a patch that, along with my readline package, will make 
IPython function in glorious color, with completion, line editing, 
history on Windows (only tested on XP).

I don't *think* these changes impact other ports 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.

The third change is the result of our previous exchange on getting \ 
escapes to work. This variant seems to work fine.

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

My readline code is now available via CVS from
http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/uncpythontools/readline/

gb
-------------- next part --------------
A non-text attachment was scrubbed...
Name: diffs
Type: application/octet-stream
Size: 7735 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/ipython-dev/attachments/20030602/c49b4d49/attachment.obj>


More information about the IPython-dev mailing list