#!/bin/sh usage () { cat <&2 Usage: ${0##*/} QUERY Perform one of the terminal QUERIES: idx: Print color indices. lines: Print 256 colored lines. list: List color support for all terminals. prop: Print the properties of the current terminal. EOF } [ $# -eq 0 ] && usage && exit 1 [ "$1" = "-h" ] && usage && exit [ "$1" = "--" ] && shift idx () { # The test text. Must be 3 letters. local T T='Doh' printf "\n 40m 41m 42m 43m\ 44m 45m 46m 47m\n"; for FG in m 1m 30m '1;30m' 31m '1;31m' 32m '1;32m' 33m '1;33m' 34m '1;34m' \ 35m '1;35m' 36m '1;36m' 37m '1;37m' ; do FGs=$(printf '%5s' "$FG") echo -en " $FGs \033[$FG $T " for BG in 40m 41m 42m 43m 44m 45m 46m 47m; do echo -en "$EINS \033[$FG\033[$BG $T \033[0m"; done echo done echo } lines () { local op line index op=$(tput op) line=$(printf '%76s' | sed 's/ /=/g') for i in {0..256}; do index=$(printf '%03d' $i) echo -e "$index $(tput setaf $i;tput setab $i)$line$op" done } list () { for T in $(find "/usr/share/terminfo" -type f -printf '%f\n'); do echo "$T $(tput -T $T colors)" done | sort -nk2 } prop () { infocmp -1 | sed -nu 's/^[ \000\t]*//;s/[ \000\t]*$//;/[^ \t\000]\{1,\}/!d;/acsc/d;s/=.*,//p'| column -c80 } case "$1" in idx) idx ;; lines) lines ;; list) list ;; prop) prop ;; *) usage;; esac