IPython colors in windows

Claudio Grondi claudio.grondi at freenet.de
Sat Feb 5 18:54:59 EST 2005


"Ashot" <ashot at removemolsoftthis.com> schrieb im Newsbeitrag
news:opslo7jfhqej1m1c at ashot...
> whoa, that was quick, looks like it works for me.  Thanks a lot!
> It would be nice to be able to set the colors in the prefs file, although
> its possible to edit the pyColorize file as Claudio mentioned.
To get the coloured texts on a grey (instead of white) background
I have extended the Console.py to accept sequences as e.g.
  "0;33;47" (see attachment)
have extended also the
  def make_color_table(in_class):
in the ColorANSI.py of IPython
and adjusted the pyColorize.py file, but it had not the desired effect.
IPython seems not to be sending to Console.py the sequences
defined in the
 LightBGColors = ColorScheme( ... )
section of pyColorize.py (or there is a problem with the
extension I have done to Console.py)
I have just forced Console.py to treat "0;33" as "0;33;47", to
achieve the result I want (see attachment).
It seems, that the  problem with Console.py of the readline module,
is not the only one which existed - there is maybe also a problem
with IPython color schemes handling, so I gave up to try to achieve
a clean nice solution supporting also selection of background colors
for any colorized text output in IPython.
It works for me as it is now, so probably it is better to wait for the
next release of IPython with a cleaner implementation of color
schemes before further efforts towards support for choosing
of background colors for each colorized text output in IPython
via extension of Console.py of the readline module.

Claudio

attachment:
  # Mapping of ANSI color escape sequences into  wAttributes  (Windows
Console
  # Attributes) according to constants #define(d) in WinCon.h for usage
with:
  #   WINBASEAPI BOOL WINAPI SetConsoleTextAttribute(
  #     IN HANDLE hConsoleOutput,
  #     IN WORD wAttributes );
  escape_to_color = {
     '0'   :                     None                        # reset colors
to default setting
  # text color (color of characters):
    # #                Foreground           Background
    # #               I , R , G , B        I , R , G , B       #
Intensified, Red, Green, Blue
    # ,'0;30':      (            0x0)                          # (dark)black
(#000000)
    # ,'0;31':      (    0x4        )                          # (dark)red
(#800000)
    # ,'0;32':      (        0x2    )                          # (dark)green
(#008000)
    # ,'0;33':      (    0x4+0x2    )                          #
(dark)yellow (#808000)
    # ,'0;34':      (            0x1)                          # (dark)blue
(#000080)
    # ,'0;35':      (    0x4+    0x1)                          #
(dark)purple (#800080)
    # ,'0;36':      (    0x4+0x2    )                          # (dark)cyan
(#808000)
    # ,'0;37':      (    0x4+0x2+0x1)                          # (dark)white
(#C0C0C0)
    # #                Foreground           Background
    # #               I , R , G , B        I , R , G , B       #
Intensified, Red, Green, Blue
    # ,'1;30':      (0x8            )                          # light black
(#808080)
    # ,'1;31':      (0x8+0x4        )                          # light red
(#FF0000)
    # ,'1;32':      (0x8+    0x2    )                          # light green
(#00FF00)
    # ,'1;33':      (0x8+0x4+0x2    )                          # light
yellow (#FFFF00)
    # ,'1;34':      (0x8+        0x1)                          # light blue
(#0000FF)
    # ,'1;35':      (0x8+0x4+    0x1)                          # light
purple (#FF00FF)
    # ,'1;36':      (0x8+0x4+0x2    )                          # light cyan
(#FFFF00)
    # ,'1;37':      (0x8+0x4+0x2+0x1)                          # light white
(#FFFFFF)
  # text background color (color of rectangles in which text characters are
displayed):
    #                Foreground           Background
    #               I , R , G , B        I , R , G , B       # Intensified,
Red, Green, Blue
    ,'0;40':                          ((            0x0)<<4) # dark  black
(#000000)
    ,'0;41':                          ((    0x4        )<<4) # dark  red
(#800000)
    ,'0;42':                          ((        0x2    )<<4) # dark  green
(#008000)
    ,'0;43':                          ((    0x4+0x2    )<<4) # dark  yellow
(#808000)
    ,'0;44':                          ((            0x1)<<4) # dark  blue
(#000080)
    ,'0;45':                          ((    0x4+    0x1)<<4) # dark  purple
(#800080)
    ,'0;46':                          ((    0x4+0x2    )<<4) # dark  cyan
(#808000)
    ,'0;47':                          ((    0x4+0x2+0x1)<<4) # dark  white
(#C0C0C0)
    #                Foreground           Background
    #               I , R , G , B        I , R , G , B       # Intensified,
Red, Green, Blue
    ,'1;40':                          ((0x8            )<<4) # light black
(#808080)
    ,'1;41':                          ((0x8+0x4        )<<4) # light red
(#FF0000)
    ,'1;42':                          ((0x8+    0x2    )<<4) # light green
(#00FF00)
    ,'1;43':                          ((0x8+0x4+0x2    )<<4) # light yellow
(#FFFF00)
    ,'1;44':                          ((0x8+        0x1)<<4) # light blue
(#0000FF)
    ,'1;45':                          ((0x8+0x4+    0x1)<<4) # light purple
(#FF00FF)
    ,'1;46':                          ((0x8+0x4+0x2    )<<4) # light cyan
(#FFFF00)
    ,'1;47':                          ((0x8+0x4+0x2+0x1)<<4) # light white
(#FFFFFF)
  # text color (color of characters) on grey background:
    #                Foreground           Background
    #               I , R , G , B        I , R , G , B       # Intensified,
Red, Green, Blue
    ,'0;30;47':   (            0x0) + ((0x8            )<<4) # light black
(#808080)
    ,'0;31;47':   (    0x4        ) + ((    0x4+0x2+0x1)<<4) # (dark)red
(on light grey #C0C0C0)
    ,'0;32;47':   (        0x2    ) + ((    0x4+0x2+0x1)<<4) # (dark)green
(on light grey #C0C0C0)
    ,'0;33;47':   (    0x4+0x2    ) + ((    0x4+0x2+0x1)<<4) # (dark)yellow(
on light grey #C0C0C0)
    ,'0;34;47':   (            0x1) + ((    0x4+0x2+0x1)<<4) # (dark)blue
(on light grey #C0C0C0)
    ,'0;35;47':   (    0x4+    0x1) + ((    0x4+0x2+0x1)<<4) #
(dark)purple(on light grey #C0C0C0)
    ,'0;36;47':   (    0x4+0x2    ) + ((    0x4+0x2+0x1)<<4) # (dark)cyan
(on light grey #C0C0C0)
    ,'0;37;47':   (    0x4+0x2+0x1) + ((    0x4+0x2+0x1)<<4) # (dark)white
(on light grey #C0C0C0)
    #                Foreground           Background
    #               I , R , G , B        I , R , G , B       # Intensified,
Red, Green, Blue
    ,'1;30;40':   (0x8            ) + ((0x8            )<<4) # light black
(#808080)
    ,'1;31;40':   (0x8+0x4        ) + ((0x8            )<<4) # light red
(on dark grey #808080)
    ,'1;32;40':   (0x8+    0x2    ) + ((0x8            )<<4) # light green
(on dark grey #808080)
    ,'1;33;40':   (0x8+0x4+0x2    ) + ((0x8            )<<4) # light yellow
(on dark grey #808080)
    ,'1;34;40':   (0x8+        0x1) + ((0x8            )<<4) # light blue
(on dark grey #808080)
    ,'1;35;40':   (0x8+0x4+    0x1) + ((0x8            )<<4) # light purple
(on dark grey #808080)
    ,'1;36;40':   (0x8+0x4+0x2    ) + ((0x8            )<<4) # light cyan
(on dark grey #808080)
    ,'1;37;40':   (0x8+0x4+0x2+0x1) + ((0x8            )<<4) # light white
(on dark grey #808080)
    #                Foreground           Background
    #               I , R , G , B        I , R , G , B       # Intensified,
Red, Green, Blue
    ,'1;30;0;47': (0x8            ) + ((0x8            )<<4) # light black
(#808080)
    ,'1;31;0;47': (0x8+0x4        ) + ((0x8            )<<4) # light red
(on dark grey #808080)
    ,'1;32;0;47': (0x8+    0x2    ) + ((0x8            )<<4) # light green
(on dark grey #808080)
    ,'1;33;0;47': (0x8+0x4+0x2    ) + ((0x8            )<<4) # light yellow
(on dark grey #808080)
    ,'1;34;0;47': (0x8+        0x1) + ((0x8            )<<4) # light blue
(on dark grey #808080)
    ,'1;35;0;47': (0x8+0x4+    0x1) + ((0x8            )<<4) # light purple
(on dark grey #808080)
    ,'1;36;0;47': (0x8+0x4+0x2    ) + ((0x8            )<<4) # light cyan
(on dark grey #808080)
    ,'1;37;0;47': (0x8+0x4+0x2+0x1) + ((0x8            )<<4) # light white
(on dark grey #808080)
    #                Foreground           Background
    #               I , R , G , B        I , R , G , B       # Intensified,
Red, Green, Blue
    ,'0;30':      (            0x0) + ((    0x4+0x2+0x1)<<4) # (dark)black
(on light grey #C0C0C0)
    ,'0;31':      (    0x4        ) + ((    0x4+0x2+0x1)<<4) # (dark)red
(on light grey #C0C0C0)
    ,'0;32':      (        0x2    ) + ((    0x4+0x2+0x1)<<4) # (dark)green
(on light grey #C0C0C0)
    ,'0;33':      (    0x4+0x2    ) + ((    0x4+0x2+0x1)<<4) #
(dark)yellow(on light grey #C0C0C0)
    ,'0;34':      (            0x1) + ((    0x4+0x2+0x1)<<4) # (dark)blue
(on light grey #C0C0C0)
    ,'0;35':      (    0x4+    0x1) + ((    0x4+0x2+0x1)<<4) #
(dark)purple(on light grey #C0C0C0)
    ,'0;36':      (    0x4+0x2    ) + ((    0x4+0x2+0x1)<<4) # (dark)cyan
(on light grey #C0C0C0)
    ,'0;37':      (    0x4+0x2+0x1) + ((    0x4+0x2+0x1)<<4) # (dark)white
(on light grey #C0C0C0)
    #                Foreground           Background
    #               I , R , G , B        I , R , G , B       # Intensified,
Red, Green, Blue
    ,'1;30':      (0x8            ) + ((    0x4+0x2+0x1)<<4) # light black
(on light grey #C0C0C0)
    ,'1;31':      (0x8+0x4        ) + ((    0x4+0x2+0x1)<<4) # light red
(on light grey #C0C0C0)
    ,'1;32':      (0x8+    0x2    ) + ((    0x4+0x2+0x1)<<4) # light green
(on light grey #C0C0C0)
    ,'1;33':      (0x8+0x4+0x2    ) + ((    0x4+0x2+0x1)<<4) # light
yellow(on light grey #C0C0C0)
    ,'1;34':      (0x8+        0x1) + ((    0x4+0x2+0x1)<<4) # light blue
(on light grey #C0C0C0)
    ,'1;35':      (0x8+0x4+    0x1) + ((    0x4+0x2+0x1)<<4) # light
purple(on light grey #C0C0C0)
    ,'1;36':      (0x8+0x4+0x2    ) + ((    0x4+0x2+0x1)<<4) # light cyan
(on light grey #C0C0C0)
    ,'1;37':      (0x8+0x4+0x2+0x1) + ((    0x4+0x2+0x1)<<4) # light white
(on light grey #C0C0C0)
  }





More information about the Python-list mailing list