- Notifications
You must be signed in to change notification settings - Fork56
Color standards for terminal emulators
License
termstandard/colors
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
(Previously published and discussed athttps://gist.github.com/XVilka/8346728.)
There exists common confusion about terminal colors. This is what we have right now:
- Plain ASCII without color controls;
- Using ANSI escape sequences:
- 8 colors as a 2×2×2 color-cube, plus bright and dim foreground;
- 16 colors: 8 colors, plus corresponding bright versions;
- 256-color palette: 16 colors, plus a 6×6×6 color-cube and a 24-level gray scale;
- 24-bit TrueColor as a 256×256×256 color-cube (aka "16 million" or just "888")
The 256-color palette has a standardized initial arrangement, but all entriesare separately reprogrammable. Using this mode, a terminal can display any 24-bitRGB colors, the same as TrueColor, but only 256 distinct colors simultaneously.The other modes do not use a palette; they just specify colors directly.
To see if your terminal supports TrueColor, run:
fgbg=48# backgroundfgbg=38# foregroundred=255green=102blue=0printf'\e[%u;2;%u;%u;%um%s\e[m\n'"$fgbg""$red""$green""$blue" TRUECOLOR
which will printTRUECOLOR in brown if itunderstands Xterm-style TrueColor escape sequences.
For a more thorough test, run:
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";}'
Some other tests:
- gist/lilydjwg/colors.py
- https://github.com/robertknight/konsole/tree/master/tests/color-spaces.pl
- https://github.com/JohnMorales/dotfiles/blob/master/colors/24-bit-color.sh
- https://git.gnome.org/browse/vte/tree/perf/img.sh
# make a sandboxmkdir tmp$$cd tmp$$# downloads scriptswget https://github.com/robertknight/konsole/raw/master/tests/color-spaces.pl \ https://gist.github.com/lilydjwg/fdeaf79e921c2f413f44b6f613f6ad53/raw/94d8b2be62657e96488038b0e547e3009ed87d40/colors.py \ https://github.com/JohnMorales/dotfiles/raw/master/colors/24-bit-color.sh \ https://gitlab.gnome.org/GNOME/vte/-/raw/master/perf/img.sh# read the scripts with your editor$EDITOR*
Stop!Only if you're satisfied that the scripts are trustworthy should you proceed:
# if you trust them, run themperl color-spaces.plpython colors.pybash 24-bit-color.shbash img.shKeep in mind that it is possible to use both ';' and ':' as Control Sequencedelimiters.
According to Wikipedia[1], this behavior is only supported by xterm and konsole.
[1]https://en.wikipedia.org/wiki/ANSI_color
VTE,Konsole andiTerm2 all advertisetruecolor support by placingCOLORTERM=truecolor in the environment of theshell user's shell. This has been in VTE for a while, but is relatively new inKonsole 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 sincencurses-6.0-20180121,under the name "RGB".You need to use the "setaf" and "setab" commands to set the foreground andbackground respectively.
Having an extra environment variable (separate fromTERM) is not ideal: bydefault it is not forwarded via sudo, ssh, etc, and so it may still beunreliable even where support is available in programs. (It does however err onthe side of safety: it does not advertise support when it is not actuallysupported, and the programs should fall back to using 8-bit color.)
These issues can be ameliorated by addingCOLORTERM to:
- the
SendEnvlist in/etc/ssh/ssh_configon ssh clients; - the
AcceptEnvlist in/etc/ssh/sshd_configon ssh servers; and - the
env_keeplist 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 desktopexperience where only one variable needs to be set.
App developers can freely choose to check for this variable, or introduce theirown method (e.g. an option in their config file). They should use whichevermethod 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 your shell's start-up file(e.g./etc/profile or~/.profile or~/.bashrc or~/.zshrc) to setCOLORTERM=truecolor when$TERM matches any terminal type known to haveworking truecolor:
case $TERM in iterm |\ vte* |\ *-truecolor ) export COLORTERM=truecolor ;;esacIn an interactive program that can read terminal responses, a more reliablemethod is available that is transparent to sudo & ssh. Simply try sending aTrueColor escape sequence to the terminal, followed by a query to ask whatcolor it currently has. If the response indicates the same color aswas just set, then TrueColor is supported.
If the response indicates an 8-bit color, or does not indicate a color, or ifno response is forthcoming within a few centiseconds, then TrueColor isprobably unsupported.
$ (printf'\e[48:2:1:2:3m\eP$qm\e\\'; xxd -g1 )^[P1$r48:2:1:2:3m^[\00000000: 1b 50 31 24 72 34 38 3a 32 3a 31 3a 32 3a 33 6d .P1$r48:2:1:2:3m
Here we set the background color toRGB(1,2,3) - an unlikely defaultchoice - and request the value that we just set. The response comes back thatthe 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
^[P1$r40m^[\00000000: 1b 50 31 24 72 34 30 6d 1b 5c 0a .P1$r40m.\.This terminal replied that the color is40 - it has not accepted our requestto set48:2:1:2:3.
^[P0$r^[\00000000: 1b 50 30 24 72 1b 5c 0a .P0$r.\.This terminal did not even understand theDECRQSS request - 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 supporttruecolor either.
- alacritty [delimiter: colon, semicolon] - written in Rust
- Black Screen [delimiter: semicolon] - cross-platform, HTML/CSS/JS-based
- cmd.exe [delimiter: semicolon] Built-in Windows shell that is mostly unchanged since DOSWindows 10
- ConEmu [delimiter: semicolon] -Windows platform
- ConHost [delimiter: semicolon] Built-in Windows console (usually hosting cmd.exe) that is mostly unchanged since DOSWindows 10
- ConnectBot -Android platform - since3bcc75ccedaf2136b04c5932c81a5155f29dc3b5 commit.
- Contour [delimiter: semicolon] - written in C++17, uses OpenGL
- cool-retro-term [delimiter: semicolon]
- FinalTerm [delimiter: semicolon] -abandoned, iTerm2borrowing it's ideas and features.
- foot [delimiter: colon, semicolon] - Wayland terminal
- ghostty [delimiter: semicolon] - written in Zig
- hterm - HTML/CSS/JS-based (ChromeOS)
- iTerm2 [delimiter: colon, semicolon] - since v3 version
- kitty [delimiter: colon,semicolon] - uses OpenGL
- konsole [delimiter: colon, semicolon] -https://bugs.kde.org/show_bug.cgi?id=107487
- MacTerm [delimiter: semicolon] -Mac OS X platform
- mintty [delimiter: semicolon]Cygwin and MSYS/MSYS2 since commit43f0ed8a46c6549cb9a3ea27abc057b5abe13bdb (2.0.1 release) -Windows platform
- MobaXtermWindows platform - closed source (run
lscolorsto see a truecolor test) - mosh (Mobile SHell) [delimiter: semicolon] - since commit6cfa4aef598146cfbde7f7a4a83438c3769a2835
- Netsarang XShell - Xshell7/ Xshell6 >= Build 0181 (You must setTools-Options.. -Advanced, check theUse true color* andreopen the software)
- pangoterm [delimiter: colon, semicolon]
- PowerShell Core [delimiter: semicolon] aka PowerShell 6+Windows 10
- Ptyxis [delimiter: semicolon] - supports 8/16/256 colors and 24-bit true color (via VTE; true color since VTE 0.36 ~2014, full in Ptyxis from v45 in 2023) -Linux/GNOME platform - open source (GPL-3.0-or-later); container-focused with GPU acceleration
- PuTTY -landed in git (patched version [3] {approximation to 256 colors} and [4] {real truecolors} available) -Windows platform
- qterminal [delimiter: semicolon] - after version 0.14.1 (issue #78)
- st (from suckless) [delimiter: semicolon] -https://lists.suckless.org/dev/1307/16688.html
- Tera Term [delimiter: colon, semicolon] -Windows platform
- AllTerminalCtrl based terminal emulators.
- Termux [delimiter: semicolon] -Android platform
- Therm [delimiter: colon, semicolon] - fork of iTerm2
- uptermWindows/MacOS/Linux Electron - A terminal emulator for the 21st century.
- Warp -MacOS X platform written in Rust
- wezterm [delimiter: colon, semicolon] - written in Rust
- Windows 10 bash console, sinceWindows Insiders build 14931
- Windows Powershell [delimiter: semicolon] - aka PowerShell 5.x and belowWindows 10
- Windows Terminal [delimiter: semicolon] - official, modern terminal emulator for Windows
- xst - fork of st
- xterm - (from331 (change 330j)
- Alllibvte based terminals (since 0.36 version) [delimiter: colon, semicolon] -https://bugzilla.gnome.org/show_bug.cgi?id=704449
- libvte-basedevilvte - no release yet, version from githttps://github.com/caleb-/evilvte
- libvte-basedGnome Terminal
- libvte-basedguake - A top-down terminal for GNOME
- libvte-basedLilyterm - since commit72536e7ba448ad9ef1126ce45fbde3a3407a271b
- libvte-basedlxterminal - with--enable-gtk3 configure flag.
- libvte-basedPantheon Terminal
- libvte-basedROXTerm
- libvte-basedsakura
- libvte-basedTerminator - since1.90 release
- libvte-basedTermit
- libvte-basedTermite (NOT MAINTAINED)
- libvte-basedTilda
- libvte-basedTilix - written in D. Similar user interface as for Terminator.
- libvte-basedtinyterm
- libvte-basedxfce4-terminal - since0.6.90 release, if compiled with GTK+3
- Allxterm.js based terminals (sincev3.13,v4.3 for webgl) [delimiter: semicolon]
- ZOCWindows/OS X platform - closed source since7.19.0 version
There are a bunch of libvte-based terminals for GTK2, so they are listed in theanother section.
- dvtm - not yet supporting truecolormartanne/dvtm#10
- pymux - tmux clone in pure Python (to enable truecolor run pymux with
--truecoloroption) - screen - has support in 'master' branch, need to be enabled (see 'truecolor' option)
- tmux - starting from version 2.2 (support since427b820...)
These terminal emulators parse ANSI color sequences, but approximate the truecolor using a palette or limit number of true colors that can be used at thesame time. A 256-color (8-bit) palette is used unless specified.
- Linux console (fbcon),since v3.16 -https://bugzilla.kernel.org/show_bug.cgi?id=79551 (downgraded to 16 foregrounds and 8 backgrounds)
- mlterm - built with--with-gtk=3.0 configure flag. Approximates colors using a 512-color embedded palette (https://sourceforge.net/p/mlterm/bugs/74/)
- urxvt aka rxvt-unicode - sincerevision 1.570. Limits maximum number of colors:http://lists.schmorp.de/pipermail/rxvt-unicode/2016q2/002261.html
Human eyes are sensitive to the primary colors in such a way that the simpleGaussian distance √(R²+G²+B²) gives poor results when trying to find the"nearest" available color as perceived by most humans.
TheCIEDE2000formula provides much better perceptual matching, but it is considerably morecomplex and may perform very slowly if used blindly [2].
[2]neovim/neovim#793 (comment)
- aterm (looks abandoned) -https://sourceforge.net/p/aterm/feature-requests/23/
- Cmder: Portable console emulator for Windows, based on ConEmu.
- fbcon (prior to Linux 3.16) -https://bugzilla.kernel.org/show_bug.cgi?id=79551
- frecon - Console that is part of ChromeOS kernel
- FreeBSD console
- Hyper.app [delimiter: semicolon] - cross-platform, HTML/CSS/JS-based (Electron)vercel/hyper#2294
- JuiceSSH -Android platform, closed source
- KiTTY -Windows platform
- mRemoteNG -Windows platform -issue #717
- mrxvt (looks abandoned) -https://sourceforge.net/p/materm/feature-requests/41/
- MTPuTTY -Windows platform
- SmarTTY -Windows platform - closed source (sent them a request)
- Terminal.app: MacOS Terminal built-in
- Terminology (Enlightenment) -https://phab.enlightenment.org/T746
- Terminus: highly configurable terminal emulator for Windows, MacOS and Linux
- Termius -Linux, Windows, OS X platforms, closed source
- yaft framebuffer terminal -issue #12
- libvte and GTK2 - based:
- clifm - The command line file manager
- dte text editor - (sinceversion 1.8)
- elinks -configure.in:1410 (./configure --enable-true-color)
- emacs - since26.1 release
- Eternal Terminal - automatically reconnecting shell
- explosion - terminal image viewer
- irssi - sincePR #48
- joe - (from4.5 version)
- ls-icons - fork of coreutils with
lsprogram that supports icons - mc - since682a5.... See alsoticket #3724 for truecolor themes.
- micro editor
- mpv - video player with support of console-only output (since 0.22 version)
- ncurses library - since 6.1 version
- neovim - since commit8dd415e887923f99ab5daaeba9f0303e173dd1aa; need to settermguicolors to enable truecolor.
- Notcurses library - all releases
- radare2 - reverse engineering framework; since 0.9.6 version.
- rizin - reverse engineering framework; since the inception (a fork of radare2).
- s-lang library - (since pre2.3.1-35, for 64bit systems)
- tcell library for Go language
- termimage - terminal image viewer
- termpaint low level library (C) - all releases
- timg - Terminal Image Viewer
- Tui Widgets library (C++/QtCore) - all releases
- tv - tool to quickly view high-resolution multi-band imagery directly in terminal
- vifm file manager - since 0.12 version
- vim - (from 7.4.1770); need to settermguicolors to enable truecolor.
- cmus (music player) -issue #799
- gui.cs Terminal UI toolkit for .NET (curses-like) -issue #48
- mcabber (jabber client) -issue #126
- mutt (email client) -http://dev.mutt.org/trac/ticket/3674
- neomutt (email client) -issue #58
- scim (spreadsheet program) -issue #306
- termbox library -issue #37 (there is a forktermbox_next with the support
- tig (git TUI) -issue #227
- weechat (chat client) -issue #1364
About
Color standards for terminal emulators
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Releases
Packages0
Uh oh!
There was an error while loading.Please reload this page.