1
0
mirror of https://github.com/tw93/Mole.git synced 2026-02-08 14:24:21 +00:00

feat(menu): add sort (date/name/size), live filter, reverse; visible-only A/N; responsive footer (#34)

Paginated menu:
- Sorting: press S/s to cycle Date → Name → Size; press R/r to reverse.
- Live filter: press F/f to enter; case-insensitive substring; prefix with ' to anchor at start; DELETE to backspace; ENTER to apply; ESC to cancel. Shows “searching…” while rebuilding.
- Selection scope: A (All) and N (None) now work on the currently visible items only (after filter/sort), not the entire list.
- Footer: adds A/N to the help line and wraps only at ' | ' separators so labels are never broken; adapts to terminal width.
- Internals: view_indices mapping for filtered/sorted view; glob-safe matching via _pm_escape_glob; drain_pending_input; robust stty restore; optional MOLE_MANAGED_ALT_SCREEN; cleanup unsets MOLE_READ_KEY_FORCE_CHAR; shellcheck clean.

common.sh:
- read_key supports a raw typing mode (MOLE_READ_KEY_FORCE_CHAR=1) emitting CHAR:<k>; ENTER/DELETE/ESC handled.
- Uppercase A/N/R mappings (ALL/NONE/RETRY), printable-key detection, better ESC sequence handling.

app_selector.sh:
- Builds and exports per-item metadata CSV for epochs and size_kb via MOLE_MENU_META_EPOCHS and MOLE_MENU_META_SIZEKB; unsets them after the menu.
- Menu options keep display text; sorting/filtering use metadata.

uninstall.sh:
- Computes app_size_kb using du -sk for numeric sorting while keeping human-readable size; writes it as the final field.
- load_applications reads the new size_kb field.

Notes:
- Footer grew due to new commands; responsive wrapping prevents mid-word breaks.
- ./tests/run.sh: only the two upstream failures remain (unchanged by this patch).

Co-authored-by: Jonas Bertossa <jonas.bertossa@eoc.ch>
This commit is contained in:
Else00
2025-10-14 03:40:47 +02:00
committed by GitHub
parent 1d1da5af18
commit cfdd414320
4 changed files with 496 additions and 62 deletions

View File

@@ -33,18 +33,44 @@ select_apps_for_uninstall() {
# Build menu options
local -a menu_options=()
# Prepare metadata (comma-separated) for sorting/filtering inside the menu
local epochs_csv=""
local sizekb_csv=""
local idx=0
for app_data in "${apps_data[@]}"; do
# Ignore metadata fields not needed for menu display
IFS='|' read -r _ _ display_name _ size last_used <<< "$app_data"
# Keep extended field 7 (size_kb) if present
IFS='|' read -r epoch _ display_name _ size last_used size_kb <<< "$app_data"
menu_options+=("$(format_app_display "$display_name" "$size" "$last_used")")
# Build csv lists (avoid trailing commas)
if [[ $idx -eq 0 ]]; then
epochs_csv="${epoch:-0}"
sizekb_csv="${size_kb:-0}"
else
epochs_csv+=",${epoch:-0}"
sizekb_csv+=",${size_kb:-0}"
fi
((idx++))
done
# Expose metadata for the paginated menu (optional inputs)
# - MOLE_MENU_META_EPOCHS: numeric last_used_epoch per item
# - MOLE_MENU_META_SIZEKB: numeric size in KB per item
# The menu will gracefully fallback if these are unset or malformed.
export MOLE_MENU_META_EPOCHS="$epochs_csv"
export MOLE_MENU_META_SIZEKB="$sizekb_csv"
# Optional: allow default sort override via env (date|name|size)
# export MOLE_MENU_SORT_DEFAULT="${MOLE_MENU_SORT_DEFAULT:-date}"
# Use paginated menu - result will be stored in MOLE_SELECTION_RESULT
# Note: paginated_multi_select enters alternate screen and handles clearing
MOLE_SELECTION_RESULT=""
paginated_multi_select "Select Apps to Remove" "${menu_options[@]}"
local exit_code=$?
# Clean env leakage for safety
unset MOLE_MENU_META_EPOCHS MOLE_MENU_META_SIZEKB
# leave MOLE_MENU_SORT_DEFAULT untouched if user set it globally
if [[ $exit_code -ne 0 ]]; then
echo "Cancelled"
return 1
@@ -56,11 +82,9 @@ select_apps_for_uninstall() {
fi
# Build selected apps array (global variable in bin/uninstall.sh)
# Clear existing selections - compatible with bash 3.2
selected_apps=()
# Parse indices and build selected apps array
# MOLE_SELECTION_RESULT is comma-separated list of indices from the paginated menu
IFS=',' read -r -a indices_array <<< "$MOLE_SELECTION_RESULT"
for idx in "${indices_array[@]}"; do