ui.sh 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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 Source Manifest"
  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. local missing_deps="$4"
  78. print_section "Installation Summary"
  79. local -a summary_items=(
  80. "Target Directory: ${target_dir}"
  81. "Package Manager: ${pm}"
  82. )
  83. if (( deps_count > 0 )); then
  84. summary_items+=("Dependencies to install: ${deps_count}")
  85. else
  86. summary_items+=("Dependencies: All installed")
  87. fi
  88. print_summary "${summary_items[@]}"
  89. echo ""
  90. # Show package installation step if there are deps to install
  91. local step_num=1
  92. if (( deps_count > 0 )); then
  93. echo -e "${YELLOW}Step $step_num:${NC} The following packages will be installed using ${pm}:"
  94. for pkg in $missing_deps; do
  95. print_list_item "•" "$pkg"
  96. done
  97. echo ""
  98. ((step_num++))
  99. fi
  100. echo -e "${YELLOW}Step $step_num:${NC} Build and install components:"
  101. ((step_num++))
  102. print_list_item "1" "Invercargill (invercargill-1) - Core library"
  103. print_list_item "2" "Invercargill-Json - JSON serialization"
  104. print_list_item "3" "USM - Universal Source Manifest"
  105. echo ""
  106. echo -e "${YELLOW}Step $step_num:${NC} Create shim at /usr/bin/usm"
  107. echo ""
  108. if ! confirm "Do you want to continue with the installation?" "n"; then
  109. return 1
  110. fi
  111. return 0
  112. }
  113. # Show completion message
  114. show_completion() {
  115. local target_dir="$1"
  116. echo ""
  117. echo -e "${GREEN}✓ Installation Complete!${NC}"
  118. echo ""
  119. echo -e " ${CYAN}Binary:${NC} ${target_dir}/bin/usm"
  120. echo -e " ${CYAN}Shim:${NC} /usr/bin/usm"
  121. echo ""
  122. echo -e "Run ${BOLD}usm --help${NC} to get started."
  123. echo ""
  124. }
  125. # Show error and exit
  126. show_error_and_exit() {
  127. local message="$1"
  128. local code="${2:-1}"
  129. echo ""
  130. echo -e "${RED}╔══════════════════════════════════════════════════════════════╗${NC}"
  131. echo -e "${RED}║ Installation Failed ║${NC}"
  132. echo -e "${RED}╚══════════════════════════════════════════════════════════════╝${NC}"
  133. echo ""
  134. echo -e "${RED}Error:${NC} $message"
  135. echo ""
  136. exit "$code"
  137. }