Skip to content

Instantly share code, notes, and snippets.

@XVilka
Last active March 6, 2026 10:14
Show Gist options
  • Select an option

  • Save XVilka/8346728 to your computer and use it in GitHub Desktop.

Select an option

Save XVilka/8346728 to your computer and use it in GitHub Desktop.
True Colour (16 million colours) support in various terminal applications and terminals

Terminal Colors

There exists common confusion about terminal colors. This is what we have right now:

  • Plain ASCII
  • ANSI escape codes: 16 color codes with bold/italic and background
  • 256 color palette: 216 colors + 16 ANSI + 24 gray (colors are 24-bit)
  • 24-bit true color: "888" colors (aka 16 milion)
printf "\x1b[${bg};2;${red};${green};${blue}m\n"

The 256-color palette is configured at start and is a 666-cube of colors, each of them defined as a 24-bit (888 rgb) color.

This means that current support can only display 256 different colors in the terminal while "true color" means that you can display 16 million different colors at the same time.

Truecolor escape codes do not use a color palette. They just specify the color itself.

This is a good test case:

printf "\x1b[38;2;255;100;0mTRUECOLOR\x1b[0m\n"
awk 'BEGIN{
    s="/\\/\\/\\/\\/\\"; s=s s s s s s s s;
    for (colnum = 0; colnum<77; colnum++) {
        r = 255-(colnum*255/76);
        g = (colnum*510/76);
        b = (colnum*255/76);
        if (g>255) g = 510-g;
        printf "\033[48;2;%d;%d;%dm", r,g,b;
        printf "\033[38;2;%d;%d;%dm", 255-r,255-g,255-b;
        printf "%s\033[0m", substr(s,colnum+1,1);
    }
    printf "\n";
}'

Keep in mind that it is possible to use both ';' and ':' as Control Sequence Introducer delimiters.

According to Wikipedia[1], this behavior is only supported by xterm and konsole.

[1] https://en.wikipedia.org/wiki/ANSI_color

Since ncurses-6.0-20180121, terminfo began to support the 24-bit True Color capability under the name of "RGB". You need to use the "setaf" and "setab" commands to set the foreground and background respectively.

True Color Detection

There will be no reliable way to detect the "RGB" flag until the new release of terminfo/ncurses. S-Lang author added a check for $COLORTERM containing either "truecolor" or "24bit" (case sensitive). In addition, VTE, Konsole and iTerm2 set this variable to "truecolor". It has been in VTE for a while and but is relatively new, being still git-only in Konsole and iTerm2).

This is obviously not a reliable method, and is not forwarded via sudo, SSH etc. However, whenever it errs, it errs on the safe side. It does not advertise support when it is actually supported. App developers can freely choose to check for this same variable, or introduce their own method (e.g. an option in their config file). They should use whichever method best matches the overall design of their app. Checking $COLORTERM is recommended though since it will lead to a more seamless desktop experience where only one variable needs to be set. This would be system-wide so that the user would not need to set it separately for each app.

Querying The Terminal

A more reliable method in an interactive program which can read terminal responses, and one that is transparent to things like sudo, SSH, etc.. is to simply try setting a truecolor value and then query the terminal to ask what color it currently has. If the response replies the same color that was set then it indicates truecolor is supported.

$ (echo -e '\e[48:2:1:2:3m\eP$qm\e\\' ; xxd)

^[P1$r48:2:1:2:3m^[\
00000000: 1b50 3124 7234 383a 323a 313a 323a 336d  .P1$r48:2:1:2:3m

Here we ask to set the background color to RGB(1,2,3) - an unlikely default choice - and request the value that we just set. The response comes back that the request was understood (1), and that the color is indeed 48:2:1:2:3. This tells us also that the terminal supports the colon delimiter. If instead, the terminal did not support truecolor we might see a response like

^[P1$r40m^[\
00000000: 1b50 3124 7234 306d 1b5c 0a              .P1$r40m.\.

This terminal replied the color is 40 - it has not accepted our request to set 48:2:1:2:3.

^[P0$r^[\
00000000: 1b50 3024 721b 5c0a                      .P0$r.\.

This terminal did not even understand the DECRQSS request - its response was 0$r. We do not learn if it managed to set the color, but since it doesn't understand how to reply to our request it is unlikely to support truecolor either.

Terminals + True Color

Now Supporting True Color

There are a bunch of libvte-based terminals for GTK2, so they are listed in the another section.

Also, while this one is not a terminal, but a terminal replayer, it is still worth mentioning:

Improper Support for True Color

Terminals that parse ANSI color sequences, but approximate them to 256 palette

Note about color differences: a) RGB axes are not orthogonal, so you cannot use sqrt(R^2+G^2+B^2) formula b) for color differences there is more correct (but much more complex) CIEDE2000 formula (which may easily blow up performance if used blindly) [2].

[2] neovim/neovim#793 (comment)

Terminal multiplexers

  • tmux - starting from version 2.2 (support since 427b820...)
  • screen - has support in 'master' branch, need to be enabled (see 'truecolor' option)
  • pymux - tmux clone in pure Python (to enable truecolor run pymux with --truecolor option)
  • dvtm - not yet supporting True Color martanne/dvtm#10

NOT Supporting True Color

Console Programs + True Color

Console Programs Supporting True Color

Console Programs Not Supporting True Color

@DaVince
Copy link

DaVince commented Jul 21, 2020

Aw damn, thanks for the information though!

@arlusf
Copy link

arlusf commented Aug 13, 2020

screen is about to have truecolor/direct color support, preview like this:
gnu screen 4.99 master (screen 5.xxx has not been released yet)
compile with bool truecolor=1 instead of 0
~/.screenrc truecolor on (did not find where truecolor is set in code at this point)
TERM=xterm-256color
COLORTERM=24bit

blink, overline and undercurl did not work as applied with test in khamer's comment above. (bash)
screencap

awk rainbow test works with dash and bash.

@laanwj
Copy link

laanwj commented Sep 24, 2020

I think weston-terminal does not support true color.

It still doesn't in version 8.0.0 that was released this year, unfortunately. Worse, it doesn't parse and ignore \e[38;2;<R>;<G>;<B>m sequences (or map them to the allowed color space like Linux terminal does) but sees everything after 2 as a new SGR parameter.

Code here: https://github.com/wayland-project/weston/blob/master/clients/terminal.c#L1581

@lllisteu
Copy link

IOS terminal apps that support true color:

  • Secure ShellFish (my favourite)
  • Blink Shell

IOS terminal apps that do NOT support true color:

  • Prompt (a.k.a. "Prompt 2")

@mintty
Copy link

mintty commented Nov 14, 2020

mintty: delimiter semicolon or colon; also supporting CMY and CMYK colour models

@Egyptorium
Copy link

Egyptorium commented Nov 16, 2020

Right now have been tested on KDE Plasma's Konsole, and it supports true color.
konsole_truecolor

@xmine64
Copy link

xmine64 commented Nov 26, 2020

cmd.exe, Windows PowerShell, and PowerShell Core are using same Console. These apps are just shells, the actual console window is conhost.exe.

@Kr1ss-XD
Copy link

Thank you very much for sharing this @XVilka, it's really helpful ! 👍

Would you consider adding delta (a syntax-highlighting diff-viewer/-formatter) to the list of apps supporting 24bit colors ?

@Delta456
Copy link

I would to add mine in this list too.

@kurahaupo
Copy link

A small nit: please remove the word Introducer from the following:

… it is possible to use both ';' and ':' as Control Sequence Introducer delimiters

A Control Sequence Introducer is just the initial 1B 5B or 9B bytes of a whole Control Sequence. It is the latter which may contain delimiters.

(Hide this comment once that's done.)

@kurahaupo
Copy link

kurahaupo commented Mar 9, 2021

Another nit: "delimiter" is related to "limit" rather than "meter", and is spelled accordingly. (This seems to have started with commit 507d2c2.)

Or just pull the changes from my repo clone of this gist.

You might also like to pull patches from the forks by CaninoDev, JohnMorales, and tizee.

(Although there doesn't seem to be a way to do this using the gist web interface, it's certainly possible using a local git repo on your own machine: you can pull from multiple gists as "remotes", and you can push to your own gist with changes merged from someone else's gist. See the instructions for cloning a gist as a repo for details.)

(As before, hide this comment once that's done.)

@jasikpark
Copy link

Edex-UI seems to support TrueColor - oculd it be added to the list of supported terminals?
https://github.com/GitSquared/edex-ui
image
It's kinda a joke terminal emulator, but it's still managed to do it

@anpavlov
Copy link

anpavlov commented Jul 28, 2021

urxvt Debian users may want to manually downgrade rxvt-unicode to 9.22-5 as it contains 24bit color patch. It was reverted in next version as it caused bugs as mentioned in 9.22-6 changelog. So use it with caution:

rxvt-unicode (9.22-6) unstable; urgency=medium

  • Revert the 24bit colour patch. Though no issues seem to arise when using
    the default resource values, it seems to cause many issues if changes are
    made to resources related to colour.
    (Closes: #922268, #922289, #922297, #922298, #922299)

-- Ryan Kavanagh rak@debian.org Thu, 14 Feb 2019 12:00:54 -0500

@kurahaupo
Copy link

@anpavlov The original patch to rxvt was pretty buggy:

  • It crashes when run as urxvt -pe tabbed
  • It doesn't cope with the terminal being in reverse video mode (it hides the cursor)
  • It introduces several other cosmetic defects

The first item on its own is a good enough reason to revert the patch. Clearly there needs to be more work done before it's ready for inclusion in a large-scale distribution.

@kurahaupo
Copy link

It seems this gist has become moribund, as @XVilka has neither commented nor applied any patches since October 2019.

It's become big enough that it really ought to be an actual project that accepts pull requests and has a bug tracker.

To that end, I suggest any further follow-up occur at https://github.com/kurahaupo/about-terminals/commits/kurahaupo/TrueColour.md

I'm happy to grant push access as required, especially to XVilka if they return.

@XVilka
Copy link
Author

XVilka commented Jul 30, 2021

@kurahaupo: I made repo some time ago - feel free to send PRs, issues, etc https://github.com/termstandard/colors

@kurahaupo
Copy link

kurahaupo commented Jul 30, 2021

@XVilka Great, I'm glad not to have to maintain my own.

(And this also explains why things have been so quiet here.)

People will keep coming here because this gist has 2200 stars and 147 forks - twenty times more links than your repo - so search results are naturally going to rank it higher than your repo.

I searched for the URL you just posted and can now see that it's referenced in the top line "Most updated version is always available", which is great, but it's very easy to miss or ignore: at first glance it just looks like the kind of link that's on every GitHub.io website, that simply points back that the very page you're already reading; it's not obvious that it's pointing at a different repo without carefully reading the URL. (Indeed it's so unobvious that I went ahead and made my own repo, thinking that none existed.)

This gist also hundreds of comments, so it's not easy to find the other links to your repo either.

To make sure that people do actually go to your new repo, instead of commenting here, I suggest starting with something like:

THIS GIST IS OBSOLETE

See termstandard/colors instead.

And to make it even more obvious, remove all the other content.

@XVilka
Copy link
Author

XVilka commented Sep 30, 2021

I updated the repository, thanks for the @kurahaupo's PR, also syncronized this gist with the repository, and added the link.

@clort81
Copy link

clort81 commented Oct 23, 2021

xterm no-longer approximates truecolor rgb to a palette, afaict.

@mintty
Copy link

mintty commented Feb 23, 2022

About Querying the Terminal: the response should actually look like ...;48:2::1:2:3m - note the double colon which allows a position for the optional color space value.

@wendajiang
Copy link

I want to know why MacOS built-in terminal not support true color?

@JoshMerlino
Copy link

echo -ne \e[1;3;4:3;5;53;38;2;255;127;0;58;2;0;48;255;48;2;255;0;{0..255..8}mX \e[0m\n

windows terminal was not a fan of this one
image

@kurahaupo
Copy link

kurahaupo commented Mar 15, 2022

@khamer @JoshMerlino what is the 4:3 supposed to do in the middle of that escape sequence, before the 38 and 48 "extended" colour codes?

@kurahaupo
Copy link

@mintty @wendajiang @JoshMerlino - please note that this gist is no longer maintained. Please add your comments to the standardterm repo instead.

@XVilka - this is why I suggested that the entire content of this gist should be deleted except for the link to the repo. It would also help to mark all the comments as "hidden".

@coolmian
Copy link

coolmian commented May 11, 2022

After my confirmation. Xshell6/7 support truecolor. But you must set "Tools-Options..-Advanced" check the "Use true color*"

@kurahaupo
Copy link

@coolmian would you mind please adding your notes as an issue on the standardterm repo ? (Preferably create a PR with a fix.)

@kurahaupo
Copy link

kurahaupo commented May 11, 2022

Reminder to future readers who want to make a comment but didn't notice the warning at the top of this page.

It's now a full-blown git repo so please write your comments there, or clone the repo and suggest changes via a Pull Request:

git clone git+ssh://github.com/termstandard/colors truecolor

THIS GIST HAS MOVED
so any comments made here will be ignored!

@XVilka
Copy link
Author

XVilka commented May 11, 2022

@kurahaupo yes, should have made this a long time ago. Now it's done.

@coolmian
Copy link

@coolmian would you mind please adding your notes as an issue on the standardterm repo ? (Preferably create a PR with a fix.)

OK, I've done it now

@kurahaupo
Copy link

Just repeating this so that it's visible at the bottom of this conversation; please don't reply - the whole point is that this should be the last comment, to make it plainly visible when someone is about to hit "reply".

Reminder to future readers who want to make a comment but didn't notice the warning at the top of this page.

It's now a full-blown git repo so please write your comments there, or clone the repo and suggest changes via a Pull Request:

git clone git+ssh://github.com/termstandard/colors truecolor

THIS GIST HAS MOVED
so any comments made here will be ignored!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment