Linux – How to Print Console Colors

colorsconsolelinuxtputtty

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"
}

Best Answer

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
Related Question