Search code examples
pythonmacoscolorscurses

Curses set bright and dark backgrounds


For this, it might be useful to note that I'm running python on a Mac in xterm-color

I'm trying to build a chess game with curses in Python, but I can't figure out how to set the color pairs to use bright black or bright white (so I can have better contrast between board and pieces.) The terminal shows the bright colors as being the color + 8 (so the 8-15 range,) but if I try to use those, I get back init_pair() returned ERR (For example, in:)

curses.init_pair(1, 0, 15)

I also thought that using the A_BOLD and A_BLINK attributes might let me set bright colors in curses, but that doesn't appear to have any effect. For example:

pad.addstr(y, x, "qwert", curses.color_pair(1)|curses.A_BOLD)

What do I need to do to get these colors?

Edit: It turns out that I had a wrong setting in the terminal ("Use bright colors for bold text" was unchecked,) but I still don't seem to have any way to set a bright background color.


Solution

  • I still don't seem to have any way to set a bright background color.

    This question is old, but in case someone will look for answer to it, you just have to combine curses.A_BOLD with curses.A_REVERSE, for example:

    curses.init_pair(1, curses.COLOR_GREEN, curses.color_BLACK);
    // Pair with green as a foreground color and black as a background
    curses.color_pair(1);
    // Pair with light green as a background color and black as a foreground
    curses.color_pair(1) | curses.A_BOLD | curses.REVERSE;
    

    ... and now you have 2 × more pairs :)