mirror of
https://github.com/tw93/Mole.git
synced 2026-02-04 16:49:41 +00:00
feat: localize app names based on system language and improve UI display width calculation for CJK characters with loading indicator
This commit is contained in:
@@ -3,6 +3,8 @@
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
# Note: get_display_width() is now defined in lib/core/ui.sh
|
||||
|
||||
# Format app info for display
|
||||
format_app_display() {
|
||||
local display_name="$1" size="$2" last_used="$3"
|
||||
@@ -20,18 +22,26 @@ format_app_display() {
|
||||
local fixed_width=28
|
||||
local available_width=$((terminal_width - fixed_width))
|
||||
|
||||
# Set reasonable bounds for name width: 24-35 chars
|
||||
# Set reasonable bounds for name width: 24-35 display width
|
||||
[[ $available_width -lt 24 ]] && available_width=24
|
||||
[[ $available_width -gt 35 ]] && available_width=35
|
||||
|
||||
# Truncate long names if needed
|
||||
local truncated_name="$display_name"
|
||||
if [[ ${#display_name} -gt $available_width ]]; then
|
||||
truncated_name="${display_name:0:$((available_width - 3))}..."
|
||||
fi
|
||||
# Truncate long names if needed (based on display width, not char count)
|
||||
local truncated_name
|
||||
truncated_name=$(truncate_by_display_width "$display_name" "$available_width")
|
||||
|
||||
# Use dynamic column width for better readability
|
||||
printf "%-*s %9s | %s" "$available_width" "$truncated_name" "$size_str" "$compact_last_used"
|
||||
# Get actual display width after truncation
|
||||
local current_display_width
|
||||
current_display_width=$(get_display_width "$truncated_name")
|
||||
|
||||
# Calculate padding needed
|
||||
# Formula: char_count + (available_width - display_width) = padding to add
|
||||
local char_count=${#truncated_name}
|
||||
local padding_needed=$((available_width - current_display_width))
|
||||
local printf_width=$((char_count + padding_needed))
|
||||
|
||||
# Use dynamic column width with corrected padding
|
||||
printf "%-*s %9s | %s" "$printf_width" "$truncated_name" "$size_str" "$compact_last_used"
|
||||
}
|
||||
|
||||
# Global variable to store selection result (bash 3.2 compatible)
|
||||
@@ -46,6 +56,14 @@ select_apps_for_uninstall() {
|
||||
fi
|
||||
|
||||
# Build menu options
|
||||
# Show loading for large lists (formatting can be slow due to width calculations)
|
||||
local app_count=${#apps_data[@]}
|
||||
if [[ $app_count -gt 30 ]]; then
|
||||
if [[ -t 2 ]]; then
|
||||
printf "\rPreparing %d applications... " "$app_count" >&2
|
||||
fi
|
||||
fi
|
||||
|
||||
local -a menu_options=()
|
||||
# Prepare metadata (comma-separated) for sorting/filtering inside the menu
|
||||
local epochs_csv=""
|
||||
@@ -66,6 +84,13 @@ select_apps_for_uninstall() {
|
||||
((idx++))
|
||||
done
|
||||
|
||||
# Clear loading message
|
||||
if [[ $app_count -gt 30 ]]; then
|
||||
if [[ -t 2 ]]; then
|
||||
printf "\r\033[K" >&2
|
||||
fi
|
||||
fi
|
||||
|
||||
# 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
|
||||
|
||||
Reference in New Issue
Block a user