#!/bin/bash # ui.sh - Text User Interface functions for USM installer # Print a banner/header print_banner() { echo -e "${CYAN}${BOLD}" echo "USM Installer - Universal Source Manifest" echo -e "Version: ${SCRIPT_VERSION}${NC}" echo "" } # Print a section header print_section() { local title="$1" echo "" echo -e "${BOLD}${BLUE}▶ $title${NC}" echo "" } # Print a summary box print_summary() { local -a items=("$@") local max_width=0 # Find max width for item in "${items[@]}"; do local len=${#item} (( len > max_width )) && max_width=$len done (( max_width < 50 )) && max_width=50 (( max_width > 70 )) && max_width=70 local line=$(printf '─%.0s' $(seq 1 $((max_width + 2)))) echo -e "${CYAN}┌${line}┐${NC}" for item in "${items[@]}"; do printf "${CYAN}│${NC} %-$((max_width))s ${CYAN}│${NC}\n" "$item" done echo -e "${CYAN}└${line}┘${NC}" } # Print a progress indicator print_progress() { local current="$1" local total="$2" local description="$3" local width=40 local filled=$((width * current / total)) local empty=$((width - filled)) printf "\r${GREEN}[" printf "%$((filled))s" | tr ' ' '█' printf "%$((empty))s" | tr ' ' '░' printf "]${NC} ($current/$total) %s" "$description" if (( current == total )); then echo "" fi } # Print a list item print_list_item() { local bullet="${1:-•}" local text="$2" local indent="${3:- }" echo -e "${indent}${CYAN}${bullet}${NC} ${text}" } # Print a status line print_status() { local label="$1" local value="$2" local status="${3:-info}" local status_icon case "$status" in ok) status_icon="${GREEN}✓${NC}" ;; warn) status_icon="${YELLOW}!${NC}" ;; error) status_icon="${RED}✗${NC}" ;; *) status_icon="${BLUE}i${NC}" ;; esac printf " ${status_icon} %-25s %s\n" "$label" "$value" } # Show installation summary and get confirmation show_installation_summary() { local target_dir="$1" local pm="$2" local deps_count="$3" local missing_deps="$4" print_section "Installation Summary" local -a summary_items=( "Target Directory: ${target_dir}" "Package Manager: ${pm}" ) if (( deps_count > 0 )); then summary_items+=("Dependencies to install: ${deps_count}") else summary_items+=("Dependencies: All installed") fi print_summary "${summary_items[@]}" echo "" # Show package installation step if there are deps to install local step_num=1 if (( deps_count > 0 )); then echo -e "${YELLOW}Step $step_num:${NC} The following packages will be installed using ${pm}:" for pkg in $missing_deps; do print_list_item "•" "$pkg" done echo "" ((step_num++)) fi echo -e "${YELLOW}Step $step_num:${NC} Build and install components:" ((step_num++)) print_list_item "1" "Invercargill (invercargill-1) - Core library" print_list_item "2" "Invercargill-Json - JSON serialization" print_list_item "3" "USM - Universal Source Manifest" echo "" echo -e "${YELLOW}Step $step_num:${NC} Create shim at /usr/bin/usm" echo "" if ! confirm "Do you want to continue with the installation?" "n"; then return 1 fi return 0 } # Show completion message show_completion() { local target_dir="$1" echo "" echo -e "${GREEN}✓ Installation Complete!${NC}" echo "" echo -e " ${CYAN}Binary:${NC} ${target_dir}/bin/usm" echo -e " ${CYAN}Shim:${NC} /usr/bin/usm" echo "" echo -e "Run ${BOLD}usm --help${NC} to get started." echo "" } # Show error and exit show_error_and_exit() { local message="$1" local code="${2:-1}" echo "" echo -e "${RED}╔══════════════════════════════════════════════════════════════╗${NC}" echo -e "${RED}║ Installation Failed ║${NC}" echo -e "${RED}╚══════════════════════════════════════════════════════════════╝${NC}" echo "" echo -e "${RED}Error:${NC} $message" echo "" exit "$code" }