Taskwarrior would greatly benefit from allowing color themes with more than just 256 colors. Currently, most of the terminal emulators on all common platforms support this feature, and many programs like Vim use it.
All up-to-date information is available here: https://github.com/termstandard/colors
It can be tested with the following command:
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 "truecolor" 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 directly.
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
delimiters.
According to Wikipedia[1], this behavior is only supported by xterm and konsole.
[1] https://en.wikipedia.org/wiki/ANSI_color
Truecolor Detection
Checking for COLORTERM
VTE,
Konsole and
iTerm2 all advertise
truecolor support by placing COLORTERM=truecolor in the environment of the
shell user's shell. This has been in VTE for a while, but is relatively new in
Konsole and iTerm2 and has to be enabled at compile time (most packages do not,
so you have to compile them yourself from the git source repo).
The S-Lang library has a check that $COLORTERM contains either "truecolor" or
"24bit" (case sensitive).
Terminfo has supported the 24-bit TrueColor capability since
ncurses-6.0-20180121,
under the name "RGB".
You need to use the "setaf" and "setab" commands to set the foreground and
background respectively.
Having an extra environment variable (separate from TERM) is not ideal: by
default it is not forwarded via sudo, ssh, etc, and so it may still be
unreliable even where support is available in programs. (It does however err on
the side of safety: it does not advertise support when it is not actually
supported, and the programs should fall back to using 8-bit color.)
These issues can be ameliorated by adding COLORTERM to:
- the
SendEnv list in /etc/ssh/ssh_config on ssh clients;
- the
AcceptEnv list in /etc/ssh/sshd_config on ssh servers; and
- the
env_keep list in /etc/sudoers.
Despite these problems, it's currently the best option, so checking
$COLORTERM is recommended since it will lead to a more seamless desktop
experience where only one variable needs to be set.
App developers can freely choose to check for this 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.
Ideally any terminal that really supports truecolor would set this variable;
but as a work-around you might need to put a check in /etc/profile to set
COLORTERM=truecolor when $TERM matches any terminal type known to have
working truecolor.
case $TERM in
iterm |\
linux-truecolor |\
screen-truecolor |\
tmux-truecolor |\
xterm-truecolor ) export COLORTERM=truecolor ;;
vte*)
esac
Querying The Terminal
In an interactive program that can read terminal responses, a more reliable
method is available, that is transparent to sudo & ssh.
Simply try sending a truecolor value to the terminal, followed by a query to
ask what color it currently has. If the response indicates the same color as
was just set, then truecolor is supported.
If the response indicates an 8-bit color, or does not indicate a color, or if
no response is forthcoming within a few centiseconds, then assume that
truecolor is not 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 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 that 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
CSI+0$r. This does not indicate whether it set the color, but since it
doesn't understand how to reply to our request it is unlikely to support
truecolor either.
Truecolor Support in Output Devices
Fully Supporting
Terminal Emulators
- xterm - (from
331 (change 330j)
- st (from suckless) [delimiter: semicolon] -
https://lists.suckless.org/dev/1307/16688.html
- xst - fork of st
- konsole [delimiter: colon,
semicolon] - https://bugs.kde.org/show_bug.cgi?id=107487
- iTerm2 [delimiter: colon, semicolon] - since v3
version
- Therm [delimiter: colon, semicolon] - fork
of iTerm2
- qterminal [delimiter: semicolon] - after version 0.14.1 (issue #78)
- alacritty [delimiter: semicolon] -
written in Rust
- Contour [delimiter: semicolon] - written in C++17, uses OpenGL
- kitty [delimiter: colon,semicolon] -
uses OpenGL
- foot [delimiter: colon, semicolon] -
Wayland terminal
- cool-retro-term [delimiter:
semicolon]
- mosh (Mobile SHell) [delimiter: semicolon] - since commit 6cfa4aef598146cfbde7f7a4a83438c3769a2835
- pangoterm [delimiter:
colon, semicolon]
- Termux [delimiter: semicolon] - Android platform
- ConnectBot - Android platform - since 3bcc75ccedaf2136b04c5932c81a5155f29dc3b5 commit.
- Black Screen [delimiter:
semicolon] - cross-platform, HTML/CSS/JS-based
- hterm -
HTML/CSS/JS-based (ChromeOS)
- PuTTY -
landed
in git (patched version [3] {approximation to 256 colors} and [4]
{real truecolors} available) - Windows platform
- Tera Term [delimiter: colon,
semicolon] - Windows platform
- ConEmu [delimiter: semicolon] -
Windows platform
- Windows
Powershell
[delimiter: semicolon] - aka PowerShell 5.x and below Windows 10
- PowerShell Core [delimiter:
semicolon] aka PowerShell 6+ Windows 10
- cmd.exe [delimiter:
semicolon] Built-in Windows shell that is mostly unchanged since DOS Windows 10
- FinalTerm [delimiter: semicolon] -
abandoned, iTerm2
borrowing it's ideas and features.
- MacTerm [delimiter: semicolon] - Mac
OS X platform
- mintty [delimiter: semicolon] Cygwin and
MSYS/MSYS2 since commit 43f0ed8a46c6549cb9a3ea27abc057b5abe13bdb
(2.0.1 release) - Windows platform
- wezterm [delimeter: colon] - written in Rust
- MobaXterm Windows platform - closed
source (run lscolors to see a truecolor test)
- ZOC Windows/OS X platform - closed
source since
7.19.0 version
- upterm Windows/MacOS/Linux Electron -
A terminal emulator for the 21st century.
- Windows 10 bash console, since
Windows Insiders build 14931
- All libvte based terminals
(since 0.36 version) [delimiter: colon, semicolon] -
https://bugzilla.gnome.org/show_bug.cgi?id=704449
- All xterm.js based terminals (since v3.13, v4.3 for webgl) [delimiter: semicolon]
- VS Code's integrated terminal
- Tabby: highly configurable terminal emulator for Windows, macOS and Linux
- Hyper.app: crossplatform, HTML/CSS/JS-based (Electron)
- Netsarang XShell -
Xshell7/ Xshell6 >= Build 0181
(You must set Tools-Options.. -Advanced, check the Use true color* and reopen the software)
There are a bunch of libvte-based terminals for GTK2, so they are listed in the
another section.
Multiplexers
Re-players
Partial Support
These terminal emulators parse ANSI color sequences, but approximate the true
color using a palette or limit number of true colors that can be used at the
same time. A 256-color (8-bit) palette is used unless specified.
Note about color differences
Human eyes are sensitive to the primary colors in such a way that the simple
Gaussian distance √(R²+G²+B²) gives poor results when trying to find the
"nearest" available color as perceived by most humans.
The CIEDE2000
formula provides much better perceptual matching, but it is considerably more
complex and may perform very slowly if used blindly [2].
[2] neovim/neovim#793 (comment)
Not Supporting Truecolor
Console Programs + Truecolor
Console Programs Supporting Truecolor
Console Programs Not Supporting Truecolor
Taskwarrior would greatly benefit from allowing color themes with more than just 256 colors. Currently, most of the terminal emulators on all common platforms support this feature, and many programs like Vim use it.
All up-to-date information is available here: https://github.com/termstandard/colors
It can be tested with the following command:
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 "truecolor" 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 directly.
This is a good test case:
https://github.com/@raw/JohnMorales/dotfiles/master/colors/24-bit-color.sh
Keep in mind that it is possible to use both ';' and ':' as Control Sequence
delimiters.
According to Wikipedia[1], this behavior is only supported by xterm and konsole.
[1] https://en.wikipedia.org/wiki/ANSI_color
Truecolor Detection
Checking for COLORTERM
VTE,
Konsole and
iTerm2 all advertise
truecolor support by placing
COLORTERM=truecolorin the environment of theshell user's shell. This has been in VTE for a while, but is relatively new in
Konsole and iTerm2 and has to be enabled at compile time (most packages do not,
so you have to compile them yourself from the git source repo).
The S-Lang library has a check that
$COLORTERMcontains either "truecolor" or"24bit" (case sensitive).
Terminfo has supported the 24-bit TrueColor capability since
ncurses-6.0-20180121,
under the name "RGB".
You need to use the "setaf" and "setab" commands to set the foreground and
background respectively.
Having an extra environment variable (separate from
TERM) is not ideal: bydefault it is not forwarded via sudo, ssh, etc, and so it may still be
unreliable even where support is available in programs. (It does however err on
the side of safety: it does not advertise support when it is not actually
supported, and the programs should fall back to using 8-bit color.)
These issues can be ameliorated by adding
COLORTERMto:SendEnvlist in/etc/ssh/ssh_configon ssh clients;AcceptEnvlist in/etc/ssh/sshd_configon ssh servers; andenv_keeplist in/etc/sudoers.Despite these problems, it's currently the best option, so checking
$COLORTERMis recommended since it will lead to a more seamless desktopexperience where only one variable needs to be set.
App developers can freely choose to check for this 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.
Ideally any terminal that really supports truecolor would set this variable;
but as a work-around you might need to put a check in
/etc/profileto setCOLORTERM=truecolorwhen$TERMmatches any terminal type known to haveworking truecolor.
Querying The Terminal
In an interactive program that can read terminal responses, a more reliable
method is available, that is transparent to sudo & ssh.
Simply try sending a truecolor value to the terminal, followed by a query to
ask what color it currently has. If the response indicates the same color as
was just set, then truecolor is supported.
If the response indicates an 8-bit color, or does not indicate a color, or if
no response is forthcoming within a few centiseconds, then assume that
truecolor is not supported.
Here we set the background color to
RGB(1,2,3)- an unlikely defaultchoice - and request the value that we just set. The response comes back that
the request was understood (
1), and that the color is indeed48: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
This terminal replied that the color is
40- it has not accepted our requestto set
48:2:1:2:3.This terminal did not even understand the
DECRQSSrequest - its response wasCSI+0$r. This does not indicate whether it set the color, but since itdoesn't understand how to reply to our request it is unlikely to support
truecolor either.
Truecolor Support in Output Devices
Fully Supporting
Terminal Emulators
331 (change 330j)
https://lists.suckless.org/dev/1307/16688.html
semicolon] - https://bugs.kde.org/show_bug.cgi?id=107487
version
of iTerm2
written in Rust
uses OpenGL
Wayland terminal
semicolon]
colon, semicolon]
semicolon] - cross-platform, HTML/CSS/JS-based
HTML/CSS/JS-based (ChromeOS)
landed
in git (patched version [3] {approximation to 256 colors} and [4]
{real truecolors} available) - Windows platform
semicolon] - Windows platform
Windows platform
Powershell
[delimiter: semicolon] - aka PowerShell 5.x and below Windows 10
semicolon] aka PowerShell 6+ Windows 10
semicolon] Built-in Windows shell that is mostly unchanged since DOS Windows 10
abandoned, iTerm2
borrowing it's ideas and features.
OS X platform
MSYS/MSYS2 since commit 43f0ed8a46c6549cb9a3ea27abc057b5abe13bdb
(2.0.1 release) - Windows platform
source (run
lscolorsto see a truecolor test)source since
7.19.0 version
A terminal emulator for the 21st century.
Windows Insiders build 14931
(since 0.36 version) [delimiter: colon, semicolon] -
https://bugzilla.gnome.org/show_bug.cgi?id=704449
Gnome Terminal
xfce4-terminal - since
0.6.90
release, if compiled with GTK+3
Terminator -
since 1.90 release
Similar user interface as for Terminator.
version from git https://github.com/caleb-/evilvte
Pantheon Terminal
--enable-gtk3 configure flag.
Xshell7/ Xshell6 >= Build 0181
(You must set Tools-Options.. -Advanced, check the Use true color* and reopen the software)
There are a bunch of libvte-based terminals for GTK2, so they are listed in the
another section.
Multiplexers
427b820...)
'master' branch, need to be enabled (see 'truecolor' option)
(to enable truecolor run pymux with
--truecoloroption)Add support for true color martanne/dvtm#10
Re-players
https://github.com/asciinema/asciinema-player
Partial Support
These terminal emulators parse ANSI color sequences, but approximate the true
color using a palette or limit number of true colors that can be used at the
same time. A 256-color (8-bit) palette is used unless specified.
configure flag. Approximates colors using a 512-color embedded palette
(https://sourceforge.net/p/mlterm/bugs/74/)
since
revision 1.570.
Limits maximum number of colors:
http://lists.schmorp.de/pipermail/rxvt-unicode/2016q2/002261.html
Note about color differences
Human eyes are sensitive to the primary colors in such a way that the simple
Gaussian distance √(R²+G²+B²) gives poor results when trying to find the
"nearest" available color as perceived by most humans.
The CIEDE2000
formula provides much better perceptual matching, but it is considerably more
complex and may perform very slowly if used blindly [2].
[2] neovim/neovim#793 (comment)
Not Supporting Truecolor
(Enlightenment) - https://phab.enlightenment.org/T746
HTML/CSS/JS-based (Electron) [V2] Color degredations vercel/hyper#2294
based on ConEmu.
highly configurable terminal emulator for Windows, MacOS and Linux
https://sourceforge.net/p/materm/feature-requests/41/
https://sourceforge.net/p/aterm/feature-requests/23/
Linux 3.16) - https://bugzilla.kernel.org/show_bug.cgi?id=79551
closed source
(sent them a request)
Console Programs + Truecolor
Console Programs Supporting Truecolor
library - (since pre2.3.1-35, for 64bit systems)
reconnecting shell
682a5....
See also ticket #3724 for
truecolor themes.
PR #48
8dd415e887923f99ab5daaeba9f0303e173dd1aa;
need to set
termguicolors to
enable truecolor.
termguicolors
to enable truecolor.
4.5
version)
26.1 release
version 1.8)
configure.in:1410
(./configure --enable-true-color)
multi-band imagery directly in terminal
viewer
lsprogram that supports iconsconsole-only output (since 0.22 version)
since 0.9.6 version.
Console Programs Not Supporting Truecolor