From 84ae97f865cfc08351972de33b457840f011c067 Mon Sep 17 00:00:00 2001 From: Peter Oliver Date: Sun, 5 Apr 2026 00:24:33 +0100 Subject: [PATCH] Use expected escape sequence for terminfo Tc and COLORTERM=truecolor MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When the non-standard terminfo capability Tc is present, or the environment variable COLORTERM is set to truecolor, use a hard-coded escape sequence that addresses all colors directly by their RGB values. Previously we used escape sequences cribbed from terminfo's setaf/setab for direct color, that expect that we will only try to use colors 000000 to 000007 for the first eight indexed colors. This isn't something we currently handle. * doc/misc/efaq.texi (Colors on a TTY): Fix off-by-one error in list of indexed colors for terminfo RGB terminals. * src/term.c (init_tty): Don’t use any indexed colors with terminfo Tc capability or COLORTERM=truecolor environment variable (bug#70941). --- doc/misc/efaq.texi | 2 +- src/term.c | 16 +++++++++++----- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/doc/misc/efaq.texi b/doc/misc/efaq.texi index 7502d8d551c..13dc2b70431 100644 --- a/doc/misc/efaq.texi +++ b/doc/misc/efaq.texi @@ -1973,7 +1973,7 @@ If Terminfo database is not available, but 24-bit direct color mode is supported, it can still be enabled by defining the environment variable @env{COLORTERM} to @samp{truecolor}. -Terminals with @samp{RGB} capability treat pixels #000001 - #000007 as +Terminals with @samp{RGB} capability treat pixels #000000 - #000007 as indexed colors to maintain backward compatibility with applications that are unaware of direct color mode. Therefore the seven darkest blue shades may not be available. If this is a problem, you can diff --git a/src/term.c b/src/term.c index 766eeebe5e8..091b900db93 100644 --- a/src/term.c +++ b/src/term.c @@ -4605,16 +4605,22 @@ use the Bourne shell command 'TERM=...; export TERM' (C-shell:\n\ signed values, tgetnum("Co") and tigetnum("colors") could return 32767. */ tty->TN_max_colors = 16777216; + + /* FIXME: When the RGB terminfo capability is given, we + should avoid trying to use colors 000000 to 000007 as if + they were RGB values. The escape sequences given by + setaf and setab treat them as the first eight indexed + ANSI colors. */ } - /* Fall back to xterm+direct (semicolon version) if Tc is set - (de-facto standard introduced by tmux) or if requested by - the COLORTERM environment variable. */ + /* Fall back to direct colour by RGB value (semicolon version) + if Tc is set (de-facto standard introduced by tmux) or if + requested by the COLORTERM environment variable. */ else if ((tigetflag ("Tc") > 0) || ((bg = getenv ("COLORTERM")) != NULL && strcasecmp (bg, "truecolor") == 0)) { - tty->TS_set_foreground = "\033[%?%p1%{8}%<%t3%p1%d%e38;2;%p1%{65536}%/%d;%p1%{256}%/%{255}%&%d;%p1%{255}%&%d%;m"; - tty->TS_set_background = "\033[%?%p1%{8}%<%t4%p1%d%e48;2;%p1%{65536}%/%d;%p1%{256}%/%{255}%&%d;%p1%{255}%&%d%;m"; + tty->TS_set_foreground = "\033[38;2;%p1%{65536}%/%d;%p1%{256}%/%{255}%&%d;%p1%{255}%&%d%;m"; + tty->TS_set_background = "\033[48;2;%p1%{65536}%/%d;%p1%{256}%/%{255}%&%d;%p1%{255}%&%d%;m"; tty->TN_max_colors = 16777216; } }