#!/bin/bash
#
# Regular Colors
preto='\e[0;30m'    # Black
vermelho='\e[0;31m' # Red
verde='\e[0;32m'    # Green
amarelo='\e[0;33m'  # Yellow
azul='\e[0;34m'     # Blue
purpura='\e[0;35m'  # Purple
ciano='\e[0;36m'    # Cyan
branco='\e[0;37m'   # White
cfim='\e[0m'
# Bold
bpreto='\e[1;30m'    # Black
bvermelho='\e[1;31m' # Red
bverde='\e[1;32m'    # Green
bamarelo='\e[1;33m'  # Yellow
bazul='\e[1;34m'     # Blue
bpurpura='\e[1;35m'  # Purple
bciano='\e[1;36m'    # Cyan
bbranco='\e[1;37m'   # White
#
# Regular Colors
prt='\e[0;30m' # Black
ver='\e[0;31m' # Red
ved='\e[0;32m' # Green
ama='\e[0;33m' # Yellow
azu='\e[0;34m' # Blue
pur='\e[0;35m' # Purple
cia='\e[0;36m' # Cyan
bra='\e[0;37m' # White
cfi='\e[0m'
# Bold
bpre='\e[1;30m' # Black
bver='\e[1;31m' # Red
bved='\e[1;32m' # Green
bama='\e[1;33m' # Yellow
bazu='\e[1;34m' # Blue
bpur='\e[1;35m' # Purple
bcia='\e[1;36m' # Cyan
bbra='\e[1;37m' # White
#
# CBold
cbpre='\e[1;30m' # Black
cbver='\e[1;31m' # Red
cbved='\e[1;32m' # Green
cbama='\e[1;33m' # Yellow
cbazu='\e[1;34m' # Blue
cbpur='\e[1;35m' # Purple
cbcia='\e[1;36m' # Cyan
cbbra='\e[1;37m' # White
#
function msg {
    tmb=80
    msg1=$1
#
#    nc=$(echo "$msg1" | tr '[1' '\n' | sort | uniq -cd)
#    if ! [ $nc > "1" ]; then
#         nc=1
#    fi
#    tmh1=$((${#msg1} - ($nc * 8)+2)) # tamanho da msg -'nc' caracteres da cor + 2 '#'
#
    tmh1=$((${#msg1} - $2)) # tamanho da msg -'n' caracteres da cor + 2 '#'
    #
    if [[ $tm = 1 ]]; then
       tmb=$tmah
       tm=0
    elif [[ $tmh1 -gt $tmb  ]]; then
          tmb=$(($tmh1 + 2))
          tmah=$tmb
          tm=1
    fi
    #
    msi1_spaces=$(printf "%*s" $((($tmb - $tmh1)/2)) "") # espacos antes da msg
    msf1_spaces=$(printf "%*s" $(($tmb - ($tmh1 + ($tmb - $tmh1)/2)))"") # espacos depois da msg
    repetec=$bverde"$(printf '%.0s#' $(seq $tmb))"$cfim
    #
    if [[ -n $4 ]]; then
       msg2=$3
       tmh2=$((${#msg2} - $4))
       msi2_spaces=$(printf "%*s" $((($tmb - $tmh2)/2)) "")
       msf2_spaces=$(printf "%*s" $(($tmb - ($tmh2 + ($tmb - $tmh2)/2)))"")
    fi
    #
    if [[ $3 != 1 ]]; then # se a variavel $3 não tiver 1 mostra o #
       if [[ $5 != 1 ]]; then # se a variavel $5 não tiver 1 mostra o #
          echo -e $repetec
       fi
    fi
    #
    echo -e $bverde"#$msi1_spaces$bamarelo$msg1$msf1_spaces$bverde#"
    #
    if [[ -n $4 ]]; then
       echo -e $bverde"#$msi2_spaces$bamarelo$msg2$msf2_spaces$bverde#"
    fi
    echo -e $repetec
}
#
