Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ncurses and white-on-black

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.

like image 803
Thanatos Avatar asked Jul 08 '10 06:07

Thanatos


People also ask

How do you color Ncurses?

To use color, you must call the start_color() function soon after calling initscr() , to initialize the default color set (the curses. wrapper() function does this automatically). Once that's done, the has_colors() function returns TRUE if the terminal in use can actually display color.


1 Answers

curses.use_default_colors()

like image 92
Thanatos Avatar answered Oct 02 '22 19:10

Thanatos