]> ncurses.scripts.mit.edu Git - ncurses.git/blob - test/tput-colorcube
ncurses 6.0 - patch 20180120
[ncurses.git] / test / tput-colorcube
1 #!/bin/sh
2 ##############################################################################
3 # Copyright (c) 2016 Free Software Foundation, Inc.                          #
4 #                                                                            #
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:                                                      #
12 #                                                                            #
13 # The above copyright notice and this permission notice shall be included in #
14 # all copies or substantial portions of the Software.                        #
15 #                                                                            #
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.                                                  #
23 #                                                                            #
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               #
27 # authorization.                                                             #
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.
32
33 failed() {
34         printf "?? $*\n" >&2
35         exit 1
36 }
37
38 newline() {
39         tput op
40         printf "\n"
41 }
42
43 if [ $# = 1 ]
44 then
45         myterm=$1
46 elif [ $# = 0 ]
47 then
48         myterm=$TERM
49 else
50         failed "expected one parameter or none"
51 fi
52
53 colors=$(tput -T $myterm colors 2>/dev/null)
54 if [ ${colors:-0} -le 0 ]
55 then
56         myterm=${myterm%%-color}
57         colors=$(tput -T $myterm colors 2>/dev/null)
58 fi
59 if [ ${colors:-0} -le 0 ]
60 then
61         failed "terminal $myterm does not support color"
62 fi
63
64 printf "System colors:\n"
65
66 color=0
67 inrow=$colors
68 to_do=$colors
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 ]
73 do
74         [ $color = $inrow ] && newline
75         tput setab $color
76         printf '  '
77         color=$(expr $color + 1)
78 done
79 newline
80
81 [ $colors -le 16 ] && exit
82
83 if [ $colors = 256 ]
84 then
85         cube=6
86         ramp=232
87 elif [ $colors -ge 88 ]
88 then
89         cube=4
90         ramp=80
91 else
92         exit
93 fi
94
95 printf "\n"
96 printf "Color cube, ${cube}x${cube}x${cube}:\n"
97 g=0
98 cube2=$(expr $cube \* $cube)
99 while [ $g -lt $cube ]
100 do
101         r=0
102         while [ $r -lt $cube ]
103         do
104                 b=0
105                 while [ $b -lt $cube ]
106                 do
107                         color=$(expr 16 + \( $r \* $cube2 \) + \( $g \* $cube \) + $b)
108                         tput setab $color
109                         printf '  '
110                         b=$(expr $b + 1)
111                 done
112                 tput op
113                 printf ' '
114                 r=$(expr $r + 1)
115         done
116         newline
117         g=$(expr $g + 1)
118 done
119
120 printf "\n"
121 printf "Grayscale ramp:\n"
122 color=$ramp
123 while [ $color -lt $colors ]
124 do
125         tput setab $color
126         printf '  '
127         color=$(expr $color + 1)
128 done
129 newline
130 # vi:ts=4 sw=4