feat: Add core utility functions for terminal output
This commit is contained in:
parent
236c01de79
commit
9b4bacabb7
1 changed files with 36 additions and 0 deletions
36
lib/output.sh
Normal file
36
lib/output.sh
Normal 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}"
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue