#!/bin/sh
#-------------------------------------------------------------------------------
# tput-test.sh                                   (C) 2007 T.Birnthaler OSTC GmbH
# tput-Attribute, Vorder- und -Hintergrundfarben ausprobieren.
# $Id: tput-test.sh,v 1.5 2008/09/16 14:41:10 tsbirn Exp $
#-------------------------------------------------------------------------------
# Vorder und Hintergrundfarbe (nicht) vertauschen
XCHG=""
B="B"
F="F"

# Liste der Attribute für die Tabellen erzeugt werden sollen
# (auch als Argument übergebbar)
ATTLIST="sgr0 blink bold rev smso"
ATTLIST="sgr0 bold x rev x rev smso"
ATTLIST="sgr0 bold rev smso"
ATTLIST="sgr0 x rev x bold"
ATTLIST="sgr0 bold"
[ $# -gt 0 ] && ATTLIST="$@"

# Pro Attribute eine Tabelle erzeugen
for ATT in $ATTLIST
do
	# Vorder- und Hintergrundfarbe vertauschen?
	if [ "$ATT" = "x" ]
	then
		[ -z "$XCHG" ] && XCHG="x" && B="F" && F="B" && continue
		[ -n "$XCHG" ] && XCHG=""  && B="B" && F="F" && continue
	fi

	# Attribut-Einstellungen ausgeben
	echo
	echo "          tput $ATT; tput setaf Bn; tput setab Fn"

	# Titelzeile der Hintergrundfarben (background) 
	echo -n "$(tput sgr0)"
	echo -n "   "
	for BG in 0 1 2 3 4 5 6 7 8 9
	do
		echo -n "  $B$BG  "
	done
	echo

	# Pro Vordergrundfarbe eine Zeile 
	for FG in 0 1 2 3 4 5 6 7 8 9
	do
		# Titelspalte der Vordergrundfarben (foreground)
		echo -n "$F$FG "
		
		# Pro Hintergrundfarbe eine Spalte 
		for BG in 0 1 2 3 4 5 6 7 8 9
		do
			echo -n "$(tput $ATT)"
			if [ -z "$XCHG" ]
			then
				echo -n "$(tput setab $BG)"
				echo -n "$(tput setaf $FG)"
			else
				echo -n "$(tput setab $FG)"
				echo -n "$(tput setaf $BG)"
			fi
			echo -n " Text "
			echo -n "$(tput sgr0)"
		done
		echo
	done
done

