Rainbow header that works

Modified: February 14, 2026 7:58 PM Created: September 17, 2025 3:27 PM Master Type: Notes Hide: No Starred: No Status: Unassigned

#!/bin/bash
set -euo pipefail

# ---------------------------
# CONFIG
# ---------------------------
SCRIPT_FOLDER="$HOME/Scripts"

# ANSI colors
GREEN="\033[1;32m"
YELLOW="\033[1;33m"
RED="\033[1;31m"
CYAN="\033[1;36m"
MAGENTA="\033[1;35m"
WHITE="\033[1;37m"
NC="\033[0m"

# ---------------------------
# Fun tips for spinner
# ---------------------------
TIPS=(
"๐Ÿ“ธ Coffee levels low. Operator alert recommended."
"๐Ÿพ Feline observers online. Spreadsheet approval pending."
"โณ Patience required. Temporal flux minimal but present."
"โœจ Archive integrity at maximum sparkle output."
"๐ŸŒŠ Hang tight. Waveforms nominal, operator stable."
"๐Ÿ”ฎ Processing magicโ€ฆ flux capacitors at 72%."
"๐Ÿ’พ Backup engaged. Future-you will report success."
"๐Ÿฆ– Dino-level patience required. Fossil signals detected."
"๐Ÿ“ Logging notesโ€ฆ head trauma risk minimal."
"๐ŸŽจ Color calibration active. Vividness at 97%."
"๐Ÿš€ Retro-futurist energy loadingโ€ฆ warp cores stabilizing."
"๐Ÿ—‚ Sorting historyโ€ฆ one artifact at a time."
"๐Ÿ’ก Bright idea detected. Routing to mainframe."
"๐Ÿ•ต๏ธโ€โ™€๏ธ Inspecting dataโ€ฆ anomaly detection online."
"โšก Almost doneโ€ฆ final sequences initializing."
"๐ŸŒŒ Pixels aligningโ€ฆ cosmic synchronization complete."
"๐Ÿ–ผ Another artifact scannedโ€ฆ victory protocol engaged."
"โ˜• Caffeine levels nominal. Moodlet bonus active."
"๐Ÿฑ Cat consensus reached: digitization approved."
"๐ŸŽ‡ Magic signal detected between clicks."
"๐Ÿ”ง Photoshop action deployedโ€ฆ feline AI supervising."
"๐Ÿช Archive orbit engaged. All systems nominal."
"๐Ÿ“ฆ Boxes secured. Tagging protocol active."
"๐Ÿ” Zoom sequence complete. Details optimized."
"๐Ÿงฉ Archival assembly progressingโ€ฆ module stability 100%."
"๐ŸŽถ Quiet beats enabled. Workflow efficiency +5."
"๐Ÿงต Threads of history digitally stitched. No tears."
"๐ŸŒฟ Operator breathing stable. Archive thanks you."
"๐Ÿ–‹ Metadata wizardry detected. Spellcasting active."
"๐Ÿ“ Precision calibration active. Pixels aligned."
"๐ŸŒŸ Minor victories logged. Accumulate morale boost."
"๐Ÿ›  Tools online. Operational magic detected."
"๐Ÿฅฝ Safety protocol engaged. Pixel hazards minimal."
"๐Ÿง  Neural networks engaged. Cognitive load optimal."
"๐ŸŒธ Workspace aesthetic nominal. Operator satisfaction +2."
"๐Ÿ”’ Archival protection active. Security protocols online."
"๐Ÿ“Š Data love flowing. Spreadsheet integrity stable."
"๐ŸŽ Every scan secured. Gift transmission confirmed."
"๐Ÿ›ธ Workflow efficiency approaching UFO-class levels."
"๐Ÿ’Œ Future researchers will send commendations."
"๐Ÿ–ค Dark mode active. Moodlet bonus applied."
"๐ŸŽข Digitization rollercoaster online. Hold on."
"๐Ÿ”‘ Unlocking archive secretsโ€ฆ sequence successful."
"๐ŸŒž Sunlight optional. Brilliance levels sufficient."
"๐Ÿฆ‰ Wisdom protocol engaged. Archive guidance online."
"๐Ÿ›Ž Ding! Process complete. All files secured."
"๐Ÿ“œ Catalogue loggingโ€ฆ poetry metrics stable."
"๐ŸŒ  Star alignment nominal. TIFFs incoming."
"๐Ÿฅ‚ Batch celebration protocol activated."
"๐Ÿ’ซ Sparkle levels responsibly maintained."
"๐Ÿ– Drawing outside lines optional. Risk: chaos."
"๐Ÿ“š History grows. Incremental progress confirmed."
"๐ŸŽฏ Focus modules online. Task success probability +12%."
"๐Ÿช Creativity levels soaring. Order stability maintained."
"๐Ÿ•ฐ Temporal navigation complete. Negative secured."
"๐Ÿฅ‡ Specialist achievement unlocked. Recognition granted."
"๐Ÿ’ฅ Pixel storm incomingโ€ฆ brace your coffee."
"๐Ÿ›ธ Alien observer: data integrity confirmed."
"๐Ÿ“ก Signal booster online. Archive ping successful."
"โšก Capacitors charged. Sparks may fly."
"๐Ÿ–ฅ Monitor flicker detectedโ€ฆ just aesthetics."
"๐Ÿช Planetary alignment favors new TIFF uploads."
"๐Ÿงญ Navigation console active. Metadata coordinates set."
"๐ŸŽ› Dial knobs clockwiseโ€ฆ efficiency +7%."
"๐Ÿ›  Emergency toolkit online. Use responsibly."
"๐Ÿ’ฃ Minor glitch detectedโ€ฆ ignore at your own risk."
"๐ŸŒ  Starfield projection engaged. Moodlet: inspired."
"๐Ÿ›ฐ Satellite ping received. Archive operational."
"๐Ÿ•น Joystick optional. Cursor stabilized."
"๐Ÿ–ฑ Mouse calibration nominal. Click at will."
"๐Ÿ”‹ Power cells charged. Operator alertness advised."
"๐Ÿ’พ Mainframe memory banks hummingโ€ฆ hum soothing."
"๐Ÿ“ Digital quills ready. Logging commencing."
"๐Ÿง  Neural interface active. Thought-stream synced."
"๐Ÿงต Threads of data: minor tangles detected, fixing."
"๐Ÿ“ฆ Cargo bay full. Extra pixels secured in storage."
"๐ŸŽฏ Target archive locked. Precision protocols online."
"๐Ÿ’ซ Photon beams aligned. TIFFs incoming."
"๐ŸŽ† Retrofuturistic fireworks queued. Stand by."
"๐Ÿ“Š Data integrity: 100% confirmed. Spreadsheet victory."
"๐ŸŒฟ Oxygen levels normal. Operator can breathe easy."
"๐ŸŽถ Retro synth ambient soundtrack active."
"๐Ÿ’Œ Message to future researchers queued."
"๐Ÿ›ธ UFO-level efficiency confirmed. No abducted pixels."
"๐Ÿ›Ž Archive alert: batch complete. Ding!"
"๐Ÿช Orbital sequence nominal. Archive intact."
"โšก Voltage spike detectedโ€ฆ aesthetic only."
"๐Ÿ”’ Security protocols online. Data safe."
"๐Ÿ’ฅ Minor cosmic glitchโ€ฆ ignore unless dramatic."
"๐Ÿ›ฐ Incoming archive signalโ€ฆ all channels green."
"๐Ÿ’พ Data replication in progress. Quantum stable."
"๐Ÿช Orbital recalibration complete. Gravity nominal."
"๐Ÿ”ง Repair drones deployed. No pixel casualties."
"โšก Warning: minor energy fluctuation detected."
"๐Ÿ–ฅ Monitor refresh sequence complete. Flicker nominal."
"๐Ÿ“ก Receiving transmissions from future researchers."
"๐ŸŽ‡ Spark sequence queued. Visuals optional, morale +5."
"๐Ÿงญ Metadata compass active. Coordinates locked."
"๐Ÿ›  Toolkit ready. Operator skill level: expert."
"๐Ÿ’ฃ Simulation: cosmic glitch incomingโ€ฆ ignore if bored."
"๐ŸŒŒ Archive cosmos scan: integrity 100%."
"๐Ÿ•น Virtual joystick activated. Cursor responsive."
"๐ŸŽ› Energy dial rotation nominal. Efficiency +3%."
"๐Ÿ“ Log sync complete. Notes secured."
"๐Ÿง  Cognitive systems online. Neural flux optimal."
"๐Ÿ“ฆ Cargo bay status: fully packed. Pixels secure."
"๐Ÿ– Drawing module online. Chaos optional."
"๐ŸŽถ Ambient synth engaged. Moodlet: focused."
"๐Ÿ’ซ Photon alignment: TIFFs incoming. Brace for brilliance."
"๐Ÿ›Ž Alert: batch sequence completed. Ding ding!"
"๐Ÿ–ค Dark mode confirmed. Eye strain minimized."
"๐ŸŒ  Star projection engaged. Cosmic bonuses applied."
)

# ---------------------------
# Captain Whiskers lines
# ---------------------------
CW_LINES=(
# --- Mission Logs / Status Reports (1โ€“30) ---
"โ–“โ–’โ–‘ LOG: Negative 01 scanned."
"โ–“โ–’โ–‘ LOG: Negative 02 scanned."
"โ–“โ–’โ–‘ LOG: Negative 03 scanned."
"โ–“โ–’โ–‘ SYSTEM: Box 07 sealed. Captain Whiskers approves."
"โ–“โ–’โ–‘ SYSTEM: Box 08 sealed. Pawprint logged."
"โ–“โ–’โ–‘ DATASTREAM: TIFF conversion in progress."
"โ–“โ–’โ–‘ DATASTREAM: JPG generation queued."
"โ–“โ–’โ–‘ ALERT: Paperclip count exceeds threshold."
"โ–“โ–’โ–‘ ARCHIVE: Folder 12 scanned."
"โ–“โ–’โ–‘ ARCHIVE: Folder 23 scanned. Paw prints logged."
"โ–“โ–’โ–‘ LOG: Batch 5 complete. Sensors nominal."
"โ–“โ–’โ–‘ LOG: Batch 6 complete. All items accounted for."
"โ–“โ–’โ–‘ SYSTEM: Power levels stable."
"โ–“โ–’โ–‘ DATASTREAM: Scanning metadata."
"โ–“โ–’โ–‘ LOG: Negative 42 successfully scanned."
"โ–“โ–’โ–‘ ALERT: Dust detected on plate. Clean immediately."
"โ–“โ–’โ–‘ LOG: Box 21 relocated to Zone C."
"โ–“โ–’โ–‘ SYSTEM: Archive temperature nominal."
"โ–“โ–’โ–‘ LOG: Batch 7 initiated. Captain Whiskers supervising."
"โ–“โ–’โ–‘ LOG: Batch 8 initiated. Pawprints logged."
"โ–“โ–’โ–‘ ALERT: Misfiled negative detected."
"โ–“โ–’โ–‘ DATASTREAM: Checking file integrity."
"โ–“โ–’โ–‘ SYSTEM: Laser calibration complete."
"โ–“โ–’โ–‘ LOG: Disk space OK. Ready for next phase."
"โ–“โ–’โ–‘ LOG: Folder 42 verified."
"โ–“โ–’โ–‘ ALERT: Minor pixel misalignment."
"โ–“โ–’โ–‘ ARCHIVE: Volume 3 scanned. Captain Whiskers approves."
"โ–“โ–’โ–‘ LOG: Batch 9 complete."
"โ–“โ–’โ–‘ LOG: Phase 1 prep done."
"โ–“โ–’โ–‘ SYSTEM: Environment stable."

# --- Captain Whiskersโ€™ Personal Commentary (31โ€“60) ---
"โ–“โ–’โ–‘ CW: Patience, young human."
"โ–“โ–’โ–‘ CW: Coffee detected. Good choice."
"โ–“โ–’โ–‘ CW: Remember the metadata!"
"โ–“โ–’โ–‘ CW: Another JPG joins the fleet."
"โ–“โ–’โ–‘ CW: Cute pawprint incoming."
"โ–“โ–’โ–‘ CW: Files are stacking nicely."
"โ–“โ–’โ–‘ CW: Inspect each box carefully."
"โ–“โ–’โ–‘ CW: Archive day is cosmic day."
"โ–“โ–’โ–‘ CW: Logging personal notes."
"โ–“โ–’โ–‘ CW: Another artifact, another victory."
"โ–“โ–’โ–‘ CW: Reminder: hydrate human."
"โ–“โ–’โ–‘ CW: Pawprint detected in unexpected location."
"โ–“โ–’โ–‘ CW: Tiny stars align on monitor."
"โ–“โ–’โ–‘ CW: Smooth scrolling. Good job."
"โ–“โ–’โ–‘ CW: Captain Whiskers approves this crop."
"โ–“โ–’โ–‘ CW: Another metadata packet secured."
"โ–“โ–’โ–‘ CW: Paw prints are being tracked."
"โ–“โ–’โ–‘ CW: Warp drive nominal."
"โ–“โ–’โ–‘ CW: Archive sensors stable."
"โ–“โ–’โ–‘ CW: Files look neat."
"โ–“โ–’โ–‘ CW: Inspecting negatives carefully."
"โ–“โ–’โ–‘ CW: Cosmic alignment achieved."
"โ–“โ–’โ–‘ CW: Minor flicker detected. All good."
"โ–“โ–’โ–‘ CW: Pawprint collected."
"โ–“โ–’โ–‘ CW: Files orbiting nicely."
"โ–“โ–’โ–‘ CW: Metadata logs complete."
"โ–“โ–’โ–‘ CW: Captain Whiskers demands more pawprints."
"โ–“โ–’โ–‘ CW: All clear in Sector 7."
"โ–“โ–’โ–‘ CW: Archive 1989 reminiscence."
"โ–“โ–’โ–‘ CW: Another warp bubble stabilized."

# --- Accidental Feedback / Spaceship Signals (61โ€“80) ---
"โ–“โ–’โ–‘ SHIP1: Warp coordinates misaligned."
"โ–“โ–’โ–‘ SHIP2: Thrusters nominal."
"โ–“โ–’โ–‘ SIGNAL: Glitch detected. Attempting repair."
"โ–“โ–’โ–‘ COMM: Data packet #42 floating in space."
"โ–“โ–’โ–‘ ALERT: Pawprint anomaly in Sector 5."
"โ–“โ–’โ–‘ SHIP3: Minor collision avoided."
"โ–“โ–’โ–‘ SIGNAL: Beam fluctuation detected."
"โ–“โ–’โ–‘ COMM: Cosmic dust detected."
"โ–“โ–’โ–‘ SHIP1: Scanning nebula."
"โ–“โ–’โ–‘ SIGNAL: Unexpected reflection detected."
"โ–“โ–’โ–‘ ALERT: Micro starfield disturbance."
"โ–“โ–’โ–‘ SHIP2: Navigation nominal."
"โ–“โ–’โ–‘ COMM: Telemetry glitch detected."
"โ–“โ–’โ–‘ ALERT: Archive sensors flicker."
"โ–“โ–’โ–‘ SHIP3: Pawprint beacon active."
"โ–“โ–’โ–‘ SIGNAL: Minor interference detected."
"โ–“โ–’โ–‘ COMM: Logging anomaly."
"โ–“โ–’โ–‘ ALERT: Cosmic rays impacting pixels."
"โ–“โ–’โ–‘ SHIP1: Alignment complete."
"โ–“โ–’โ–‘ SIGNAL: Minor warp fluctuation detected."

# --- Digitization Mission Tips / Humor (81โ€“100) ---
"โ–“โ–’โ–‘ TIP: Label all boxes. Captain Whiskers insists."
"โ–“โ–’โ–‘ TIP: Save often, or face cosmic chaos."
"โ–“โ–’โ–‘ CW: Pixels align. Proceed with caution."
"โ–“โ–’โ–‘ CW: Inspect every negative, even the tiny ones."
"โ–“โ–’โ–‘ TIP: Coffee improves scanning efficiency."
"โ–“โ–’โ–‘ CW: Every pawprint counts."
"โ–“โ–’โ–‘ TIP: Organize by date and type."
"โ–“โ–’โ–‘ CW: Keep your cat nearby for supervision."
"โ–“โ–’โ–‘ TIP: Small victories accumulate."
"โ–“โ–’โ–‘ CW: Cosmic sparkle in archive achieved."
"โ–“โ–’โ–‘ TIP: Double-check metadata before export."
"โ–“โ–’โ–‘ CW: Captain Whiskers recommends napping."
"โ–“โ–’โ–‘ TIP: Rotate boxes to avoid dust accumulation."
"โ–“โ–’โ–‘ CW: Archive sensors nominal."
"โ–“โ–’โ–‘ TIP: Use proper lighting when scanning."
"โ–“โ–’โ–‘ CW: Pawprint patrol active."
"โ–“โ–’โ–‘ TIP: Every scan is a gift to the future."
"โ–“โ–’โ–‘ CW: Cosmic alignment nominal."
"โ–“โ–’โ–‘ TIP: Enjoy the workflow, young specialist."
"โ–“โ–’โ–‘ CW: Captain Whiskers approves the export."
)

# ---------------------------
# Helper: print centered text
# ---------------------------
print_centered() {
    local color="$1"
    local text="$2"
    local width="$3"
    local symbols=("*" "โ€ข" "+" "ยบ" "." "โœฆ" " ")

    [ ${#text} -gt $width ] && text="${text:0:$width}"
    text="${text//%/%%}"

    local pad_left=$(( (width - ${#text}) / 2 ))
    local pad_right=$(( width - ${#text} - pad_left ))
    local left_pad="" right_pad=""

    for ((i=0;i<pad_left;i++)); do
        if (( RANDOM % 12 < 9 )); then left_pad+=" "; else left_pad+="${symbols[$((RANDOM % ${#symbols[@]}))]}"; fi
    done
    for ((i=0;i<pad_right;i++)); do
        if (( RANDOM % 20 < 16 )); then right_pad+=" "; else right_pad+="${symbols[$((RANDOM % ${#symbols[@]}))]}"; fi
    done
    left_pad="${left_pad//%/%%}"
    right_pad="${right_pad//%/%%}"

    printf "%bโ•‘%s%s%sโ•‘%b\n" "$color" "$left_pad" "$text" "$right_pad" "$NC"
}

# ---------------------------
# Shimmering stars generator (sparser)
# ---------------------------
generate_stars() {
    local count=$1
    local output=""
    local symbols=("*" "โ€ข" "+" "ยบ" "." "โœฆ" " ")
    for i in $(seq 1 $count); do
        if (( RANDOM % 3 < 2 )); then
            output+=" "
        else
            output+="${symbols[$((RANDOM % ${#symbols[@]}))]}"
        fi
    done
    echo "$output"
}

# ---------------------------
# Spinner function (with rotating tips)
# ---------------------------
spinner() {
    local pid=$1
    local min_time=${2:-2}
    local start_time=$(date +%s)
    local delay=0.15
    local spinstr='|/-\'
    local sparkles=("โœจ" "๐ŸŒŸ" "๐Ÿ’ซ" "โญ๏ธ" "๐Ÿพ" "โœฆ" "ยบ" "โ€ข")
    local tip_interval_secs=1
    local last_tip_time=$(date +%s)
    local tip="${TIPS[$((RANDOM % ${#TIPS[@]}))]}"
    local i=0

    local max_len=0
    for t in "${TIPS[@]}"; do (( ${#t} > max_len )) && max_len=${#t}; done

    while kill -0 "$pid" 2>/dev/null; do
        local now=$(date +%s)
        if (( now - last_tip_time >= tip_interval_secs )); then
            tip="${TIPS[$((RANDOM % ${#TIPS[@]}))]}"
            last_tip_time=$now
        fi
        local idx=$(( i % 4 ))
        local spin_char="${spinstr:$idx:1}"
        local sparkle="${sparkles[$((RANDOM % ${#sparkles[@]}))]}"
        printf "\r${CYAN}Working... %-*s %s${NC}" "$max_len" "$tip" "$spin_char$sparkle"
        sleep $delay
        ((i++))
    done

    local elapsed=$(( $(date +%s) - start_time ))
    while [ $elapsed -lt $min_time ]; do
        local now=$(date +%s)
        if (( now - last_tip_time >= tip_interval_secs )); then
            tip="${TIPS[$((RANDOM % ${#TIPS[@]}))]}"
            last_tip_time=$now
        fi
        local idx=$(( i % 4 ))
        local spin_char="${spinstr:$idx:1}"
        local sparkle="${sparkles[$((RANDOM % ${#sparkles[@]}))]}"
        printf "\r${CYAN}Working... %-*s %s${NC}" "$max_len" "$tip" "$spin_char$sparkle"
        sleep $delay
        ((i++))
        elapsed=$(( $(date +%s) - start_time ))
    done

    printf "\r${GREEN}Working... %-*s โœ… Done!${NC}\n" "$max_len" "$tip"
}

# ---------------------------
# Detect candidate volumes
# ---------------------------
detect_volume() {
    local candidateVolumes=()
    for vol in /Volumes/*; do
        [ -f "$vol/config.sh" ] && candidateVolumes+=("$vol")
    done

    if [ ${#candidateVolumes[@]} -eq 0 ]; then
        echo -e "${RED}No volume with config.sh found.${NC}"
        exit 1
    elif [ ${#candidateVolumes[@]} -eq 1 ]; then
        TOP_FOLDER="${candidateVolumes[0]}"
        echo -e "${GREEN}Detected volume: $TOP_FOLDER${NC}"
    else
        echo -e "${YELLOW}Multiple candidate volumes detected:${NC}"
        select TOP_FOLDER in "${candidateVolumes[@]}"; do
            [ -n "$TOP_FOLDER" ] && break
            echo -e "${RED}Invalid selection.${NC}"
        done
    fi
}

print_centered_rainbow() {
    local text="$1"
    local width="$2"
    local symbols=("*" "โ€ข" "+" "ยบ" "." "โœฆ" " ")

    # Trim if too long
    [ ${#text} -gt $width ] && text="${text:0:$width}"

    # Padding calculations
    local pad_left=$(( (width - ${#text}) / 2 ))
    local pad_right=$(( width - ${#text} - pad_left ))
    local left_pad="" right_pad=""

    for ((i=0;i<pad_left;i++)); do
        if (( RANDOM % 12 < 9 )); then left_pad+=" "; else left_pad+="${symbols[$((RANDOM % ${#symbols[@]}))]}"; fi
    done
    for ((i=0;i<pad_right;i++)); do
        if (( RANDOM % 20 < 16 )); then right_pad+=" "; else right_pad+="${symbols[$((RANDOM % ${#symbols[@]}))]}"; fi
    done

    # Side borders
    printf "%bโ•‘" "$GREEN"

    # Print left padding
    printf "%s" "$left_pad"

    # Rainbow text
    for ((i=0; i<${#text}; i++)); do
        local hue=$(( i * 360 / ${#text} ))
        local color_code="\033[38;5;$(hue_to_ansi $hue)m"
        printf "${color_code}%s${NC}" "${text:i:1}"
    done

    # Print right padding
    printf "%s" "$right_pad"

    # Close right border
    printf "%bโ•‘%b\n" "$GREEN" "$NC"
}

# ---------------------------
# Draw menu
# ---------------------------
draw_menu() {
    local ascii_banner_lines=(
"โ–ˆโ–ˆโ•—  โ–ˆโ–ˆโ•—โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•—  โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•—   โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•—โ–ˆโ–ˆโ•—  โ–ˆโ–ˆโ•—"
"โ–ˆโ–ˆโ•‘  โ–ˆโ–ˆโ•‘โ–ˆโ–ˆโ•”โ•โ•โ–ˆโ–ˆโ•—โ–ˆโ–ˆโ•”โ•โ•โ•โ•โ•   โ–ˆโ–ˆโ•”โ•โ•โ•โ•โ•โ–ˆโ–ˆโ•‘  โ–ˆโ–ˆโ•‘"
"โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•‘โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•”โ•โ–ˆโ–ˆโ•‘        โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•—โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•‘"
"โ–ˆโ–ˆโ•”โ•โ•โ–ˆโ–ˆโ•‘โ–ˆโ–ˆโ•”โ•โ•โ–ˆโ–ˆโ•—โ–ˆโ–ˆโ•‘        โ•šโ•โ•โ•โ•โ–ˆโ–ˆโ•‘โ–ˆโ–ˆโ•”โ•โ•โ–ˆโ–ˆโ•‘"
"โ–ˆโ–ˆโ•‘  โ–ˆโ–ˆโ•‘โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•”โ•โ•šโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•—โ–ˆโ–ˆโ•—โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•‘โ–ˆโ–ˆโ•‘  โ–ˆโ–ˆโ•‘"
"โ•šโ•โ•  โ•šโ•โ•โ•šโ•โ•โ•โ•โ•โ•  โ•šโ•โ•โ•โ•โ•โ•โ•šโ•โ•โ•šโ•โ•โ•โ•โ•โ•โ•โ•šโ•โ•  โ•šโ•โ•"
    )

    local max_len=0
    for line in "${ascii_banner_lines[@]}"; do
        (( ${#line} > max_len )) && max_len=${#line}
    done

    local border_width=$(( max_len + 4 ))
    local inner_width=$(( border_width - 2 ))

    local header="Detected volume: ${TOP_FOLDER:-None}"
    local left_extra="โ•โ•โ• "
    local top_content="$left_extra$header"
    local top_len=${#top_content}
    local fill_len=$(( border_width - top_len - 2 ))
    (( fill_len < 0 )) && fill_len=0
    printf "${GREEN}โ•”%s%sโ•—${NC}\n" "$top_content" "$(printf 'โ•%.0s' $(seq 1 $fill_len))"
    
    # Convert hue (0โ€“360) to ANSI 256-color code
hue_to_ansi() {
    local hue=$1
    local r g b
    if [ $hue -lt 60 ]; then r=5; g=$((hue*5/60)); b=0
    elif [ $hue -lt 120 ]; then r=$((5-(hue-60)*5/60)); g=5; b=0
    elif [ $hue -lt 180 ]; then r=0; g=5; b=$(((hue-120)*5/60))
    elif [ $hue -lt 240 ]; then r=0; g=$((5-(hue-180)*5/60)); b=5
    elif [ $hue -lt 300 ]; then r=$(((hue-240)*5/60)); g=0; b=5
    else r=5; g=0; b=$((5-(hue-300)*5/60)); fi
    echo $((16 + 36*r + 6*g + b))
}

    for line in "${ascii_banner_lines[@]}"; do
    print_centered_rainbow "$line" "$inner_width"
done

    for i in $(seq 1 $((1 + RANDOM % 2))); do
        local line="${CW_LINES[$((RANDOM % ${#CW_LINES[@]}))]}"
        print_centered "$MAGENTA" "$line" "$inner_width"
    done

    printf "${GREEN}โ• %sโ•ฃ${NC}\n" "$(printf 'โ•%.0s' $(seq 1 $inner_width))"

    # ---- UPDATED MENU ----
    local options=(
        "1 โ†’ Phase 1, Crop and Adjust"
        "2 โ†’ Phase 2, Convert and Export"
        "3 โ†’ Phase 3, Sort and Filter"
        "4 โ†’ Crop and Convert Prints"
        "5 โ†’ Create New Volume"
        "Q โ†’ Quit"
    )
    for opt in "${options[@]}"; do
        local color="$YELLOW"
        [[ "$opt" =~ ^Q ]] && color="$RED"
        print_centered "$color" "$opt" "$inner_width"
    done

    printf "${GREEN}โ• %sโ•ฃ${NC}\n" "$(printf 'โ•%.0s' $(seq 1 $inner_width))"

    local archive_text="Hooks ยฉ 1907"
    local stars_total=$(( inner_width - ${#archive_text} - 2 ))
    local left_stars_count=$(( stars_total / 2 ))
    local right_stars_count=$(( stars_total - left_stars_count ))
    local left_stars=$(generate_stars $left_stars_count)
    local right_stars=$(generate_stars $right_stars_count)
    print_centered "$CYAN" "$left_stars $archive_text $right_stars" "$inner_width"
    printf "${GREEN}โ•š%sโ•${NC}\n" "$(printf 'โ•%.0s' $(seq 1 $inner_width))"
}

# ---------------------------
# Helper: run script with spinner
# ---------------------------
run_with_spinner() {
    local script="$1"
    local args="${2:-}"
    local completion_msg="${3:-Done!}"

    bash "$script" $args &
    local pid=$!

    spinner $pid 2
    echo -e "${GREEN}${completion_msg}${NC}"

    sleep 1
    clear
}

# ---------------------------
# Main loop
# ---------------------------
main_loop() {
    detect_volume

    while true; do
        clear
        draw_menu
        echo
        read -rp "$(printf "${WHITE}Choose an option: ${NC}")" choice

        case "$choice" in
            1)
                run_with_spinner "$SCRIPT_FOLDER/phase1.sh" "$TOP_FOLDER" "โœ… Phase 1 complete."
                ;;
            2)
                run_with_spinner "$SCRIPT_FOLDER/phase2.sh" "$TOP_FOLDER" "โœ… Phase 2 complete."
                ;;
            3)
                run_with_spinner "$SCRIPT_FOLDER/phase3.sh" "$TOP_FOLDER" "โœ… Phase 3 complete."
                ;;
            4)
    echo -e "${CYAN}Starting Phase 1 & 2 combined...${NC}"

    # Phase 1 in foreground
    bash "$SCRIPT_FOLDER/phase1.sh" "$TOP_FOLDER" &
    pid=$!
    
    # Spinner watches PID in background
    spinner $pid 2 &
    spinner_pid=$!
    
    wait $pid       # Wait for Phase 1 to truly finish
    kill $spinner_pid 2>/dev/null
    echo -e "${GREEN}โœ… Phase 1 complete.${NC}"

    # Phase 2 in foreground
    bash "$SCRIPT_FOLDER/phase2.sh" "$TOP_FOLDER" &
    pid=$!
    spinner $pid 2 &
    spinner_pid=$!
    wait $pid
    kill $spinner_pid 2>/dev/null
    echo -e "${GREEN}โœ… Phase 2 complete.${NC}"

    sleep 1
    clear
    ;;
            5)
                read -rp "Enter new volume name: " userVolume
                read -rp "Enter enclosure type: " userEnclosure
                run_with_spinner "$SCRIPT_FOLDER/newvolume.sh" "$userVolume $userEnclosure $SCRIPT_FOLDER" "โœ… New volume created."
                ;;
            Q|q)
                echo -e "${RED}Exitingโ€ฆ${NC}"
                exit 0
                ;;
            *)
                echo "โš ๏ธ Invalid choice."
                sleep 1
                ;;
        esac
    done
}

# ---------------------------
# Start launcher
# ---------------------------
main_loop