/usr/lib/ncurses/examples/tput-initc is in ncurses-examples 6.1-1ubuntu1.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 | #!/bin/sh
##############################################################################
# Copyright (c) 2016 Free Software Foundation, Inc. #
# #
# Permission is hereby granted, free of charge, to any person obtaining a #
# copy of this software and associated documentation files (the "Software"), #
# to deal in the Software without restriction, including without limitation #
# the rights to use, copy, modify, merge, publish, distribute, distribute #
# with modifications, sublicense, and/or sell copies of the Software, and to #
# permit persons to whom the Software is furnished to do so, subject to the #
# following conditions: #
# #
# The above copyright notice and this permission notice shall be included in #
# all copies or substantial portions of the Software. #
# #
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR #
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, #
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL #
# THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER #
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING #
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER #
# DEALINGS IN THE SOFTWARE. #
# #
# Except as contained in this notice, the name(s) of the above copyright #
# holders shall not be used in advertising or otherwise to promote the sale, #
# use or other dealings in this Software without prior written #
# authorization. #
##############################################################################
# $Id: tput-initc,v 1.5 2016/12/17 22:35:05 tom Exp $
# Some of the ".dat" files in ncurses' test-directory give r/g/b numbers for
# default palettes of xterm and Linux console. This script reads the numbers
# and (assuming the same or compatible terminal) uses tput to (re)initialize
# the palette using those numbers.
failed() {
printf "?? $*\n" >&2
exit 1
}
usage() {
cat >&2 <<-EOF
usage: $0 [-r] [-s] [palette-data]
Use this script with a palette data-file to (re)initialize colors with
tput. This script assumes arrangements for 16-, 88- and 256-colors
like the xterm 88colors2.pl and 256colors2.pl scripts.
Options:
-r reverse palette
-s reverse system colors (first 16 if more than 16 colors)
EOF
exit 1
}
opt_r=no
opt_s=no
while getopts "rs" option "$@"
do
case $option in
(r)
opt_r=yes
;;
(s)
opt_s=yes
;;
(*)
usage
;;
esac
done
shift $(expr $OPTIND - 1)
if [ $# = 1 ]
then
file=$1
elif [ $# = 0 ]
then
file=$TERM.dat
else
failed "expected one parameter or none"
fi
if [ ! -f "$file" ]
then
if [ -f "$file.dat" ]
then
file="$file.dat"
else
failed "no such file: $file"
fi
fi
myterm=${file%%.dat}
colors=$(tput -T $myterm colors 2>/dev/null)
if [ ${colors:-0} -le 0 ]
then
myterm=${myterm%%-color}
colors=$(tput -T $myterm colors 2>/dev/null)
fi
if [ ${colors:-0} -le 0 ]
then
failed "terminal $myterm does not support color"
fi
cat $file |\
awk -v opt_r=$opt_r \
-v opt_s=$opt_s \
-v colors=$colors \
-v myterm=$myterm '
BEGIN {
limit = 1000;
range = -1;
cramp = -1;
if ( colors == 88 ) {
cramp = 80;
} else if ( colors = 256 ) {
cramp = 232;
}
}
function scaled(n) {
return (n * 1000)/limit;
}
/^scale:[0-9]+/{
sub("^scale:","",$0);
limit = $0;
}
/^[0-9]+:/{
sub(":","",$1);
item = $1 + 0;
if (range < item) {
range = item;
}
params[$1] = sprintf ("%d %d %d", scaled($2),scaled($3),scaled($4));
}
END {
for (n = 0; n <= range; ++n) {
m = n;
if ( opt_r == "yes" ) {
if ( colors <= 16 ) {
m = range - n;
} else if ( ( opt_s == "yes" ) && ( n < 16 ) ) {
m = 15 - n;
} else if ( n >= cramp ) {
m = cramp + colors - 1 - n;
} else {
m = 16 + cramp - 1 - n;
}
}
printf "tput -T%s initc %d %s\n", myterm, m, params[n];
}
}
' |sh -
|