IPython colors in windows

Claudio Grondi claudio.grondi at freenet.de
Sun Feb 6 13:11:51 EST 2005


Hi,

I have done some more work on Console.py
from the readline package version 1.12, adding
support for background colors and testing of proper
function of them (run the Console.py script to
see coloured output).
Added was also the possibility to set the default
text/background colors for colored output using:
  Console.setStandardBackgroundColorTo(strColor)
  Console.setStandardForegroundColorTo(strColor)
where strColor can be one of:
[
 '(dark)black'
,'(dark)red',
,'(dark)green'
,'(dark)yellow'
,'(dark)blue'
,'(dark)purple'
,'(dark)cyan'
,'(dark)white'
,'light black'
,'light red'
,'light green'
,'light yellow'
,'light blue'
,'light purple'
,'light cyan'
,'light white'
]

There are some comments added where e.g.
the colors are named including their HTML color
notation to clarify which colors are displayed.
I work on Windows 2000 SP 4, so it will be
interesting for me to get some feedback if the
colors are the same in other Windows versions.
Which colors are displayed on Linux/Unix by
the native readline?

There are also some other changes done to
make the code better readable (from my
personal point of view ;-)

The blnIPythonFixActive flag allows to set colored
text output of IPython to (dark)white background
(instead of the standard one, which is  in my
Console the 'light white' one i.e. I work with white
background as IDLE does).

Another modification is, that when a text without
escape sequences is passed to Console.write(),
no escape sequences are sent, so, that the
colouring stays the same until it is explicitely
reset. I find this behaviour more strightforward
than the implicit writing of texts in the standard
colors if no colors are specified.

If someone is interested to check it out I have
uploaded it to:
 http://people.freenet.de/AiTI-IT/Python/Console.py

The extended Console.py module can be used
standalone for writing of any coloured texts
to the console using alternatively .
  Console.setStandardBackgroundColorTo(strColor)
  Console.setStandardForegroundColorTo(strColor)
  with resetting the colors
or the build-in ANSI escape sequences for the
text and the background.

Utilizing the code or some parts of it in
the next release of readline is welcome.

Claudio

"Gary Bishop" <gb at cs.unc.edu> schrieb im Newsbeitrag
news:42057751_1 at news.unc.edu...
> On SourceForge you will find release 1.12 of my Python readline
> module. If you don't want to hack the colors, there is no reason to
> upgrade from 1.11 to 1.12. They *should* work the same.
>
> But if you'd like to hack the iPython colors this new version makes it
> possible.  In your ipythonrc file add a line like:
>
> execfile hackcolors.py
>
> Now in hackcolors.py you can change colors and backgrounds like this:
>
> ####hackcolors.py####
> import readline
>
> # reach deep into the bowels of readline to get the color table
> escape_to_color = readline.rl.console.escape_to_color
>
> # change a color
> escape_to_color['0;32'] = 0x72
>
> del escape_to_color
> del readline
>
> #################
>
> The two hex digits are the background and foreground color
> respectively. In the example above I'm setting the color to green on a
> grey background. Here is the table that is normally used to translate
> colors.
>
>   escape_to_color = { '0;30': 0x0,             #black
>                       '0;31': 0x4,             #red
>                       '0;32': 0x2,             #green
>                       '0;33': 0x4+0x2,         #brown?
>                       '0;34': 0x1,             #blue
>                       '0;35': 0x1+0x4,         #purple
>                       '0;36': 0x2+0x4,         #cyan
>                       '0;37': 0x1+0x2+0x4,     #grey
>                       '1;30': 0x1+0x2+0x4,     #dark gray
>                       '1;31': 0x4+0x8,         #red
>                       '1;32': 0x2+0x8,         #light green
>                       '1;33': 0x4+0x2+0x8,     #yellow
>                       '1;34': 0x1+0x8,         #light blue
>                       '1;35': 0x1+0x4+0x8,     #light purple
>                       '1;36': 0x1+0x2+0x8,     #light cyan
>                       '1;37': 0x1+0x2+0x4+0x8, #white
>                       '0': None,
>                       }
>
> An interested party should be able to arbitrarily map colors and their
> backgrounds.
>
> Enjoy,
> gb
>





More information about the Python-list mailing list