8

I can't seem to get white-on-black to work in curses when in color mode. If I don't call start_color, I get white-on-black. As soon as I call start_color, things start outputting in grey-on-black.

If you run this script:

import sys

for i in xrange(30, 38):
    print '\x1b[0;' + str(i) + 'm' + str(i) + ': Shiny colors \x1b[1m(bright)'
print '\x1b[0m...and this is normal.'

...you'll probably see a lot of pretty colors. The one I want, and can't get, is the last line: '...and this is normal.' Asking for color pair 0 or asking for COLOR_WHITE, COLOR_BLACK gets me the non-bright #37 from the script.

For reference, this is what I see in Gnome Terminal:

http://rpi.edu/~wellir/random/colors.png

I'm programming in Python (using the curses library), so my code is something like:

import curses

screen = curses.initscr()
curses.start_color()
curses.init_pair(1, curses.COLOR_WHITE, curses.COLOR_BLACK)
screen.clear()
screen.attrset(0)
screen.addstr('Hello')
screen.attrset(curses.A_BOLD)
screen.addstr('Hello')
screen.attrset(curses.color_pair(1))
screen.addstr('Hello')
screen.refresh()
curses.napms(5000)
curses.endwin()

...which gets me 37, 37-bright, and 37.

Thanatos
  • 42,585
  • 14
  • 91
  • 146

3 Answers3

5

curses.use_default_colors()

Thanatos
  • 42,585
  • 14
  • 91
  • 146
1

I was on gnome terminal too with the same problem.

I managed to solve it with:

right click on screen > profile > profile preferences > color > palette

I think this is what each of the 8 colors will map to.

for some reason, the built-in scheme Default that was selected mapped the first color to gray instead of black!

changing scheme to XTerm, or changing the first color to black solved my problem.

I am not using curses.use_default_colors.

Ciro Santilli OurBigBook.com
  • 347,512
  • 102
  • 1,199
  • 985
  • To be clear this is in the palette and not necessarily what your terminal background is. This is absolutely essential for any curses program, not just Python. c3270 especially is hard to read with this grey and does not behave like this on Windows. #000000 – mckenzm Jun 10 '23 at 09:29
1

Your gnome terminal may have its own color scheme, which changes the colors of the default white to bright white, except when in curses mode. Check that gnome-terminal does not changes the colors, because this would make testing the colors difficult.

Sjoerd
  • 74,049
  • 16
  • 131
  • 175
  • This would make testing easier, it would seem. I want to output that "normal" text: If Gnome differentiates it with color, that'd make it all the easier to test. – Thanatos Jul 09 '10 at 05:42
  • Almost certainly using use_default_colors() won't solve the issue above and far more likely the color profile of the terminal has white / black / etc. mapped to non-normal values as described in this answer! thanks! – Doug Jan 22 '12 at 13:43
  • I am using gnome-terminal with a different color scheme, and `use_default_colors()` **did** fix my problem – mattgately Dec 19 '13 at 17:00