1
0
mirror of https://github.com/tw93/Mole.git synced 2026-02-04 18:34:46 +00:00

Adjust uninstall menu footer controls order

This commit is contained in:
Tw93
2025-12-29 15:13:54 +08:00
parent 2a6930388f
commit 492f3f77d6

View File

@@ -479,6 +479,22 @@ paginated_multi_select() {
# Footer: single line with controls # Footer: single line with controls
local sep=" ${GRAY}|${NC} " local sep=" ${GRAY}|${NC} "
# Helper to calculate display length without ANSI codes
_calc_len() {
local text="$1"
local stripped
stripped=$(printf "%s" "$text" | LC_ALL=C awk '{gsub(/\033\[[0-9;]*[A-Za-z]/,""); print}')
printf "%d" "${#stripped}"
}
# Common menu items
local nav="${GRAY}${ICON_NAV_UP}${ICON_NAV_DOWN}${NC}"
local space_select="${GRAY}Space Select${NC}"
local space="${GRAY}Space${NC}"
local enter="${GRAY}Enter${NC}"
local exit="${GRAY}Q Exit${NC}"
if [[ "$filter_mode" == "true" ]]; then if [[ "$filter_mode" == "true" ]]; then
# Filter mode: simple controls without sort # Filter mode: simple controls without sort
local -a _segs_filter=( local -a _segs_filter=(
@@ -489,106 +505,60 @@ paginated_multi_select() {
) )
_print_wrapped_controls "$sep" "${_segs_filter[@]}" _print_wrapped_controls "$sep" "${_segs_filter[@]}"
else else
# Normal mode - single line compact format # Normal mode - prepare dynamic items
local reverse_arrow="↑" local reverse_arrow="↑"
[[ "$sort_reverse" == "true" ]] && reverse_arrow="↓" [[ "$sort_reverse" == "true" ]] && reverse_arrow="↓"
# Determine filter text based on whether filter is active
local filter_text="/ Search" local filter_text="/ Search"
[[ -n "$applied_query" ]] && filter_text="/ Clear" [[ -n "$applied_query" ]] && filter_text="/ Clear"
local refresh="${GRAY}R Refresh${NC}"
local search="${GRAY}${filter_text}${NC}"
local sort_ctrl="${GRAY}S ${sort_status}${NC}"
local order_ctrl="${GRAY}O ${reverse_arrow}${NC}"
if [[ "$has_metadata" == "true" ]]; then if [[ "$has_metadata" == "true" ]]; then
if [[ -n "$applied_query" ]]; then if [[ -n "$applied_query" ]]; then
# Filtering: hide sort controls # Filtering active: hide sort controls
local -a _segs_all=( local -a _segs_all=("$nav" "$space" "$enter" "$refresh" "$search" "$exit")
"${GRAY}${ICON_NAV_UP}${ICON_NAV_DOWN}${NC}"
"${GRAY}Space${NC}"
"${GRAY}Enter${NC}"
"${GRAY}${filter_text}${NC}"
"${GRAY}Q Exit${NC}"
)
_print_wrapped_controls "$sep" "${_segs_all[@]}" _print_wrapped_controls "$sep" "${_segs_all[@]}"
else else
# Normal: show full controls (without O ↑/↓ to save space) # Normal: show full controls with dynamic reduction
# Dynamically reduce controls if they won't fit
local term_width="${COLUMNS:-}" local term_width="${COLUMNS:-}"
[[ -z "$term_width" ]] && term_width=$(tput cols 2> /dev/null || echo 80) [[ -z "$term_width" ]] && term_width=$(tput cols 2> /dev/null || echo 80)
# Helper to calculate display length without ANSI codes # Level 0: Full controls
_calc_len() { local -a _segs=("$nav" "$space_select" "$enter" "$refresh" "$search" "$sort_ctrl" "$order_ctrl" "$exit")
local text="$1"
local stripped
stripped=$(printf "%s" "$text" | LC_ALL=C awk '{gsub(/\033\[[0-9;]*[A-Za-z]/,""); print}')
printf "%d" "${#stripped}"
}
# Build full controls and calculate total width # Calculate width
local -a _segs_full=( local total_len=0 seg_count=${#_segs[@]}
"${GRAY}${ICON_NAV_UP}${ICON_NAV_DOWN}${NC}" for i in "${!_segs[@]}"; do
"${GRAY}Space Select${NC}" total_len=$((total_len + $(_calc_len "${_segs[i]}")))
"${GRAY}Enter${NC}"
"${GRAY}R Refresh${NC}"
"${GRAY}${filter_text}${NC}"
"${GRAY}S ${sort_status}${NC}"
"${GRAY}Q Exit${NC}"
)
# Calculate total width with separators
local total_len=0 seg_count=${#_segs_full[@]}
local i
for i in "${!_segs_full[@]}"; do
total_len=$((total_len + $(_calc_len "${_segs_full[i]}")))
# Add separator width (3 chars: " | ")
[[ $i -lt $((seg_count - 1)) ]] && total_len=$((total_len + 3)) [[ $i -lt $((seg_count - 1)) ]] && total_len=$((total_len + 3))
done done
# Multi-level fallback: progressively remove items if too wide # Level 1: Remove "Space Select"
if [[ $total_len -gt $term_width ]]; then if [[ $total_len -gt $term_width ]]; then
# Level 1: Remove "R Refresh" (least critical) _segs=("$nav" "$enter" "$refresh" "$search" "$sort_ctrl" "$order_ctrl" "$exit")
local -a _segs_reduced=(
"${GRAY}${ICON_NAV_UP}${ICON_NAV_DOWN}${NC}"
"${GRAY}Space Select${NC}"
"${GRAY}Enter${NC}"
"${GRAY}${filter_text}${NC}"
"${GRAY}S ${sort_status}${NC}"
"${GRAY}Q Exit${NC}"
)
# Recalculate length
total_len=0 total_len=0
seg_count=${#_segs_reduced[@]} seg_count=${#_segs[@]}
for i in "${!_segs_reduced[@]}"; do for i in "${!_segs[@]}"; do
total_len=$((total_len + $(_calc_len "${_segs_reduced[i]}"))) total_len=$((total_len + $(_calc_len "${_segs[i]}")))
[[ $i -lt $((seg_count - 1)) ]] && total_len=$((total_len + 3)) [[ $i -lt $((seg_count - 1)) ]] && total_len=$((total_len + 3))
done done
# Level 2: If still too wide, also remove "S ${sort_status}" # Level 2: Remove "S ${sort_status}"
if [[ $total_len -gt $term_width ]]; then if [[ $total_len -gt $term_width ]]; then
local -a _segs_all=( _segs=("$nav" "$enter" "$refresh" "$search" "$order_ctrl" "$exit")
"${GRAY}${ICON_NAV_UP}${ICON_NAV_DOWN}${NC}"
"${GRAY}Space Select${NC}"
"${GRAY}Enter${NC}"
"${GRAY}${filter_text}${NC}"
"${GRAY}Q Exit${NC}"
)
else
local -a _segs_all=("${_segs_reduced[@]}")
fi fi
else
local -a _segs_all=("${_segs_full[@]}")
fi fi
_print_wrapped_controls "$sep" "${_segs_all[@]}" _print_wrapped_controls "$sep" "${_segs[@]}"
fi fi
else else
# Without metadata: basic controls # Without metadata: basic controls
local -a _segs_simple=( local -a _segs_simple=("$nav" "$space_select" "$enter" "$refresh" "$search" "$exit")
"${GRAY}${ICON_NAV_UP}${ICON_NAV_DOWN}${NC}"
"${GRAY}Space Select${NC}"
"${GRAY}Enter${NC}"
"${GRAY}${filter_text}${NC}"
"${GRAY}Q Exit${NC}"
)
_print_wrapped_controls "$sep" "${_segs_simple[@]}" _print_wrapped_controls "$sep" "${_segs_simple[@]}"
fi fi
fi fi