mirror of
https://github.com/tw93/Mole.git
synced 2026-02-15 22:10:03 +00:00
Optimize the key usage experience
This commit is contained in:
28
bin/clean.sh
28
bin/clean.sh
@@ -460,25 +460,25 @@ start_cleanup() {
|
|||||||
|
|
||||||
if [[ -t 0 ]]; then
|
if [[ -t 0 ]]; then
|
||||||
echo ""
|
echo ""
|
||||||
echo -ne "${PURPLE}${ICON_ARROW}${NC} System caches need sudo — ${GREEN}Enter${NC} continue, other key skip: "
|
echo -ne "${PURPLE}${ICON_ARROW}${NC} System caches need sudo — ${GREEN}Enter${NC} continue, ${GRAY}Space${NC} skip: "
|
||||||
|
|
||||||
# Use IFS= and read without -n to allow Ctrl+C to work properly
|
# Use read_key to properly handle all key inputs
|
||||||
IFS= read -r -s -n 1 choice
|
local choice
|
||||||
local read_status=$?
|
choice=$(read_key)
|
||||||
|
|
||||||
# If read was interrupted (Ctrl+C), exit cleanly
|
# Check for cancel (ESC or Q)
|
||||||
if [[ $read_status -ne 0 ]]; then
|
if [[ "$choice" == "QUIT" ]]; then
|
||||||
echo ""
|
|
||||||
exit 130
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ "$choice" == $'\e' ]]; then
|
|
||||||
echo -e " ${GRAY}Cancelled${NC}"
|
echo -e " ${GRAY}Cancelled${NC}"
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Space = skip
|
||||||
|
if [[ "$choice" == "SPACE" ]]; then
|
||||||
|
echo -e " ${GRAY}Skipped${NC}"
|
||||||
|
echo ""
|
||||||
|
SYSTEM_CLEAN=false
|
||||||
# Enter = yes, do system cleanup
|
# Enter = yes, do system cleanup
|
||||||
if [[ -z "$choice" ]] || [[ "$choice" == $'\n' ]]; then
|
elif [[ "$choice" == "ENTER" ]]; then
|
||||||
printf "\r\033[K" # Clear the prompt line
|
printf "\r\033[K" # Clear the prompt line
|
||||||
if request_sudo_access "System cleanup requires admin access"; then
|
if request_sudo_access "System cleanup requires admin access"; then
|
||||||
SYSTEM_CLEAN=true
|
SYSTEM_CLEAN=true
|
||||||
@@ -514,10 +514,8 @@ start_cleanup() {
|
|||||||
echo -e "${YELLOW}Authentication failed${NC}, continuing with user-level cleanup"
|
echo -e "${YELLOW}Authentication failed${NC}, continuing with user-level cleanup"
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
# ESC or other key = no system cleanup
|
# Other keys (including arrow keys) = skip, no message needed
|
||||||
SYSTEM_CLEAN=false
|
SYSTEM_CLEAN=false
|
||||||
echo ""
|
|
||||||
echo -e "${GRAY}Skipped system cleanup, user-level only${NC}"
|
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
SYSTEM_CLEAN=false
|
SYSTEM_CLEAN=false
|
||||||
|
|||||||
@@ -503,6 +503,7 @@ main() {
|
|||||||
echo -ne "${PURPLE}${ICON_ARROW}${NC} System optimizations need admin access — ${GREEN}Enter${NC} Touch ID/password, ${GRAY}ESC${NC} cancel: "
|
echo -ne "${PURPLE}${ICON_ARROW}${NC} System optimizations need admin access — ${GREEN}Enter${NC} Touch ID/password, ${GRAY}ESC${NC} cancel: "
|
||||||
|
|
||||||
IFS= read -r -s -n1 key || key=""
|
IFS= read -r -s -n1 key || key=""
|
||||||
|
drain_pending_input # Clean up any escape sequence remnants
|
||||||
case "$key" in
|
case "$key" in
|
||||||
$'\e' | q | Q)
|
$'\e' | q | Q)
|
||||||
echo ""
|
echo ""
|
||||||
|
|||||||
@@ -144,6 +144,7 @@ show_menu() {
|
|||||||
if is_touchid_configured; then
|
if is_touchid_configured; then
|
||||||
echo -ne "${PURPLE}☛${NC} Press ${GREEN}Enter${NC} to disable, ${GRAY}Q${NC} to quit: "
|
echo -ne "${PURPLE}☛${NC} Press ${GREEN}Enter${NC} to disable, ${GRAY}Q${NC} to quit: "
|
||||||
IFS= read -r -s -n1 key || key=""
|
IFS= read -r -s -n1 key || key=""
|
||||||
|
drain_pending_input # Clean up any escape sequence remnants
|
||||||
echo ""
|
echo ""
|
||||||
|
|
||||||
case "$key" in
|
case "$key" in
|
||||||
@@ -162,6 +163,7 @@ show_menu() {
|
|||||||
else
|
else
|
||||||
echo -ne "${PURPLE}☛${NC} Press ${GREEN}Enter${NC} to enable, ${GRAY}Q${NC} to quit: "
|
echo -ne "${PURPLE}☛${NC} Press ${GREEN}Enter${NC} to enable, ${GRAY}Q${NC} to quit: "
|
||||||
IFS= read -r -s -n1 key || key=""
|
IFS= read -r -s -n1 key || key=""
|
||||||
|
drain_pending_input # Clean up any escape sequence remnants
|
||||||
|
|
||||||
case "$key" in
|
case "$key" in
|
||||||
$'\e') # ESC
|
$'\e') # ESC
|
||||||
|
|||||||
@@ -289,6 +289,7 @@ read_key() {
|
|||||||
$'\n' | $'\r') echo "ENTER" ;;
|
$'\n' | $'\r') echo "ENTER" ;;
|
||||||
' ') echo "SPACE" ;;
|
' ') echo "SPACE" ;;
|
||||||
'q' | 'Q') echo "QUIT" ;;
|
'q' | 'Q') echo "QUIT" ;;
|
||||||
|
'h' | 'H') echo "HELP" ;;
|
||||||
'R') echo "RETRY" ;;
|
'R') echo "RETRY" ;;
|
||||||
'o' | 'O') echo "OPEN" ;;
|
'o' | 'O') echo "OPEN" ;;
|
||||||
'/') echo "FILTER" ;; # Trigger filter mode
|
'/') echo "FILTER" ;; # Trigger filter mode
|
||||||
@@ -368,13 +369,13 @@ drain_pending_input() {
|
|||||||
# Mouse wheel scrolling can generate rapid sequences like B^[OB^[OB^[O...
|
# Mouse wheel scrolling can generate rapid sequences like B^[OB^[OB^[O...
|
||||||
while IFS= read -r -s -n 1 -t 0.01 _ 2> /dev/null; do
|
while IFS= read -r -s -n 1 -t 0.01 _ 2> /dev/null; do
|
||||||
((drained++))
|
((drained++))
|
||||||
# Higher safety limit for mouse wheel sequences
|
# Safety limit for mouse wheel sequences
|
||||||
[[ $drained -gt 1000 ]] && break
|
[[ $drained -gt 200 ]] && break
|
||||||
done
|
done
|
||||||
# Second pass with even shorter timeout to catch any remaining input
|
# Second pass with even shorter timeout to catch any remaining input
|
||||||
while IFS= read -r -s -n 1 -t 0.001 _ 2> /dev/null; do
|
while IFS= read -r -s -n 1 -t 0.001 _ 2> /dev/null; do
|
||||||
((drained++))
|
((drained++))
|
||||||
[[ $drained -gt 1500 ]] && break
|
[[ $drained -gt 500 ]] && break
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -868,6 +869,7 @@ prompt_action() {
|
|||||||
echo ""
|
echo ""
|
||||||
echo -ne "${PURPLE}${ICON_ARROW}${NC} Press ${GREEN}Enter${NC} to ${action}, ${GRAY}ESC${NC} to ${cancel}: "
|
echo -ne "${PURPLE}${ICON_ARROW}${NC} Press ${GREEN}Enter${NC} to ${action}, ${GRAY}ESC${NC} to ${cancel}: "
|
||||||
IFS= read -r -s -n1 key || key=""
|
IFS= read -r -s -n1 key || key=""
|
||||||
|
drain_pending_input # Clean up any escape sequence remnants
|
||||||
|
|
||||||
case "$key" in
|
case "$key" in
|
||||||
$'\e') # ESC
|
$'\e') # ESC
|
||||||
@@ -891,6 +893,7 @@ confirm_prompt() {
|
|||||||
local message="$1"
|
local message="$1"
|
||||||
echo -n "$message (Enter=OK / ESC q=Cancel): "
|
echo -n "$message (Enter=OK / ESC q=Cancel): "
|
||||||
IFS= read -r -s -n1 _key || _key=""
|
IFS= read -r -s -n1 _key || _key=""
|
||||||
|
drain_pending_input # Clean up any escape sequence remnants
|
||||||
case "$_key" in
|
case "$_key" in
|
||||||
$'\e' | q | Q)
|
$'\e' | q | Q)
|
||||||
echo ""
|
echo ""
|
||||||
|
|||||||
@@ -27,21 +27,6 @@ _pm_parse_csv_to_array() {
|
|||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
# Non-blocking input drain (bash 3.2) - improved for mouse wheel
|
|
||||||
drain_pending_input() {
|
|
||||||
local _k drained=0
|
|
||||||
# Multiple passes to handle mouse wheel burst sequences
|
|
||||||
while IFS= read -r -s -n 1 -t 0.01 _k 2> /dev/null; do
|
|
||||||
((drained++))
|
|
||||||
[[ $drained -gt 1000 ]] && break
|
|
||||||
done
|
|
||||||
# Second pass with shorter timeout
|
|
||||||
while IFS= read -r -s -n 1 -t 0.001 _k 2> /dev/null; do
|
|
||||||
((drained++))
|
|
||||||
[[ $drained -gt 1500 ]] && break
|
|
||||||
done
|
|
||||||
}
|
|
||||||
|
|
||||||
# Main paginated multi-select menu function
|
# Main paginated multi-select menu function
|
||||||
paginated_multi_select() {
|
paginated_multi_select() {
|
||||||
local title="$1"
|
local title="$1"
|
||||||
|
|||||||
@@ -137,6 +137,7 @@ batch_uninstall_applications() {
|
|||||||
echo -ne "${PURPLE}${ICON_ARROW}${NC} ${removal_note}. Press ${GREEN}Enter${NC} to confirm, ${GRAY}ESC${NC} to cancel: "
|
echo -ne "${PURPLE}${ICON_ARROW}${NC} ${removal_note}. Press ${GREEN}Enter${NC} to confirm, ${GRAY}ESC${NC} to cancel: "
|
||||||
|
|
||||||
IFS= read -r -s -n1 key || key=""
|
IFS= read -r -s -n1 key || key=""
|
||||||
|
drain_pending_input # Clean up any escape sequence remnants
|
||||||
case "$key" in
|
case "$key" in
|
||||||
$'\e' | q | Q)
|
$'\e' | q | Q)
|
||||||
echo ""
|
echo ""
|
||||||
|
|||||||
3
mole
3
mole
@@ -343,6 +343,7 @@ remove_mole() {
|
|||||||
|
|
||||||
# Read single key
|
# Read single key
|
||||||
IFS= read -r -s -n1 key || key=""
|
IFS= read -r -s -n1 key || key=""
|
||||||
|
drain_pending_input # Clean up any escape sequence remnants
|
||||||
case "$key" in
|
case "$key" in
|
||||||
$'\e')
|
$'\e')
|
||||||
echo -e "${GRAY}Cancelled${NC}"
|
echo -e "${GRAY}Cancelled${NC}"
|
||||||
@@ -531,7 +532,7 @@ interactive_main_menu() {
|
|||||||
4) exec "$SCRIPT_DIR/bin/analyze.sh" ;;
|
4) exec "$SCRIPT_DIR/bin/analyze.sh" ;;
|
||||||
esac
|
esac
|
||||||
;;
|
;;
|
||||||
"h" | "H")
|
"HELP")
|
||||||
show_cursor
|
show_cursor
|
||||||
clear
|
clear
|
||||||
show_help
|
show_help
|
||||||
|
|||||||
Reference in New Issue
Block a user