Subject: Re: curses background color issue
To: None <netbsd-help@netbsd.org>
From: Julian Coleman <jdc@coris.org.uk>
List: netbsd-help
Date: 03/09/2004 21:10:53
> How does one correctly initialise a color pair so as only to set the
> foreground color? (thus preserving the terminal's background)
>
> Right now I'm using (on -CURRENT, as 1.6.1 doesn't support
> use_default_colors) the following:
>
> init_pair(1, COLOR_YELLOW, -1);
>
> which works, but there's no mentioning of this (the -1) in the manpages
> of -CURRENT, and there are absolutely no checks in the code of curses on
> what to do with -1, it seems (or I'm missing them).
Your code is correct. The only manual page that mentions colour -1 is the
curses_default_colors(3) page. I'll add the list of colours and mention
colour -1 on the curses_color(3) page too. Thanks for pointing this out.
The code that allows colour -1 to be set is in the functions init_pair()
and assume_default_colors() in lib/libcurses/color.c. The code that parses
the values (and handles colour -1) is in the internal function __set_color()
(which is called from the internal screen refresh function makech() in
refresh.c).
> But later they are saying it does not have to be -1 necessarily, but
> can be any negative value:
We only accept -1. As we are emulating an ncurses interface, we should
accept any negative number here. I'll change init_pair() to treat any
negative number as -1. I think ncurses should really have defined (say)
COLOR_DEFAULT here, for consistency with other curses definitions.
> And I've observed that 0 also works as background color in NetBSD
> curses, but negative values other than -1 don't work, while in ncurses
> they do.
0 is COLOR_BLACK (/usr/include/curses.h), which might be the colour of your
terminal background. Also, note that changing colour pair 0 has no affect
and that we deviate from the ncurses implementation by allowing colour -1
to be set even if use_default_colors() has not been called.
> Does this mean our curses implementation is flawed, or the documentation
> is incomplete, or both?
A bit of both.
J
--
My other computer also runs NetBSD / Sailing at Newbiggin
http://www.netbsd.org/ / http://www.newbigginsailingclub.org/