On 8/28/25 04:30, Thomas Dickey wrote:
But thinking about the extensions to the API, it isn't as simple.
+ it has to support mixing indexed colors and direct colors, so that one
can have ANSI blue on top of rgb whatever.
+ without lots of interface changes, it needs functions to map to/from the
rgb triple vs a direct-color number, e.g., using a different range of
values to make checking simple.
So there's no mode-switching contemplated, but a goal of a small set of
functions to incorporate direct-colors along with attributes to remind
caller/called which is used.
Sounds reasonable.
About ten years back, PDCursesMod had something close to what (I
think) you have in mind. If you set an A_RGB attribute, you could then
set foreground and background with RGB values.
A few years later, William McBrine (maintainer of PDCurses)
persuaded me that it was a bad idea (I think "misfeature" was the word
he used). He pointed out that (a) it breaks the existing curses color
model and (b) you don't really need it if you have enough color pairs
and colors. It was simpler and better to just make it possible to have
lots and lots of color pairs and colors, within the existing curses
color model. (Well, you could argue it stretches that model a little.)
In PDCursesMod, I got around all this by having COLORS = 256 +
2^24. By default, the first 256 are the "standard" sixteen plus 6x6x6
color cube plus 24 grayscales; the remaining 2^24 are RGBs. I bumped
up COLOR_PAIRS to 2^20 = 1048576 color pairs, which should be enough
for anybody. (Suffices, albeit barely, for a picture-drawing program
on a 1920x1080 display with a 2x4 pixel font, where each cell may have
its own color pair. I have a picsmap-like demo and a Mandelbrot set
program that use the scheme.)
For both color pairs and colors, memory is only allocated as
needed. If you set, say, color pair 42, the color pair table is
reallocated to have 64 entries (next higher power of two). So most
programs actually use less memory than they did before, when those
tables were at fixed maximum sizes.
The only needed extensions were init_extended_pair(),
extended_color_content(), etc. Which I already had anyway.
-- Bill