5

Wrote a bash function to display the console colors.

But, it seems some of the colors are not possible to show that way! (?)

Also, note the strange "bright black"!

(Note: The below screendump is of xterm, but this is meant to be used in console mode. I had to use xterm to get a screendump. But it looks much the same.)

clr

function clr () {
  Color_names="bla red gre yel blu mag cya whi"
  Color_arr=($Color_names)
  for m in {0..15}
  do
    tput setaf $m
    echo -n ${Color_arr[$((m % 8))]}" "
  done
  echo
  tput sgr0
  cat /sys/module/vt/parameters/default_red \
      /sys/module/vt/parameters/default_grn \
      /sys/module/vt/parameters/default_blu | tr "," "\t"
}
Glorfindel
  • 805
  • 2
  • 10
  • 19
Emanuel Berg
  • 6,763
  • 7
  • 43
  • 65

3 Answers3

8

If you check tput colors, you'll probably see that the answer is 8. The way to show the bright colors is by tput bold.

This shows all 8x8x2 combinations of foreground and background, normal and bold.

for cmd in sgr0 bold; do
  tput $cmd
  for i in $(seq 0 7); do
    for j in $(seq 0 7); do
      tput setaf $i; tput setab $j; echo -n " $i,$j "
    done
    tput sgr0; echo; tput $cmd
  done
done
angus
  • 12,131
  • 3
  • 44
  • 40
  • 1
    I added `tput reset` because after breaking the lines 1) if the terminal output is scrolled up, the end of lines get filled with the last used color; 2) if the prompt sets no colors (or even if it sets, depending on the terminal) the next command will keep the last used color. I find it very ugly. Maybe `reset` was more than needed, I intended to use it as `\e[0m` equivalent. Update: you are right, should use `tput sgr0` instead. – manatwork Aug 24 '12 at 10:50
  • Awesome stuff! I'll edit the question with your stuff when I've integrated it with my table values. – Emanuel Berg Aug 24 '12 at 19:23
1

See this blog post: http://www.enigmacurry.com/2009/01/20/256-colors-on-the-linux-terminal/

Edit: if you have just 8 color result from tput-color you can use ncurses to solve your weakness! in ubuntu install it:

sudo apt-get install ncurses-term

and add the following line in your ~/.bashrc or ~/bash_profile:

export TERM=xterm-256color

and instead of your script you can use emacs command to see your colors. run emacs in terminal with emacs -nw and type command M-x list-colors-display

doesn't matter witch terminal do you have, this tools will work on all of your terminal emulators ;-)

Shahin
  • 224
  • 2
  • 6
0

There are several terminal descriptions which can be used for the Linux console. The most commonly used one of course is set with TERM=linux.

As an alternative, there is TERM=linux-16color, which does the combinations of bold/color that you can see in @angus' answer.

Comparing linux and linux-16color with infocmp shows this:

comparing linux to linux-16color.
    comparing booleans.
    comparing numbers.
        colors: 8, 16.
        ncv: 18, 63.
        pairs: 64, 256.
    comparing strings.
        setab: '\E[4%p1%dm', '\E[4%p1%{8}%m%d%?%p1%{7}%>%t;5%e;25%;m'.
        setaf: '\E[3%p1%dm', '\E[3%p1%{8}%m%d%?%p1%{7}%>%t;1%e;21%;m'.

The %t;5 and %t;1 pieces use the blink- and bold-attributes (a feature of the display hardware) to get bright background and foreground colors depending on the value fed to tput setab and tput setaf.

Here is a screenshot done using the ncurses test-program with linux-16color:

example of linux-16color

Thomas Dickey
  • 75,040
  • 9
  • 171
  • 268