feat: Add core utility functions for terminal output

This commit is contained in:
Matteo Cherubini 2026-05-08 21:09:41 +02:00
parent 236c01de79
commit 9b4bacabb7

36
lib/output.sh Normal file
View file

@ -0,0 +1,36 @@
#!/usr/bin/env bash
# =============================================================================
# lib/output.sh
# Terminal output helpers: colors, log levels, and step banners.
# =============================================================================
if [[ -t 1 ]]; then
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
CYAN='\033[0;36m'
RED='\033[0;31m'
BOLD='\033[1m'
NC='\033[0m'
else
GREEN='' YELLOW='' CYAN='' RED='' BOLD='' NC=''
fi
info() { echo -e "${CYAN}[INFO]${NC} $*"; }
success() { echo -e "${GREEN}[OK]${NC} $*"; }
warn() { echo -e "${YELLOW}[WARN]${NC} $*"; }
error() { echo -e "${RED}[ERROR]${NC} $*" >&2; }
step() { echo -e "\n${BOLD}${YELLOW}━━━ $* ━━━${NC}"; }
box() {
local max_len=0
for line in "$@"; do
[[ ${#line} -gt $max_len ]] && max_len=${#line}
done
local border
border=$(printf '─%.0s' $(seq 1 $((max_len + 2))))
echo -e "${CYAN}${border}${NC}"
for line in "$@"; do
printf "${CYAN}${NC} %-${max_len}s ${CYAN}${NC}\n" "$line"
done
echo -e "${CYAN}${border}${NC}"
}