开发者

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()

...whi开发者_如何学JAVAch gets me 37, 37-bright, and 37.


curses.use_default_colors()


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜