#!/bin/bash
#
# 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
fim='\e[0m'    # Normal
# 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
bfim='\e[0m'    # Normal
#
#function esp {
esp() {
    local nc=$(echo "${2}" | grep -Fo '\e[' | wc -l) # numero de caracteres da cor da msg
    #
    if [[ $nc <  1 ]]; then
       local tmh_=${#2} # tamanho da msg sem caracteres da cor
    else
       local tmh_=$((${#2} - ($nc * 8))) # tamanho da msg - 'nc' caracteres da cor
    fi
    #
    if [[ $tm = 1 ]]; then
       tmb=$tmah
    elif [[ $tmh_ -gt $tmb  ]]; then
         tmb=$(($tmh_ + 2)) # se tamanho da msg for maior que 'tmb' faz 'tmb' igual a msg + 2
         tmah=$tmb
         tm=1
    fi
    #
    declare -g msi${1}_spaces=$(printf "%*s" $((($tmb - $tmh_)/2))"") # espacos antes da msg
    declare -g msf${1}_spaces=$(printf "%*s" $(($tmb - ($tmh_ + ($tmb - $tmh_)/2)))"") # espacos depois da msg
}
#
#function msg {
msg() {
    local tmb=80
    #
    local ct1="\u2554" # superior esquerda
    local ct2="\u2557" # superior direita
    local cb1="\u255A" # inferior esquerda
    local cb2="\u255D" # inferior direita
    local cc1="\u2560" # meio esquerda
    local cc2="\u2563" # meio direita
    local cd1="\u2550" # linha
    local cd2="\u2551" # reta
    #
    if [[ "${2}${3}${4}${5}${6}" == "1" ]]; then
       local ct1=$cc1
       local ct2=$cc2
    fi
    #
    if [[ "${2}${3}${4}${5}${6}" == "2" ]]; then
       local cb1=$ct1
       local cb2=$ct2
    fi
    #
    if [[ "${2}${3}${4}${5}${6}" == "3" ]]; then
       local ct1=$cc1
       local ct2=$cc2
       local cb1=$cc1
       local cb2=$cc2
    fi
    #
    if [[ "${2}${3}${4}${5}${6}" == "4" ]]; then
       local ct1=$cc1
       local ct2=$cc2
    fi
    #
       esp 1 $1
    #
    if [[ -n $2 ]]; then
       esp 2 $2
    fi
    #
    if [[ -n $3 ]]; then
       esp 3 $3
    fi
    #
    if [[ -n $4 ]]; then
       esp 4 $4
    fi
    #
    if [[ -n $5 ]]; then
       esp 5 $5
    fi
    #
    local repetect="${bved}${ct1}$(printf "%.0s${cd1}" $(seq $tmb))${ct2}${bfim}"
    #
    local repetecb="${bved}${cb1}$(printf "%.0s${cd1}" $(seq $tmb))${cb2}${bfim}"
    #
    if [[ $2 != 1 && $3 != 1 && $4 != 1 && $5 != 1 && $6 != 1 ]]; then
       echo -e ${repetect}
    fi
    #
       echo -e "${bved}${cd2}${msi1_spaces}${1}${msf1_spaces}${bved}${cd2}"
    #
    if [[ -n $2 && $2 != 1 && $2 != 2 && $2 != 3 && $2 != 4 ]]; then
       echo -e "${bved}${cd2}${msi2_spaces}${2}${msf2_spaces}${bved}${cd2}"
    fi
    #
    if [[ -n $3 && $3 != 1 && $3 != 2 && $3 != 3 && $3 != 4 ]]; then
       echo -e "${bved}${cd2}${msi3_spaces}${3}${msf3_spaces}${bved}${cd2}"
    fi
    #
    if [[ -n $4 && $4 != 1 && $4 != 2 && $4 != 3 && $4 != 4 ]]; then
       echo -e "${bved}${cd2}${msi4_spaces}${4}${msf4_spaces}${bved}${cd2}"
    fi
    #
    if [[ -n $5 && $5 != 1 && $5 != 2 && $5 != 3 && $5 != 4 ]]; then
       echo -e "${bved}${cd2}${msi5_spaces}${5}${msf5_spaces}${bved}${cd2}"
    fi
    #
    if [[ $2 != 2 && $3 != 2 && $4 != 2 && $5 != 2 && $6 != 2 ]]; then
       echo -e ${repetecb}
    fi
    #
}
#
