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-initc,v 1.6 2020/02/02 23:34:34 tom Exp $
31 # Some of the ".dat" files in ncurses' test-directory give r/g/b numbers for
32 # default palettes of xterm and Linux console. This script reads the numbers
33 # and (assuming the same or compatible terminal) uses tput to (re)initialize
34 # the palette using those numbers.
43 usage: $0 [-r] [-s] [palette-data]
45 Use this script with a palette data-file to (re)initialize colors with
46 tput. This script assumes arrangements for 16-, 88- and 256-colors
47 like the xterm 88colors2.pl and 256colors2.pl scripts.
51 -s reverse system colors (first 16 if more than 16 colors)
59 while getopts "rs" option "$@"
73 shift $(expr $OPTIND - 1)
82 failed "expected one parameter or none"
91 failed "no such file: $file"
96 colors=$(tput -T $myterm colors 2>/dev/null)
97 if [ ${colors:-0} -le 0 ]
99 myterm=${myterm%%-color}
100 colors=$(tput -T $myterm colors 2>/dev/null)
102 if [ ${colors:-0} -le 0 ]
104 failed "terminal $myterm does not support color"
108 awk -v opt_r=$opt_r \
116 if ( colors == 88 ) {
118 } else if ( colors = 256 ) {
123 return (n * 1000)/limit;
127 sub("^scale:","",$0);
137 params[$1] = sprintf ("%d %d %d", scaled($2),scaled($3),scaled($4));
140 for (n = 0; n <= range; ++n) {
142 if ( opt_r == "yes" ) {
143 if ( colors <= 16 ) {
145 } else if ( ( opt_s == "yes" ) && ( n < 16 ) ) {
147 } else if ( n >= cramp ) {
148 m = cramp + colors - 1 - n;
150 m = 16 + cramp - 1 - n;
153 printf "tput -T%s initc %d %s\n", myterm, m, params[n];