1
0
mirror of https://github.com/tw93/Mole.git synced 2026-03-22 18:30:08 +00:00

The animation only appears at the current time

This commit is contained in:
Tw93
2025-10-03 13:55:39 +08:00
parent 452f1263d6
commit dd9fe4f617

77
mole
View File

@@ -214,13 +214,12 @@ show_main_menu() {
local full_draw="${2:-true}"
if [[ "$full_draw" == "true" ]]; then
clear_screen
echo ""
show_brand_banner
echo ""
# Save cursor position right before menu items
printf '\033[s'
else
# Restore to saved position and clear everything from there
printf '\033[u\033[0J'
fi
@@ -229,7 +228,7 @@ show_main_menu() {
show_menu_option 3 "Help & Information - Usage guide and tips" "$([[ $selected -eq 3 ]] && echo true || echo false)"
show_menu_option 4 "Exit - Close Mole" "$([[ $selected -eq 4 ]] && echo true || echo false)"
if [[ "$full_draw" == "true" ]]; then
if [[ -t 0 ]]; then
echo ""
echo -e "${BLUE}↑/↓ to navigate, ENTER to select, Q to quit${NC}"
fi
@@ -237,10 +236,34 @@ show_main_menu() {
# Interactive main menu loop
interactive_main_menu() {
animate_mole_intro
maybe_show_intro() {
if [[ ! -t 1 ]]; then
return
fi
local tty_name
tty_name=$(tty 2>/dev/null || echo "")
if [[ -n "$tty_name" ]]; then
local sanitized
sanitized=$(echo "$tty_name" | tr -c '[:alnum:]_' '_')
local flag_file="/tmp/mole_intro_${sanitized}"
if [[ -f "$flag_file" ]]; then
return
fi
animate_mole_intro
touch "$flag_file" 2>/dev/null || true
else
if [[ -z "${MOLE_INTRO_SHOWN:-}" ]]; then
animate_mole_intro
export MOLE_INTRO_SHOWN=1
fi
fi
}
maybe_show_intro
local current_option=1
local first_draw=true
cleanup_and_exit() {
show_cursor
echo ""
@@ -267,32 +290,7 @@ interactive_main_menu() {
show_cursor
case $current_option in
1)
echo -e "${BLUE}Press SPACE for Dry Run preview, Enter to start cleaning (Esc/q to cancel)${NC}"
# SPACE => dry run; Enter => normal; Esc/q => cancel
IFS= read -r -s -n1 key2 || true
if [[ "$key2" == $'\e' ]]; then
# ESC pressed -> cancel
:
elif [[ "$key2" == ' ' ]]; then
exec "$SCRIPT_DIR/bin/clean.sh" --dry-run
elif [[ "$key2" == $'\n' || -z "$key2" ]]; then
exec "$SCRIPT_DIR/bin/clean.sh"
elif [[ "$key2" == 'q' || "$key2" == 'Q' ]]; then
:
else
exec "$SCRIPT_DIR/bin/clean.sh"
fi
continue
IFS= read -r -s -n1 key2 || true
if [[ "$key2" == $'\n' || -z "$key2" ]]; then
exec "$SCRIPT_DIR/bin/clean.sh"
elif [[ "$key2" == "d" || "$key2" == "D" ]]; then
exec "$SCRIPT_DIR/bin/clean.sh" --dry-run
elif [[ "$key2" == "q" || "$key2" == "Q" ]]; then
:
else
exec "$SCRIPT_DIR/bin/clean.sh"
fi
exec "$SCRIPT_DIR/bin/clean.sh"
;;
2) exec "$SCRIPT_DIR/bin/uninstall.sh" ;;
3) clear; show_help; exit 0 ;;
@@ -304,20 +302,7 @@ interactive_main_menu() {
show_cursor
case $key in
1)
echo -e "${BLUE}Press SPACE for Dry Run preview, Enter to start cleaning (Esc/q to cancel)${NC}"
# SPACE => dry run; Enter => normal; Esc/q => cancel
IFS= read -r -s -n1 key2 || true
if [[ "$key2" == $'\e' ]]; then
:
elif [[ "$key2" == ' ' ]]; then
exec "$SCRIPT_DIR/bin/clean.sh" --dry-run
elif [[ "$key2" == $'\n' || -z "$key2" ]]; then
exec "$SCRIPT_DIR/bin/clean.sh"
elif [[ "$key2" == 'q' || "$key2" == 'Q' ]]; then
:
else
exec "$SCRIPT_DIR/bin/clean.sh"
fi
exec "$SCRIPT_DIR/bin/clean.sh"
;;
2) exec "$SCRIPT_DIR/bin/uninstall.sh" ;;
3) clear; show_help; exit 0 ;;
@@ -334,7 +319,7 @@ main() {
case "${1:-""}" in
"clean")
exec "$SCRIPT_DIR/bin/clean.sh"
exec "$SCRIPT_DIR/bin/clean.sh" "${@:2}"
;;
"uninstall")
exec "$SCRIPT_DIR/bin/uninstall.sh"