X-Git-Url: http://ncurses.scripts.mit.edu/?p=ncurses.git;a=blobdiff_plain;f=test%2Ftput-initc;h=9d71c4f6187561c6db3c5bc04ed571527bf208a8;hp=3382ee5ad818ea479a4c51cd85c7566fa45c3667;hb=04d942c3d98cf0a929c6afb17be8c10d4ae39af0;hpb=1b540608eae9a714c0c4195310f25c1a1897ae89 diff --git a/test/tput-initc b/test/tput-initc old mode 100644 new mode 100755 index 3382ee5a..9d71c4f6 --- a/test/tput-initc +++ b/test/tput-initc @@ -1,6 +1,7 @@ #!/bin/sh ############################################################################## -# Copyright (c) 2016 Free Software Foundation, Inc. # +# Copyright 2020 Thomas E. Dickey # +# Copyright 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"), # @@ -26,7 +27,7 @@ # use or other dealings in this Software without prior written # # authorization. # ############################################################################## -# $Id: tput-initc,v 1.1 2016/12/10 23:35:46 tom Exp $ +# $Id: tput-initc,v 1.6 2020/02/02 23:34:34 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 @@ -37,6 +38,40 @@ failed() { 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 @@ -70,8 +105,20 @@ then fi cat $file |\ -awk -v myterm=$myterm ' -BEGIN { limit=1000; } +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; } @@ -83,5 +130,27 @@ function scaled(n) { /^[0-9]+:/{ sub(":","",$1); - printf "tput -T%s initc %d %d %d %d\n", myterm, $1,scaled($2),scaled($3),scaled($4); -}' |sh - + 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 -