From 9b4bacabb73e0a4fad5ddbdf94f00d12395575eb Mon Sep 17 00:00:00 2001 From: Matteo Cherubini Date: Fri, 8 May 2026 21:09:41 +0200 Subject: [PATCH] feat: Add core utility functions for terminal output --- lib/output.sh | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 lib/output.sh diff --git a/lib/output.sh b/lib/output.sh new file mode 100644 index 0000000..1a65c90 --- /dev/null +++ b/lib/output.sh @@ -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}" +}