dvergin has asked for the wisdom of the Perl Monks concerning the following question:

I posted this question over the weekend. I'm hoping this week-day post will find its way to someone who has the answer.

The short of it is: How do I get the Curses module (and ncurses itself) to give me more than one color on a true white background.

All of the Curses/ncurses docs and discussions I can find mostly ignore that what Curses calls WHITE (off-white to the eye) is not the same (true) white that Curses is able to produce in certain limited cases as a background color. In particular, using a non-standard background color of '8'...

assume_default_colors(COLOR_BLACK, 8); # True White bg! Why? . . . init_pair(3, COLOR_RED, 8); # Produces Black on Black
The assume_default_colors(SOMECOLOR, 8) trick gives me the kind of thing I want. But how can I get a second color on true white on the same screen.

Some docs do acknowledge that white in the foreground can be "bolded" to get true white. But that is no help for the background.

Curses looks like a wonderful tool -- I'd like to use it. But this one hang-up could be a deal-breaker for applying it in my current task.

Sample code was posted in the node referred to above.

Update: Dear Reader, do not be discouraged from responding by the extended discussion below with steves. Though it is illuminating, it does not lead to a solution to my problem.

------------------------------------------------------------
"Perl is a mess and that's good because the
problem space is also a mess.
" - Larry Wall

Replies are listed 'Best First'.
Re: Color on TrueWhite in Curses - Redux
by steves (Curate) on Feb 04, 2003 at 20:13 UTC

    Maybe I'm being thick, but can_change_color is returning false, which is telling you your terminal can't change colors. Basically it sounds like you want to send color sequences to a terminal that doesn't support it. The terminal (which may be a console driver ... same basic thing from a curses point of view) may be using colors as part of its monchrome display which may be confusing you.

    Way back when I worked on a curses-like thing the first step was to manually apply the escape sequences to see if the terminals did what we wanted. It could be that you have color capablites but you either have your TERM environment variable set to a monochrome version; or you have a termcap/terminfo entry that isn't specifying the color sequences even though the terminal supports them.

    I did get a smile from the "curses looks like a wonderful tool ..." bit. I suppose there are still uses and I loved this kind of work when I did it, but the advent of windows and web browsers pretty much ended my foray into the world of ASCII terminals.

      Nope.

      can_change_color() tells you whether the terminal can change its color setup. There is a different function called has_colors() that tells you whether the terminal can display colors at all.

      I can produce colors on my terminal with the Curses module just fine. I can double the number of available foreground colors by using "BOLD". And I can establish a library of up to 64 color pairs (foreground/background) to refer to as I wish.

      What "can_change_color() == 0" tells me is that I cannot use the init_color(...) function to build a custom color beyond the eight that are initially available.

      I can get multiple foreground colors on any of eight predetermined background colors on the same screen. But I cannot achieve two foreground colors on true white on the same screen.

      Regarding "I suppose there are still uses..." There are indeed. I am building a new UI for a server admin tool that has out-grown its command line interface. Since this tool will only be used via SSH, I am implementing this as a character-based full-window design. The kind of interactive responsiveness we desire makes a CGI solution impractical.

      ------------------------------------------------------------
      "Perl is a mess and that's good because the
      problem space is also a mess.
      " - Larry Wall

        My mistake on simplifying this. You've obviously dug in quite a bit here ...

        As a first course of action I'd still see if it's a terminal/driver limitation or a bug in curses; i.e., get into a mode on the terminal that allows you to type in escape sequences. When I used to do this stuff we wrote a small program for this that set the terminal to raw mode and recognized a 'QUIT' sequence to get back to the shell. That allowed us to try out the documented sequences. As you probably already know, what's documented doesn't always work. At one point we had three configurations for 3 different SCO xterm consoles because they kept introducing new bugs with each driver ... but I digress. Get to this sort of mode, set the background to true white, then try setting foreground colors and see if they work. That should show you if this is a terminal/driver issue or a curses issue.