24bit color reporting in terminfo?

626 views
Skip to first unread message

John de Largentaye

unread,
Mar 21, 2019, 8:03:19 PM3/21/19
to iterm2-discuss
(preemptive apologies if this topic has been discussed previously)
(context: iTerm 3.2.7, macOS 10.14 18A390, ncurses 6.1.20180127 via MacPorts)

I've been exploring 24bit color support, and I think there's a couple places reporting could be improved.

ncurses supports reporting 24bit color in terminfo through the ill-documented "RGB" capability since ncurses-6.0-20180121 according to the XVilka [1] gist. I didn't find it mentioned explicitly in the release notes nor can find ncurses revision control (!?), but that version did add xterm-direct (and others) that has this capability.

$ tput -T xterm-direct RGB; echo $?
0

compare with:
$ tput -T xterm-256color RGB; echo $?
tput: unknown terminfo capability 'RGB'
4
$

(confusing output; I only know enough about ncurses to be dangerous, QED this topic)

As it is, the terminal software ecosystem still relies on a collection of hacks from before ncurses supported this cap to sleuth out if the terminal supports 24bit. Emacs looks for [2] the stf24 and setb24 caps, and I don't know if Vim can/does [3] autodetect it. Tmux does recognize the terminfo RGB cap.

Anyhow, since iTerm2 does support 24bit color with the control codes that xterm-direct supports, I think it would be useful to add that as a default selection item to "Report terminal type" profile preference drop-down, don't you think?

Now, granted, this implies existence of an xterm-direct terminfo file on the machine. As of my version of macOS, the bundled ncurses is 5.7.20081102 which doesn't include that entry. Is it viable for iTerm2 to ship an appropriate terminfo to put in a user's ~/.terminfo/ ? Unfortunately, I wasn't able to make this work in my limited testing. Either macOS's ncurses won't search ~/.terminfo/ (by itself nor when I set $TERMINFO), or it doesn't recognize the (newer?) format.

Can you think of any other ways to make usage of 24bit-color mode easier?

(postfacto apologies if I don't quite make sense. Delving into ncurses has an... effect... on one's mind)

Jean de Largentaye

unread,
Mar 21, 2019, 8:57:50 PM3/21/19
to iterm2-discuss
Correction: setting $TERM=xterm-direct isn't really viable.

This is because all the system utilities (like "less") are linked with the system ncurses, which won't recognize the xterm-direct terminfo (because of format, location... I don't know).

Thus, we're stuck with TERM set to some value shipped as part of macOS, and hacks on top of that to get programs to use 24bit color.

--
You received this message because you are subscribed to the Google Groups "iterm2-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to iterm2-discus...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Jean de Largentaye

unread,
Mar 21, 2019, 9:28:51 PM3/21/19
to iterm2-discuss
Actually, it's possible to provide an functional xterm-direct (or other) terminfo, it just had to be compiled with the right version of tic, such as the system one, and modified to accommodate the older ncurses' limits.

$ /opt/local/bin/infocmp xterm-direct > xterm-direct.src
# edit the src file to change 'colors' and 'pairs' to 0x7FFF to accomodate ncurses 5.7 limits
$ /usr/bin/tic -x -o ~/.terminfo xterm-direct.src
# test:
$ /usr/bin/tput -T xterm-direct RGB; echo $?
0
$ /usr/bin/tput -T xterm-direct colors
32767
# without editing the src, the above would be 0

George Nachman

unread,
Mar 22, 2019, 1:06:34 AM3/22/19
to iterm2-...@googlegroups.com
Yeah, terminfo is a bit of a disaster. It has to work on every system you ssh to as well as localhost. The world needs a better way of reporting terminal capabilities. The Terminals Working Group has been trying to hash this out for some time but the way forward is not clear.

dic...@invisible-island.net

unread,
Apr 9, 2019, 8:59:22 PM4/9/19
to iterm2-discuss
On Thursday, March 21, 2019 at 8:03:19 PM UTC-4, John de Largentaye wrote:
(preemptive apologies if this topic has been discussed previously)
(context: iTerm 3.2.7, macOS 10.14 18A390, ncurses 6.1.20180127 via MacPorts)

I've been exploring 24bit color support, and I think there's a couple places reporting could be improved.

ncurses supports reporting 24bit color in terminfo through the ill-documented "RGB" capability since ncurses-6.0-20180121 according to the XVilka [1] gist. I didn't find it mentioned explicitly in the release notes nor can find ncurses revision control (!?), but that version did add xterm-direct (and others) that has this capability.
It looks like you're getting your information second hand (and a lot of the source you cite is putting words in my mouth that I never said):
  •  RGB's mentioned three times in the release notes for ncurses 6.1.  You might want to read them sometime.
  • There's a section in one of the manpages which discusses it.
  • There also are examples of its use in ncurses, e.g., the picsmap program discussed here.
As for MacOS, it bundles a ten-year-old version of ncurses.
If you want any improvements over that, you'll have to upgrade.
MacPorts  is fairly current --looks like it's only a year old.

dic...@invisible-island.net

unread,
Apr 9, 2019, 9:34:57 PM4/9/19
to iterm2-discuss
On Friday, March 22, 2019 at 1:06:34 AM UTC-4, George Nachman wrote:
Yeah, terminfo is a bit of a disaster. It has to work on every system you ssh to as well as localhost. The world needs a better way of reporting terminal capabilities. The Terminals Working Group has been trying to hash this out for some time but the way forward is not clear.

George Nachman

unread,
Apr 10, 2019, 3:32:31 AM4/10/19
to iterm2-...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages