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-initc,v 1.5 2016/12/17 22:35:05 tom Exp $
30 # Some of the ".dat" files in ncurses' test-directory give r/g/b numbers for
31 # default palettes of xterm and Linux console. This script reads the numbers
32 # and (assuming the same or compatible terminal) uses tput to (re)initialize
33 # the palette using those numbers.
42 usage: $0 [-r] [-s] [palette-data]
44 Use this script with a palette data-file to (re)initialize colors with
45 tput. This script assumes arrangements for 16-, 88- and 256-colors
46 like the xterm 88colors2.pl and 256colors2.pl scripts.
50 -s reverse system colors (first 16 if more than 16 colors)
58 while getopts "rs" option "$@"
72 shift $(expr $OPTIND - 1)
81 failed "expected one parameter or none"
90 failed "no such file: $file"
95 colors=$(tput -T $myterm colors 2>/dev/null)
96 if [ ${colors:-0} -le 0 ]
98 myterm=${myterm%%-color}
99 colors=$(tput -T $myterm colors 2>/dev/null)
101 if [ ${colors:-0} -le 0 ]
103 failed "terminal $myterm does not support color"
107 awk -v opt_r=$opt_r \
115 if ( colors == 88 ) {
117 } else if ( colors = 256 ) {
122 return (n * 1000)/limit;
126 sub("^scale:","",$0);
136 params[$1] = sprintf ("%d %d %d", scaled($2),scaled($3),scaled($4));
139 for (n = 0; n <= range; ++n) {
141 if ( opt_r == "yes" ) {
142 if ( colors <= 16 ) {
144 } else if ( ( opt_s == "yes" ) && ( n < 16 ) ) {
146 } else if ( n >= cramp ) {
147 m = cramp + colors - 1 - n;
149 m = 16 + cramp - 1 - n;
152 printf "tput -T%s initc %d %s\n", myterm, m, params[n];