From a712969d6571e239f28f32e516beeffb2251508a Mon Sep 17 00:00:00 2001 From: Tw93 Date: Thu, 2 Oct 2025 15:24:02 +0800 Subject: [PATCH] feat: improve arrow key handling to fix stray AB chars; add left/right navigation; update analyze docs --- README.md | 80 +++++++++++++++++++++++++++++++++++++++++++++++++++ lib/common.sh | 40 ++++++++++++++++---------- 2 files changed, 105 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 910f2bb..a89fe50 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,7 @@ - ๐Ÿฆก **Deep System Cleanup** - Remove hidden caches, logs, and temp files in one sweep - ๐Ÿ“ฆ **Smart Uninstall** - Complete app removal with all related files and folders +- ๐Ÿ“Š **Disk Space Analyzer** - Visualize disk usage with lightning-fast mdfind + du hybrid scanning - โšก๏ธ **Fast Interactive UI** - Arrow-key navigation with pagination for large lists - ๐Ÿงน **Massive Space Recovery** - Reclaim 100GB+ of wasted disk space @@ -23,6 +24,7 @@ curl -fsSL https://raw.githubusercontent.com/tw93/mole/main/install.sh | bash mole # Interactive main menu mole clean # Deep system cleanup mole uninstall # Interactive app uninstaller +mole analyze [path]# Analyze disk space (default: home directory) mole --help # Show help ``` @@ -83,6 +85,84 @@ Select Apps to Remove ==================================================================== ``` +### Disk Space Analyzer + +```bash +# Quick start - explore your home directory +$ mole analyze + +# View all disk volumes and major locations +$ mole analyze --all + +๐Ÿ’พ Disk Volumes & Locations + + TYPE SIZE LOCATION + โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ +โ–ถ ๐Ÿ’ฟ 245.3GB Macintosh HD (Root) + ๐Ÿ  89.2GB ~ + ๐Ÿ“š 45.1GB ~/Library + ๐Ÿ“ 33.7GB ~/Downloads + ๐Ÿ“ 18.4GB ~/Documents + ๐Ÿ”Œ 128.0GB External Drive + +# Explore specific directory with progress bar +$ mole analyze ~/Downloads + + ๐Ÿ“Š [โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆ] 100% (25/25) โ† Real-time scanning progress + +๐Ÿ“Š Disk Space Explorer + + Current: ~/Downloads + โ†‘/โ†“: Navigate | โ†’ / Enter: Open folder | โ† / Backspace: Back | q: Quit + + Items (sorted by size): + + TYPE SIZE NAME + โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ + โ–ถ ๐Ÿ“ 33.72GB materials โ† Use arrow keys to select + ๐Ÿ“ 5.67GB learning + ๐Ÿ“ 4.50GB projects + ๐ŸŽฌ 1.68GB recording.mov โ† Files can't be opened + ๐ŸŽฌ 1.58GB presentation.mov + ๐Ÿ“ฆ 1.20GB OldInstaller.dmg + ๐Ÿ“ 2.22GB shared + ๐Ÿ“ 1.78GB recent + ... and 12 more items + +# Press Enter on "materials" folder to drill down: + +๐Ÿ“Š Disk Space Explorer + + Current: ~/Downloads/materials + โ†‘/โ†“: Navigate | โ†’ / Enter: Open folder | โ† / Backspace: Back | q: Quit + + Items (sorted by size): + + โ–ถ ๐Ÿ“ 15.2GB videos โ† Keep drilling down + ๐Ÿ“ 10.1GB documents + ๐Ÿ“ 6.8GB images + ๐ŸŽฌ 2.5GB demo.mov +``` + +**Interactive Navigation:** + +- **Instant startup** - no waiting for initial scan +- **Real-time progress** - visual progress bar when scanning (10+ directories) +- **All volumes view** - `--all` flag shows all disks and major locations +- **Files and folders mixed together**, sorted by size (largest first) +- Shows **top 16 items** per directory (largest items only) +- Use **โ†‘/โ†“** arrow keys to navigate (green arrow โ–ถ shows selection) +- Press **Enter** on a ๐Ÿ“ folder to drill down into it +- Press **Backspace** or **โ†** to go back to parent directory +- Press **q** to quit at any time +- **Color coding**: Red folders >10GB, Yellow >1GB, Blue <1GB +- Files (๐Ÿ“ฆ๐ŸŽฌ๐Ÿ“„๐Ÿ–ผ๏ธ๐Ÿ“Š) are shown but can't be opened (only folders) + +**Performance:** +- **Fast scanning** - real-time progress bar for large directories (10+ folders) +- **Smart caching** - sizes are calculated once and cached during navigation +- **Top 16 only** - shows largest items first, keeps interface clean and fast + ## What Mole Cleans | Category | Targets | Typical Recovery | diff --git a/lib/common.sh b/lib/common.sh index 68cf8b6..9c02028 100755 --- a/lib/common.sh +++ b/lib/common.sh @@ -11,6 +11,7 @@ readonly BLUE="${ESC}[0;34m" readonly YELLOW="${ESC}[1;33m" readonly PURPLE="${ESC}[0;35m" readonly RED="${ESC}[0;31m" +readonly GRAY="${ESC}[0;90m" readonly NC="${ESC}[0m" # Logging configuration @@ -88,14 +89,12 @@ show_cursor() { # Keyboard input handling (simple and robust) read_key() { - local key rest - # Use macOS bash 3.2 compatible read syntax + local key IFS= read -r -s -n 1 key || return 1 - # Some terminals can yield empty on Enter with -n1; treat as ENTER + # Empty = ENTER (some terminals) if [[ -z "$key" ]]; then - echo "ENTER" - return 0 + echo "ENTER"; return 0 fi case "$key" in @@ -105,18 +104,29 @@ read_key() { 'a'|'A') echo "ALL" ;; 'n'|'N') echo "NONE" ;; '?') echo "HELP" ;; + $'\x7f'|$'\b') echo "BACKSPACE" ;; # Support Backspace $'\x1b') - # Read the next two bytes within 1s; works well on macOS bash 3.2 - if IFS= read -r -s -n 2 -t 1 rest 2>/dev/null; then - case "$rest" in - "[A") echo "UP" ;; - "[B") echo "DOWN" ;; - "[C") echo "RIGHT" ;; - "[D") echo "LEFT" ;; - *) echo "OTHER" ;; - esac + # Non-blocking, byte-by-byte escape sequence parsing to avoid leaking 'A'/'B' + local next third + if IFS= read -r -s -n 1 -t 0.02 next 2>/dev/null; then + if [[ "$next" == "[" ]]; then + if IFS= read -r -s -n 1 -t 0.02 third 2>/dev/null; then + case "$third" in + 'A') echo "UP" ;; + 'B') echo "DOWN" ;; + 'C') echo "RIGHT" ;; + 'D') echo "LEFT" ;; + *) echo "OTHER" ;; + esac + else + echo "OTHER" + fi + else + # ESC followed by something else (e.g. ALT key combos) + echo "OTHER" + fi else - # ESC pressed alone - treat as quit + # Bare ESC = quit echo "QUIT" fi ;;