#!/usr/bin/env bash
######################################################################
#Copyright (C) 2026 Kris Occhipinti
#http://filmsbykris.com 

#This program is free software: you can redistribute it and/or modify
#it under the terms of the GNU General Public License as published by
#the Free Software Foundation version 3 of the License.

#This program is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#GNU General Public License for more details.

#You should have received a copy of the GNU General Public License
#along with this program.  If not, see <http://www.gnu.org/licenses/>.
######################################################################

[[ $1 ]] && MESSAGE="$1" || return
COLUMNS=$(tput cols)

#Default is red background with white text
COLOR="\e[41;37;1m"

[[ $2 ]] && color="${2^^}"
[[ "$color" == "BLUE" ]] && COLOR="\e[44;37;1m"
[[ "$color" == "GREEN" ]] && COLOR="\e[42;30;1m"
[[ "$color" == "GREY" ]] || [[ "$color" == "GRAY" ]] && COLOR="\e[47;30;1m"

NC="\e[0m"

#calc padding
padding_length=$(((COLUMNS - ${#MESSAGE}) / 2))
printf -v centered_line "%*s%s%*s" "$padding_length" "" "$MESSAGE" "$padding_length" ""

# if width is odd add an extra space to center it
[ ${#centered_line} -lt $COLUMNS ] && centered_line="${centered_line} "
echo -e "${COLOR}${centered_line}${NC}"

