37 lines
1.1 KiB
Bash
37 lines
1.1 KiB
Bash
#!/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() { printf "%b\n" "${CYAN}[INFO]${NC} $*"; }
|
|
success() { printf "%b\n" "${GREEN}[OK]${NC} $*"; }
|
|
warn() { printf "%b\n" "${YELLOW}[WARN]${NC} $*"; }
|
|
error() { printf "%b\n" "${RED}[ERROR]${NC} $*" >&2; }
|
|
die() { error "$*"; exit 1; }
|
|
step() { printf "\n%b\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))))
|
|
printf "%b\n" "${CYAN}┌${border}┐${NC}"
|
|
for line in "$@"; do
|
|
printf "${CYAN}│${NC} %-${max_len}s ${CYAN}│${NC}\n" "$line"
|
|
done
|
|
printf "%b\n" "${CYAN}└${border}┘${NC}"
|
|
}
|