#! /usr/bin/zsh -feu

source /usr/share/mmc-shell/mmc-functions.sh

if [[ $# -lt 1 ]]; then
    die "missing argument: a color name"
fi

COLOR=$1

hash_support=1

if [ $hash_support = 1 ]
then
declare -A _COLORS
_COLORS[reset]='\e[00m'
_COLORS[black]='\e[30m'
_COLORS[red]='\e[31m'
_COLORS[yellow]='\e[32m'
_COLORS[green]='\e[33m'
_COLORS[hiyellow]='\033[1;32m'
_COLORS[blue]='\e[34m'
_COLORS[hiblue]='\033[1;34m'
#hiblue=$blue
_COLORS[magenta]='\e[35m'
_COLORS[cyan]='\e[36m'
_COLORS[white]='\e[37m'
_COLORS[bold]='\033[1m'
else
declare -a _COLORS
_COLORS=(
"reset:\e[00m"
"black:\e[30;47m"
"red:\e[31;47m"
"green:\e[32;47m"
"yellow:\e[33;47m"
"hiyellow:\033[1;32m"
"blue:\e[34;47m"
"hiblue:\033[1;34m"
#hiblue=$blue
"magenta:\e[35;47m"
"cyan:\e[36;47m"
"white:\e[37;47m"
"bold:\033[1m"
   );
fi


emit_color()
{
    if [ $hash_support = 1 ]
    then
        echo -n -e "${_COLORS[$COLOR]}"
    else
        for info in ${_COLORS[@]} ; do
            KEY=${info%%:*}
            VALUE=${info##*:}
            if [ $KEY = $1 ]
            then
                echo -n -e "$VALUE"
            fi
        done
    fi
}



if [ -t 0 -o -S /dev/stdin ]; then
    if [ "${TERM}" = "xterm" \
        -o "${TERM}" = "screen" \
        -o "${TERM}" = "xterm-256color" \
        -o "${TERM}" = "rxvt" \
        -o "${TERM}" = "ansi" ]; then
        emit_color $COLOR
#	echo $@
#	tput sgr0
        # echo
    else
        :
#	echo $@
    fi
else
    :
    #echo $@
fi
