ui.sh 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. #!/bin/bash
  2. # ui.sh - Text User Interface functions for USM installer
  3. # Print a banner/header
  4. print_banner() {
  5. echo -e "${CYAN}${BOLD}"
  6. echo "USM Installer - Universal Software Manager"
  7. echo -e "Version: ${SCRIPT_VERSION}${NC}"
  8. echo ""
  9. }
  10. # Print a section header
  11. print_section() {
  12. local title="$1"
  13. echo ""
  14. echo -e "${BOLD}${BLUE}▶ $title${NC}"
  15. echo ""
  16. }
  17. # Print a summary box
  18. print_summary() {
  19. local -a items=("$@")
  20. local max_width=0
  21. # Find max width
  22. for item in "${items[@]}"; do
  23. local len=${#item}
  24. (( len > max_width )) && max_width=$len
  25. done
  26. (( max_width < 50 )) && max_width=50
  27. (( max_width > 70 )) && max_width=70
  28. local line=$(printf '─%.0s' $(seq 1 $((max_width + 2))))
  29. echo -e "${CYAN}┌${line}┐${NC}"
  30. for item in "${items[@]}"; do
  31. printf "${CYAN}│${NC} %-$((max_width))s ${CYAN}│${NC}\n" "$item"
  32. done
  33. echo -e "${CYAN}└${line}┘${NC}"
  34. }
  35. # Print a progress indicator
  36. print_progress() {
  37. local current="$1"
  38. local total="$2"
  39. local description="$3"
  40. local width=40
  41. local filled=$((width * current / total))
  42. local empty=$((width - filled))
  43. printf "\r${GREEN}["
  44. printf "%$((filled))s" | tr ' ' '█'
  45. printf "%$((empty))s" | tr ' ' '░'
  46. printf "]${NC} ($current/$total) %s" "$description"
  47. if (( current == total )); then
  48. echo ""
  49. fi
  50. }
  51. # Print a list item
  52. print_list_item() {
  53. local bullet="${1:-•}"
  54. local text="$2"
  55. local indent="${3:- }"
  56. echo -e "${indent}${CYAN}${bullet}${NC} ${text}"
  57. }
  58. # Print a status line
  59. print_status() {
  60. local label="$1"
  61. local value="$2"
  62. local status="${3:-info}"
  63. local status_icon
  64. case "$status" in
  65. ok) status_icon="${GREEN}✓${NC}" ;;
  66. warn) status_icon="${YELLOW}!${NC}" ;;
  67. error) status_icon="${RED}✗${NC}" ;;
  68. *) status_icon="${BLUE}i${NC}" ;;
  69. esac
  70. printf " ${status_icon} %-25s %s\n" "$label" "$value"
  71. }
  72. # Show installation summary and get confirmation
  73. show_installation_summary() {
  74. local target_dir="$1"
  75. local pm="$2"
  76. local deps_count="$3"
  77. print_section "Installation Summary"
  78. local -a summary_items=(
  79. "Target Directory: ${target_dir}"
  80. "Package Manager: ${pm}"
  81. "Dependencies to install: ${deps_count}"
  82. "Components:"
  83. )
  84. print_summary "${summary_items[@]}"
  85. echo ""
  86. print_list_item "1" "Invercargill (invercargill-1) - Core library"
  87. print_list_item "2" "Invercargill-Json - JSON serialization"
  88. print_list_item "3" "USM - Universal Software Manager"
  89. echo ""
  90. echo -e "${YELLOW}This script will:${NC}"
  91. print_list_item "•" "Install required system packages via ${pm}"
  92. print_list_item "•" "Build and install Invercargill libraries"
  93. print_list_item "•" "Build and install USM to ${target_dir}"
  94. print_list_item "•" "Create a shim at /usr/bin/usm"
  95. echo ""
  96. if ! confirm "Do you want to continue with the installation?" "n"; then
  97. return 1
  98. fi
  99. return 0
  100. }
  101. # Show completion message
  102. show_completion() {
  103. local target_dir="$1"
  104. echo ""
  105. echo -e "${GREEN}✓ Installation Complete!${NC}"
  106. echo ""
  107. echo -e " ${CYAN}Binary:${NC} ${target_dir}/bin/usm"
  108. echo -e " ${CYAN}Shim:${NC} /usr/bin/usm"
  109. echo ""
  110. echo -e "Run ${BOLD}usm --help${NC} to get started."
  111. echo ""
  112. }
  113. # Show error and exit
  114. show_error_and_exit() {
  115. local message="$1"
  116. local code="${2:-1}"
  117. echo ""
  118. echo -e "${RED}╔══════════════════════════════════════════════════════════════╗${NC}"
  119. echo -e "${RED}║ Installation Failed ║${NC}"
  120. echo -e "${RED}╚══════════════════════════════════════════════════════════════╝${NC}"
  121. echo ""
  122. echo -e "${RED}Error:${NC} $message"
  123. echo ""
  124. exit "$code"
  125. }