Introduction
My question arises from the necessity of understanding why I have now (after multiple trials) Terminal and tmux supporting 256 colours and tput colors
telling me there are only 8 of them.
Background
Let's start from the beginning.
I'm using a Ubuntu box, Guake, tmux, Vim and I love the theme Solarized. They were looking pretty awful, so I decided to enable the 256 colours support and play a bit around.
Let's see what happens for my Terminal. tput colors
says there are 8 colours. I personally set them to purple, on the left, and of course on the right we have 2 different shades of blue. $TERM
says xterm
. (To have the coloured ls
I eval
this in my .bashrc
.)
Vim also looks fine, despite the fact that I call it with the 256
flag in an environment where 256 colours are not supported.
set t_Co=256
let g:solarized_termcolors=256
colorscheme solarized
The only guy who complains about the reduced colour space is tmux. Calling tmux
provides the "wrong" expected results.
But calling tmux
with the -2
flag makes everything work fine, magically.
Now the only thing that I understand is that -2
is equivalent of export TERM=screen-256color
(source).
Guake behaves analogously to Terminal and both of them answer xterm
to the question echo $TERM
.
Question
Basically, does anyone understand why everything works even if it shouldn't?
- Am I sadistic that I complaining why things work? Maybe.
- Is there a better reason? Sure: I'd like to fix the appearance of other Ubuntu boxes in my office, and I'd like to understand why things work or don't work.
Additional experiments
Running this script (slightly modified) on my xterm
provides the following result: 256 colours, but only 16 are displayed correctly.
Then, changing terminal's profile, also these 16 colours change.
More tests are following.
From left to right, top to bottom, we have Solarized colour theme, dircolor
ansi-dark
and 256dark
, then default (Tango) colour scheme, dircolor
ansi-dark
and 256dark
.
Observation: in theory the dircolor
ansi-dark
on Solarized colour scheme should have match closely the dircolor
256dark
. This is not clearly happening for the specific listed files. Instead, this quite happens when in the working directory there are folders, text files and symbolic links. Conclusion: no much attention as been paid while encoding the 256dark
colours.
Preliminary conclusions
xterm
supports 256 colours, despite what tput colors
says. Programs can refer to the ansi
palette (customisable by the user) or define their colours, picking from a total of 256 colours.
tput colors
is an unreliable test. Could you check my preliminary conclusions?tput colors
can only return one value and in terminals that support any of 2,8,16,88 or 256 colors, only the first value (8 in your case) is returned. To get the true value use the script from my last comment. What does that return?