4

TLDR: What is the theory behind terminal colors?

I have a fixed value of LS_COLORS in numbers: no=00:fi=00:di=01;34:ln=00;36:pi=40;33:so=00;35:bd=40;33;01:cd=40;33;01:or=01;05;37;41:mi=01;05;37;41:ex=00;33:*.cmd=00;33:*.exe=00;33:*.com=00;33:*.btm=00;33:*.bat=00;33:*.sh=00;33:*.csh=00;33:*.tar=00;31:*.tgz=00;31:*.arj=00;31:*.taz=00;31:*.lzh=00;31:*.zip=00;31:*.z=00;31:*.Z=00;31:*.gz=00;31:*.bz2=00;31:*.bz=00;31:*.tz=00;31:*.rpm=00;31:*.cpio=00;31:*.jpg=00;35:*.gif=00;35:*.bmp=00;35:*.xbm=00;35:*.xpm=00;35:*.png=00;35:*.tif=00;35:*.c=00;41:*.cpp=00;41:*.h=00;44:*.cu=00;43:*.cuh=00;43:ex=00;32

I wonder what causes gnome-terminal, urxvt and yakuake to show perceptibly different colors for the same file type? The difference ranges from very similar (and yet clearly different) to drastically different- brown vs yellow.

Similarly, there are differences in how vim color shows up, I see very different colors in all three terminals. Both when t_Co=8 (vim supporting 8 colors) and t_Co=256(vim supporting 256 colors).

What's worse is that when I copy .XResources from internet which has english names for colors, the same colorscheme in vim shows much different colors. (I think I can attribute this to the use of names in vimscheme, and color redefintion by .Xresources)

Could someone help me with understanding the theory behind how terminal color works? A link would work great. If someone's feeling extra generous- maybe they can give tips too to ensure that I always have a standard environment, specially in the context of vim?

I should note that on yakuake, my color theme is: "Linux theme" (which seems to be only standard theme) and on gnome-terminal I have no theme. When I check the 'user system colors' option, the colors are even more disastrous, and the output itself is mangled (e.g. vanilla ls showing each file on a different line). For urxvt, the only color related fields I have defined in .Xresources and xrdb -q yields are:

Urxvt.background: #000000 
Urxvt.foreground: #FFFFFF

Ok so some screenshots to explain what I'm talking about (first is on yakuake, second on urxvt)

On yakuake On urxvt The difference is clearly major...

Using: http://www.vim.org/scripts/script.php?script_id=1349 (first is yakuake, second on urxvt)

enter image description here enter image description here

5

The indexed color palette has the actual rendering open to interpretation - on actual hardware, there were different standards (especially brown vs. dark yellow, brown is more useful and nicer to look at).

Just check out this: https://en.wikipedia.org/wiki/Color_Graphics_Adapter

On terminal emulators, it depends on the configuration. Most emulators have a mode defined (echo $TERM), singifying which old-school hardware it is emulating. The color is the least of the changes - other control codes (invisible character strings that control the cursor position, bold/invert video, blinking and whatever) can have different codes too. That's the garbage you sometimes get, when you press cursors when the terminal type is incorrectly set (over ssh, for instance). Some more sophisticated emulators actually don't care about the ancient color standards and let you define your own colors (Konsole - which Yakuake uses - has color profiles). Modern terminal emulators actually support more colors than that (256), but of course, the application running in the terminal has to recognize this capability (through termcap or something, or by reading $TERM variable), and output the correct character combinations to use them.

What you actually want to read is this, there is even a color table: https://en.wikipedia.org/wiki/ANSI_escape_code

  • Thanks. I have $TERM set to xterm for all the emulators, you mean konsole is ignoring $TERM? – 0fnt Jun 12 '15 at 12:20
  • 1
    Not ignoring it, it is the other way around. The terminal sets the $TERM variable, so that the applications know how to communicate with it, and so it knows what the terminal can do. Most of the modern terminals are compatible with almost everything, and you can change the $TERM variable to change how applications deal with the terminal, as long as the terminal emulator can still understand the "dialect". Most of the terminal emulators nowadays just set TERM=xterm, including Konsole (by default). urxvt uses rxvt-unicode but some apps behave better if you change to xterm. – orion Jun 12 '15 at 14:09
  • 1
    Using slightly different shades of color is not a violation. For instance, "dark yellow" can be shown in different ways - some emulators choose to emulate old hardware (setting it to half-brightness pure yellow, or to dark orange), while others take a more modern approach and choose a color scheme, more pleasant to the eye. The difference is also in the interpretation "bright color/dark color" versus "bold font in color/regular font in color" - again, it can be either one of the old-school hardware styles, or an arbitrary "skin". – orion Jun 12 '15 at 14:13
  • 1
    It looks to me that the foreground (font colors) are almost the same. Only the inverted background is messed up. I'm not sure how to understand this... but it still seems these are 256 color terminals (or you have a very clownish color scheme). You can try just export TERM=xterm and run vi again, see if it changes. My guess is, vi is too smart and selects its color scheme based on the terminal capabilities. But it could just be that both emulators set the inverted video colors differently (possibly, one actually inverts the color while the other just colors the background?). – orion Jun 12 '15 at 15:31
  • 1
    Excellent. I thought it must be something strange with the terminal. No idea why only 88 colors by default, though :) – orion Jun 12 '15 at 15:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.