Redesign wizard UI with gum (charmbracelet)
- Bootstrap gum automatically on first run (Arch/Debian/RHEL/Fedora/SUSE) - utils.sh: replace all bash color helpers with gum equivalents - gum input for text prompts (with value pre-fill for defaults) - gum choose for selection menus - gum confirm for yes/no - gum spin for long-running operations - gum style/log for output (catppuccin mocha palette) - gum style for banners and summary box - core.sh: spinner on git clone/pull - workflow.sh: spinner on git clone - prereqs.sh: spinner on package installs - wizard.sh: double-border welcome banner, rounded summary box, success banner with next-steps panel Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
8a82d27dae
commit
699087f08c
6 changed files with 267 additions and 243 deletions
133
lib/utils.sh
133
lib/utils.sh
|
|
@ -1,70 +1,119 @@
|
|||
#!/usr/bin/env bash
|
||||
# utils.sh — colors, prompts, helpers
|
||||
# utils.sh — gum-based UI helpers (requires gum)
|
||||
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
CYAN='\033[0;36m'
|
||||
BOLD='\033[1m'
|
||||
RESET='\033[0m'
|
||||
# ── Catppuccin Mocha palette ─────────────────────────────────────────────
|
||||
C_MAUVE="#CBA6F7"
|
||||
C_SKY="#89DCEB"
|
||||
C_GREEN="#A6E3A1"
|
||||
C_YELLOW="#F9E2AF"
|
||||
C_RED="#F38BA8"
|
||||
C_PINK="#F5C2E7"
|
||||
C_BASE="#1E1E2E"
|
||||
C_TEXT="#CDD6F4"
|
||||
C_SURFACE="#585B70"
|
||||
|
||||
info() { echo -e "${CYAN}${BOLD}[info]${RESET} $*"; }
|
||||
success() { echo -e "${GREEN}${BOLD}[ok]${RESET} $*"; }
|
||||
warn() { echo -e "${YELLOW}${BOLD}[warn]${RESET} $*"; }
|
||||
error() { echo -e "${RED}${BOLD}[error]${RESET} $*" >&2; }
|
||||
die() { error "$*"; exit 1; }
|
||||
header() { echo -e "\n${BOLD}${CYAN}━━━ $* ━━━${RESET}\n"; }
|
||||
# ── Output helpers ────────────────────────────────────────────────────────
|
||||
info() { gum log --level info -- "$*"; }
|
||||
success() { gum style --foreground "$C_GREEN" " ✓ $*"; }
|
||||
warn() { gum log --level warn -- "$*"; }
|
||||
error() { gum log --level error -- "$*" >&2; }
|
||||
die() { gum style --foreground "$C_RED" --bold " ✗ $*" >&2; exit 1; }
|
||||
|
||||
# ask VAR "prompt" "default"
|
||||
header() {
|
||||
echo ""
|
||||
gum style \
|
||||
--foreground "$C_MAUVE" --bold \
|
||||
--margin "0 2" \
|
||||
"◆ $*"
|
||||
gum style \
|
||||
--foreground "$C_SURFACE" \
|
||||
--margin "0 2" \
|
||||
"────────────────────────────────────────────────"
|
||||
echo ""
|
||||
}
|
||||
|
||||
# ── Prompts ───────────────────────────────────────────────────────────────
|
||||
|
||||
# ask VAR "Label" "default"
|
||||
ask() {
|
||||
local var="$1" prompt="$2" default="$3"
|
||||
local input
|
||||
local var="$1" prompt="$2" default="${3:-}"
|
||||
local result
|
||||
if [[ -n "$default" ]]; then
|
||||
echo -ne "${BOLD}${prompt}${RESET} ${CYAN}[${default}]${RESET}: "
|
||||
result=$(gum input \
|
||||
--value "$default" \
|
||||
--prompt " › " \
|
||||
--prompt.foreground "$C_MAUVE" \
|
||||
--cursor.foreground "$C_MAUVE" \
|
||||
--header " $prompt" \
|
||||
--header.foreground "$C_SKY" \
|
||||
--width 70) || true
|
||||
else
|
||||
echo -ne "${BOLD}${prompt}${RESET}: "
|
||||
result=$(gum input \
|
||||
--placeholder "(required)" \
|
||||
--prompt " › " \
|
||||
--prompt.foreground "$C_MAUVE" \
|
||||
--cursor.foreground "$C_MAUVE" \
|
||||
--header " $prompt" \
|
||||
--header.foreground "$C_SKY" \
|
||||
--width 70) || true
|
||||
fi
|
||||
read -r input || true
|
||||
if [[ -z "$input" && -n "$default" ]]; then
|
||||
if [[ -z "$result" && -n "$default" ]]; then
|
||||
eval "$var=\"\$default\""
|
||||
else
|
||||
eval "$var=\"\$input\""
|
||||
eval "$var=\"\$result\""
|
||||
fi
|
||||
}
|
||||
|
||||
# ask_yn VAR "prompt" "y|n"
|
||||
# ask_yn VAR "Question" "y|n"
|
||||
ask_yn() {
|
||||
local var="$1" prompt="$2" default="$3"
|
||||
local input options
|
||||
if [[ "$default" == "y" ]]; then options="Y/n"; else options="y/N"; fi
|
||||
echo -ne "${BOLD}${prompt}${RESET} ${CYAN}[${options}]${RESET}: "
|
||||
read -r input || true
|
||||
input="${input:-$default}"
|
||||
if [[ "$input" =~ ^[Yy]$ ]]; then
|
||||
local affirmative="Yes" negative="No"
|
||||
[[ "$default" == "y" ]] && affirmative="Yes" || affirmative="Yes"
|
||||
if gum confirm \
|
||||
--affirmative "Yes" \
|
||||
--negative "No" \
|
||||
--default="$([[ "$default" == "y" ]] && echo Yes || echo No)" \
|
||||
--prompt.foreground "$C_SKY" \
|
||||
--selected.background "$C_MAUVE" \
|
||||
--selected.foreground "$C_BASE" \
|
||||
--unselected.foreground "$C_TEXT" \
|
||||
" $prompt"; then
|
||||
eval "$var=y"
|
||||
else
|
||||
eval "$var=n"
|
||||
fi
|
||||
}
|
||||
|
||||
# ask_choice VAR "prompt" option1 option2 ...
|
||||
# ask_choice VAR "Header" option1 option2 ...
|
||||
ask_choice() {
|
||||
local var="$1" prompt="$2"; shift 2
|
||||
local options=("$@")
|
||||
local input idx
|
||||
echo -e "${BOLD}${prompt}${RESET}"
|
||||
for i in "${!options[@]}"; do
|
||||
echo -e " ${CYAN}$((i+1))${RESET}) ${options[$i]}"
|
||||
done
|
||||
echo -ne "Choice ${CYAN}[1]${RESET}: "
|
||||
read -r input || true
|
||||
input="${input:-1}"
|
||||
if [[ "$input" =~ ^[0-9]+$ ]] && (( input >= 1 && input <= ${#options[@]} )); then
|
||||
idx=$(( input - 1 ))
|
||||
local first="$1"
|
||||
local result
|
||||
result=$(gum choose \
|
||||
--cursor " › " \
|
||||
--cursor.foreground "$C_MAUVE" \
|
||||
--selected.foreground "$C_MAUVE" \
|
||||
--selected.bold \
|
||||
--header " $prompt" \
|
||||
--header.foreground "$C_SKY" \
|
||||
--height 10 \
|
||||
"$@") || true
|
||||
if [[ -z "$result" ]]; then
|
||||
eval "$var=\"\$first\""
|
||||
else
|
||||
idx=0
|
||||
eval "$var=\"\$result\""
|
||||
fi
|
||||
eval "$var=\"\${options[$idx]}\""
|
||||
}
|
||||
|
||||
# spin "Title" command args...
|
||||
spin() {
|
||||
local title="$1"; shift
|
||||
gum spin \
|
||||
--spinner dot \
|
||||
--spinner.foreground "$C_MAUVE" \
|
||||
--title " $title" \
|
||||
--title.foreground "$C_SKY" \
|
||||
-- "$@"
|
||||
}
|
||||
|
||||
require_cmd() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue