+showit() {
+ local col="${PREFIX}[${1};${2}m"
+ printf '%bthis color is: %s %b\n' "${col}" "${col}" "${PREFIX}[0m"
+}
+
+main() {
+ if [[ $1 == "--posix" ]] ; then
+ PREFIX=${POSIX_PREFIX}
+ shift
+ fi
+ case $1 in
+ --env)
+ show_env
+ ;;
+ ""|16|system)
+ for i in {0..1} ; do
+ for j in {30..37} ; do
+ showit ${i} ${j}
+ done
+ done
+ ;;
+ cube|6x6x6)
+ check256
+ for n in {16..231} ; do
+ showit "38;05" $(printf '%03i' ${n})
+ done
+ ;;
+ gr[ae]y)
+ check256
+ for n in {232..255} ; do
+ showit "38;05" ${n}
+ done
+ ;;
+ all|256)
+ for x in system cube gray ; do
+ echo "### SET: ${x}"
+ "$0" ${x}
+ done
+ ;;
+ ncurses|curses|mutt|nano)
+ colors=(
+ black
+ red
+ green
+ yellow
+ blue
+ magenta
+ cyan
+ white
+ )
+ norm=$(tput sgr0)
+ bold=$(tput bold)
+ blackfg=$(tput setaf 0)
+ for seta in "af" "ab" ; do
+ [[ ${seta} == "af" ]] && ground=fore || ground=back
+ for pfx in "" "bright" ; do
+ for (( i = 0; i < ${#colors[@]}; ++i )) ; do
+ [[ ${pfx} == "bright" ]] && printf "${bold}"
+ [[ ${seta} == "ab" ]] && printf "${blackfg}"
+ echo "$(tput set${seta} ${i})this is ${ground}ground color '${pfx}${colors[i]}'${norm}"
+ done
+ done
+ done
+ ;;
+ *)
+ cat <<-EOF
+ usage: $0 [--posix] [colors]
+
+ Colors:
+ - --env - show env you can eval in a shell
+ - 16, system - show basic colors (default)
+ - cube, 6x6x6 - show most extended colors
+ - gray - show gray scale
+ - all, 256 - show all colors
+ - curses - show ncurses color names (used by mutt, nano, etc...)
+ EOF
+ exit 1
+ ;;
+ esac
+}
+main "$@"