The short answer is that you could not get the information from terminfo until ncurses 6.1 was released in January 2018.
The longer answer:
- to effectively use TrueColor, you need an interface handling 3 parameters (for red, green, blue). Termcap cannot do this. Terminfo can handle multiple parameters, but...
- there is no standard terminal capability (a name for a feature which may be a boolean, number or a string) dealing with TrueColor as such.
- you could adapt existing capabilities, but they have limitations
Looking at the terminfo(5) manual, you might see these (strings):
initialize_color initc Ic initialize color #1
to (#2,#3,#4)
initialize_pair initp Ip Initialize color
pair #1 to
fg=(#2,#3,#4),
bg=(#5,#6,#7)
which are related to these (numbers):
max_colors colors Co maximum number of
colors on screen
max_pairs pairs pa maximum number of
color-pairs on the
screen
ANSI colors and schemes compatible with those (such as 16-, 88- and 256-colors) assume you are coloring foreground and background in pairs. The reason for that was that long ago, hardware terminals just worked that way. The initialize_color
capability is for a different scheme (Tektronix), which might seem useful.
However, terminfo is compiled, and the resulting binary files stored only signed 16-bit integers. You could not use the terminal description to store a suitable max_pairs
or max_colors
for 24-bit color. (termcap stores everything as strings, but as noted is unsuited for this application).
A couple of years after this question and answer were first written, terminfo was updated to use a new file format that uses signed 32-bit integers, which is enough for expressing the number of colours in 24-bit RGB colour.
More details can be found in release announcement for ncurses 6.1 and in the updated term(5)
manual page, which latter notes that there are still restrictions in the old API used by some applications that access the terminfo data directly.
Further reading: