#!/usr/bin/env bash
#
# System-Tools
# Copyright (C) 2002-2025 by Thomas Dreibholz
#
# 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, either version 3 of the License, or
# (at your option) any later version.
#
# 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/>.
#
# Contact: thomas.dreibholz@gmail.com
#

# Bash options:
set -eu


# ====== Indentation ========================================================
print-utf8 -n -s '<*' '=' '*>'
for indent in -20 +20 ; do
   echo "Indented ${indent}:"
   print-utf8 -i ${indent} "Test: "
   echo "*"
   print-utf8 -i ${indent} "Test äöüß ÆØÅ: "
   echo "*"
   print-utf8 -i ${indent} "托马斯博士: "
   echo "*"
   print-utf8 -i ${indent} "😀💻: "
   echo "*"
done


# ====== Centering ==========================================================
print-utf8 -n -s '<😀' '=' '😀>'
echo "Centered:"
print-utf8 -n -c "Test"
print-utf8 -n -c "\x1b[38;2;241;71;29mTest\x1b[0m"
print-utf8 -n -c "äöüß"
print-utf8 -n -c "托马斯博士"

print-utf8 -n -s '<💻😀' '=' '😀💻>'


# ====== Length, size and width =============================================
echo "Length, size and width:"
print-utf8 -s '<\x1b[5m💻\x1b[25m😀' '=' '\x1b[5m💻\x1b[25m😀>'
print-utf8 -l '<\x1b[5m💻\x1b[25m😀'
print-utf8 -b '<\x1b[5m💻\x1b[25m😀'
print-utf8 -w '<\x1b[5m💻\x1b[25m😀'
print-utf8 -a '<\x1b[5m💻\x1b[25m😀'
print-utf8 -s '<\x1b[5m💻\x1b[25m😀' '=' '\x1b[5m💻\x1b[25m😀>'


# ====== More complex examples ==============================================

echo "Box with date:"
print-utf8 -n -s "\e[1;34m╔" "═" "╗\e[0m"
# Using fixed date here, to make the test output reproducible:
date +"29. 09. 1976 12:34:56" | figlet -w 128 | \
print-utf8 -n -C "\e[1;34m║🕑\e[1;31m" "\e[1;34m🕑║\e[0m"
print-utf8 -n -s "\e[1;34m╚" "═" "╝\e[0m"

echo "Box with error:"
print-utf8 -n -s "\e[1;31;5m█" "▀" "█\e[0m"
echo "ERROR  1234" | figlet -w 128 | \
   print-utf8 -n -C "\e[1;31;5m█\e[25m" "\e[5m█\e[0m"
print-utf8 -n -s "\e[1;31;5m█" "▄" "█\e[0m"

echo "Guru Meditation:"
print-utf8 -n -s "\e[1;31;40;5m█" "▀" "█\e[0m"
echo -e "Software Failure.   Press left mouse button to continue.\nGuru Meditation #00000004.48454C50" | \
   print-utf8 -n -C "\e[1;31;40;5m█\e[25m" "\e[5m█\e[0m"
print-utf8 -n -s "\e[1;31;40;5m█" "▄" "█\e[0m"

echo "Box with indentation:"
print-utf8 -n -x 44 -s "\e[1;32m╒" "═" "╕\e[0m"
for i in 1 2 3 4 5  ; do echo "Test $i" ; done | print-utf8 -n --multiline-indent -42 "\e[1;32m│\e[34m" "\e[1;32m│\e[0m"
for i in 6 7 8 9 10 ; do echo "Test $i" ; done | print-utf8 -n --multiline-indent +42 "\e[1;32m│\e[34m" "\e[1;32m│\e[0m"
print-utf8 -n -x 44 -s "\e[1;32m╘" "═" "╛\e[0m"


echo "Test passed!"
