I'm trying to understand exactly how colors are processed in my terminal emulator (iTerm2).
In iTerm2 I can configure my "base 16" color palette - in iTerm2 this is done using HSL, not 16-bit RGB values. The colors defined this way are native - they use the cocoa API and are not limited to the typical 256 color palette (they are rendered in true color).
X11'srgb.txt defines names for the colors in the 256 color palette.
In a shell, bash or zsh, I can print text using the 16bit 256 color palette with echo -e "\e[38;5;82mHello \e[38;5;198mWorld"
(the third parameter is the xterm color code)
In vim (terminal not gui) the colors are utilized as a 'cterm' value when defining highlights (for example: :highlight Normal ctermfg=188 ctermbg=233 guifg=#e8e8d3 guibg=#151515
), however as far as I can tell - there is no way to define a terminal color using an RGB code, so while I can display the base16 colors in truecolor, the rest of the colors are arbitrarily limited to the 256 color palette.
What I haven't been able to figure out is where rgb values are mapped to the xterm codes. It appears to be an arbitrary relationship (the xterm codes don't appear to have a functional relationship with the RGB values), so I assume there must be a mapping somewhere.
I believe that the colors can be redefined in .Xresources (here is an example), but I'm unsure about a couple things:
So at this point I believe way it works is:
So, no other applications (X11 or anything else) are involved in the color mapping or conversion - it's straight from the terminal application to the terminal emulator.
This being the case, since iTerm2 only allows user to configure the "base 16 colors" users are free to use true color when rendering those only, but restricted to the web-safe palette for all other colors.
Is this correct?
The default xterm palette is standard and expected to be the same in every xterm implementation. It is different from the more or less standard rgb.txt that is only used by GUI programs.
The first 16 colors, 0-15, have more or less standard names, "red", "darkgreen", etc. but all the others can only be referred to by their number, from 16 to 255.
The first 16 colors can usually be defined by the user (using CMYK, HSL, RGB or hexadecimal notation, it doesn't matter) so using "red" or "2" in a colorscheme is pretty much a shot in the dark as there's no guarantee whatsoever that "red" will actually be red. Solarized is an horrible example where the color traditionally referred to as "bright green" is actually a dark grey.
Most "modern" terminal emulators let you define those 16 colors with a GUI but other more "old school" emulators like xterm or rxvt use ~/.Xresources
. That file is completely ignored by iTerm so you shouldn't waste your time on it.
It is possible to change the xterm palette but few people know about that which makes this practice very uncommon.
So…
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With