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