Re: ANSI color issue (SOLVED)

David Clymer <david-LEGOU7lN1jbY0TyS/[email protected]> Sat, 18 Dec 2004 11:35:13 -0500
Newsgroups gmane.comp.games.mud.client.lyntin
Message-ID <1103387713.4364.75.camel@localhost>
On Mon, 2004-12-13 at 14:00, David Clymer wrote:
> On Mon, 2004-12-13 at 13:15, will guaraldi wrote:
> > There's a section in the cursesui code called "color_lookup".  I'm 
> > gusseing that you probably need to fiddle with the color codes in there. 
> > I would say poke around until you find the right light grey, dark grey, 
> > white, and black and then send a diff.
> > 
> 
> I'll take another look at it, but I dont think that is used in the
> _decode_colors function which does the ANSI -> curses color stuff. It
> may be a curses problem of some sort...but ATM, I dont know much about
> that.

Well, it seems that it is a "problem" with curses. The problem is that
the curses (on my terminal) has 8 colors and 64 color combinations to
work with. Of those 64 color pairs, all but colorpair 0 are mutable.
Color pair 0 is set to white on black and cannot be changed. When
cursesui generated its pallette of color pairs (fg,bg) to be used in
coloring text, it was also generating a (white,black) color pair. I've
replaced the duplicate color pair with a (black,black) pair which, in
conjunction with curses.A_BOLD will produce dark grey text. As long as
curses_fore() is used to generate color attributes, all coloring should
work as expected.

-davidc


*** cursesui.py	2004-12-18 11:26:37.000000000 -0500
--- cursesui.py.orig	2004-12-12 11:39:28.000000000 -0500
***************
*** 201,211 ****
    
  
  def curses_fore(color):
-   # generate default attribute when using white, since it is white
anyway
-   if color == 7:
-     color = 0
-   elif color == 0:
-     color = 7
    return color * 256
    
  
--- 201,206 ----
***************
*** 218,233 ****
  
  
  color_lookup = {
!   'white':   curses.A_BOLD,
!   'normal':  curses.A_NORMAL,
!   'grey':    curses_fore(curses.COLOR_BLACK) | curses.A_BOLD,
!   'red':     curses_fore(curses.COLOR_RED),
!   'green':   curses_fore(curses.COLOR_GREEN),
!   'blue':    curses_fore(curses.COLOR_BLUE),
!   'brown':   curses_fore(curses.COLOR_YELLOW),
    'yellow':  curses_fore(curses.COLOR_YELLOW) | curses.A_BOLD,
    'magenta': curses_fore(curses.COLOR_MAGENTA),
!   'cyan':    curses_fore(curses.COLOR_CYAN),
  }
  
  
--- 213,227 ----
  
  
  color_lookup = {
!   'white':  curses.A_BOLD,
!   'grey':   curses.A_NORMAL,
!   'red':    curses_fore(curses.COLOR_RED),
!   'green':  curses_fore(curses.COLOR_GREEN),
!   'blue':   curses_fore(curses.COLOR_BLUE),
!   'brown':  curses_fore(curses.COLOR_YELLOW),
    'yellow':  curses_fore(curses.COLOR_YELLOW) | curses.A_BOLD,
    'magenta': curses_fore(curses.COLOR_MAGENTA),
!   'cyan': curses_fore(curses.COLOR_CYAN)
  }
  
  
***************
*** 666,678 ****
        stdscr = curses.initscr()
        if curses.has_colors():
          curses.start_color()
-         # generate our pallette of fg/bg color combinations
          for i in xrange(1,64):
            curses.init_pair(i, i%8, i/8)
- 
-       # dont duplicate colorpair 0 (colorpair 0 is set to white on
black and cannot be changed)
-       curses.init_pair(7, curses.COLOR_BLACK, curses.COLOR_BLACK)
- 
        curses.raw()
        curses.noecho()
        curses.nonl()
--- 660,667 ----




-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now. 
http://productguide.itmanagersjournal.com/