1
0
mirror of https://github.com/tw93/Mole.git synced 2026-02-10 00:54:15 +00:00

feat(ui): add Ctrl+U support and optimize paginated menu performance

This commit is contained in:
tw93
2026-02-07 10:23:35 +08:00
parent f3b288a21b
commit 02843dee74
3 changed files with 428 additions and 370 deletions

View File

@@ -12,9 +12,12 @@ format_app_display() {
# Use common function from ui.sh to format last used time
local compact_last_used
compact_last_used=$(format_last_used_summary "$last_used")
if [[ -z "$compact_last_used" || "$compact_last_used" == "Unknown" || "$compact_last_used" == "Never" ]]; then
compact_last_used="..."
fi
# Format size
local size_str="Unknown"
local size_str="..."
[[ "$size" != "0" && "$size" != "" && "$size" != "Unknown" ]] && size_str="$size"
# Calculate available width for app name based on terminal width
@@ -114,10 +117,14 @@ select_apps_for_uninstall() {
local epochs_csv=""
local sizekb_csv=""
local -a names_arr=()
local has_epoch_metadata=false
local has_size_metadata=false
local idx=0
for app_data in "${apps_data[@]}"; do
IFS='|' read -r epoch _ display_name _ size last_used size_kb <<< "$app_data"
menu_options+=("$(format_app_display "$display_name" "$size" "$last_used" "$terminal_width" "$max_name_width")")
[[ "${epoch:-0}" =~ ^[0-9]+$ && "${epoch:-0}" -gt 0 ]] && has_epoch_metadata=true
[[ "${size_kb:-0}" =~ ^[0-9]+$ && "${size_kb:-0}" -gt 0 ]] && has_size_metadata=true
if [[ $idx -eq 0 ]]; then
epochs_csv="${epoch:-0}"
sizekb_csv="${size_kb:-0}"
@@ -143,8 +150,16 @@ select_apps_for_uninstall() {
# - 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"
if [[ $has_epoch_metadata == true ]]; then
export MOLE_MENU_META_EPOCHS="$epochs_csv"
else
unset MOLE_MENU_META_EPOCHS
fi
if [[ $has_size_metadata == true ]]; then
export MOLE_MENU_META_SIZEKB="$sizekb_csv"
else
unset MOLE_MENU_META_SIZEKB
fi
export MOLE_MENU_FILTER_NAMES="$names_newline"
# Use paginated menu - result will be stored in MOLE_SELECTION_RESULT
@@ -157,11 +172,6 @@ select_apps_for_uninstall() {
unset MOLE_MENU_META_EPOCHS MOLE_MENU_META_SIZEKB
# leave MOLE_MENU_SORT_DEFAULT untouched if user set it globally
# Refresh signal handling
if [[ $exit_code -eq 10 ]]; then
return 10
fi
if [[ $exit_code -ne 0 ]]; then
return 1
fi