2 ##############################################################################
3 # Copyright 2020 Thomas E. Dickey #
4 # Copyright 2016 Free Software Foundation, Inc. #
6 # Permission is hereby granted, free of charge, to any person obtaining a #
7 # copy of this software and associated documentation files (the "Software"), #
8 # to deal in the Software without restriction, including without limitation #
9 # the rights to use, copy, modify, merge, publish, distribute, distribute #
10 # with modifications, sublicense, and/or sell copies of the Software, and to #
11 # permit persons to whom the Software is furnished to do so, subject to the #
12 # following conditions: #
14 # The above copyright notice and this permission notice shall be included in #
15 # all copies or substantial portions of the Software. #
17 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR #
18 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, #
19 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL #
20 # THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER #
21 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING #
22 # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER #
23 # DEALINGS IN THE SOFTWARE. #
25 # Except as contained in this notice, the name(s) of the above copyright #
26 # holders shall not be used in advertising or otherwise to promote the sale, #
27 # use or other dealings in this Software without prior written #
29 ##############################################################################
30 # $Id: tput-colorcube,v 1.2 2020/02/02 23:34:34 tom Exp $
31 # Use this script to print an xterm-style color cube, e.g., as done in
32 # the xterm 88colors2.pl and 256colors2.pl scripts.
51 failed "expected one parameter or none"
54 colors=$(tput -T $myterm colors 2>/dev/null)
55 if [ ${colors:-0} -le 0 ]
57 myterm=${myterm%%-color}
58 colors=$(tput -T $myterm colors 2>/dev/null)
60 if [ ${colors:-0} -le 0 ]
62 failed "terminal $myterm does not support color"
65 printf "System colors:\n"
70 [ $colors -gt 256 ] && colors=256
71 [ $inrow -gt 8 ] && inrow=8
72 [ $to_do -gt 16 ] && to_do=16
73 while [ $color -lt $to_do ]
75 [ $color = $inrow ] && newline
78 color=$(expr $color + 1)
82 [ $colors -le 16 ] && exit
88 elif [ $colors -ge 88 ]
97 printf "Color cube, ${cube}x${cube}x${cube}:\n"
99 cube2=$(expr $cube \* $cube)
100 while [ $g -lt $cube ]
103 while [ $r -lt $cube ]
106 while [ $b -lt $cube ]
108 color=$(expr 16 + \( $r \* $cube2 \) + \( $g \* $cube \) + $b)
122 printf "Grayscale ramp:\n"
124 while [ $color -lt $colors ]
128 color=$(expr $color + 1)