@@ -13,16 +13,41 @@ import (
1313 "github.com/Tyooughtul/lume/pkg/scanner"
1414)
1515
16+ // ANSI color helpers for diagnose output
17+ const (
18+ colorReset = "\033 [0m"
19+ colorRed = "\033 [31m"
20+ colorGreen = "\033 [32m"
21+ colorYellow = "\033 [33m"
22+ colorCyan = "\033 [36m"
23+ colorDim = "\033 [2m"
24+ colorBold = "\033 [1m"
25+ )
26+
27+ // sizeTag returns a colored severity indicator for a given size
28+ func sizeTag (size int64 , canClean bool ) string {
29+ if ! canClean {
30+ return colorDim + "[L]" + colorReset
31+ }
32+ if size > 1024 * 1024 * 1024 {
33+ return colorRed + colorBold + "[!]" + colorReset
34+ }
35+ if size > 100 * 1024 * 1024 {
36+ return colorYellow + "[~]" + colorReset
37+ }
38+ return colorGreen + "[+]" + colorReset
39+ }
40+
1641func diagnose () {
1742 fmt .Println ("╔════════════════════════════════════════════════════════════╗" )
1843 fmt .Println ("║ Lume - Disk Space Diagnostic Tool ║" )
1944 fmt .Println ("╚════════════════════════════════════════════════════════════╝" )
2045 fmt .Println ()
2146
22- homeDir , _ := os . UserHomeDir ()
47+ homeDir := scanner . GetRealHomeDir ()
2348
2449 // 1. Quick analysis of main directories
25- fmt .Println ("📊 Analyzing main directories..." )
50+ fmt .Println ("[*] Analyzing main directories..." )
2651 fmt .Println ()
2752
2853 keyDirs := []struct {
@@ -71,22 +96,23 @@ func diagnose() {
7196 })
7297
7398 for _ , r := range results {
99+ tag := sizeTag (r .size , true )
74100 sizeStr := humanize .Bytes (uint64 (r .size ))
75- if r . size > 1024 * 1024 * 1024 {
76- sizeStr = "🔴 " + sizeStr
77- } else if r . size > 100 * 1024 * 1024 {
78- sizeStr = "🟡 " + sizeStr
79- } else {
80- sizeStr = "🟢 " + sizeStr
101+ // pad manually: tag has ANSI codes, so use fixed field for the visible part
102+ visible := fmt . Sprintf ( "%s %s" , tag , sizeStr )
103+ // ANSI codes don't take visual space; right-align within 17 char column
104+ pad := 17 - ( 3 + 1 + len ( sizeStr )) // [!] + space + size
105+ if pad < 0 {
106+ pad = 0
81107 }
82- fmt .Printf ("│ %-39s │ %17s │\n " , r .name , sizeStr )
108+ fmt .Printf ("│ %-39s │ %s%s │\n " , r .name , strings . Repeat ( " " , pad ), visible )
83109 }
84110
85111 fmt .Println ("└─────────────────────────────────────────┴───────────────────┘" )
86112 fmt .Println ()
87113
88114 // 2. Detailed scan of junk directories
89- fmt .Println ("🗑 Scanning junk file directories..." )
115+ fmt .Println ("[*] Scanning junk file directories..." )
90116 fmt .Println ()
91117
92118 junkScanner := scanner .NewEnhancedJunkScanner ()
@@ -134,14 +160,14 @@ func diagnose() {
134160 name = name [:36 ] + "..."
135161 }
136162
163+ tag := sizeTag (target .Size , true )
137164 sizeStr := humanize .Bytes (uint64 (target .Size ))
138- if target .Size > 1024 * 1024 * 1024 {
139- sizeStr = "🔴 " + sizeStr
140- } else if target .Size > 100 * 1024 * 1024 {
141- sizeStr = "🟡 " + sizeStr
165+ pad := 17 - (3 + 1 + len (sizeStr ))
166+ if pad < 0 {
167+ pad = 0
142168 }
143-
144- fmt .Printf ("│ %-39s │ %17s │\n " , name , sizeStr )
169+ visible := fmt . Sprintf ( "%s %s" , tag , sizeStr )
170+ fmt .Printf ("│ %-39s │ %s%s │\n " , name , strings . Repeat ( " " , pad ), visible )
145171 }
146172
147173 fmt .Println ("└─────────────────────────────────────────┴───────────────────┘" )
@@ -154,12 +180,12 @@ func diagnose() {
154180 }
155181
156182 fmt .Println ("═════════════════════════════════════════════════════════════" )
157- fmt .Printf ("💾 Total reclaimable space: %s\n " , humanize .Bytes (uint64 (totalJunk )))
183+ fmt .Printf ("[ Total] Reclaimable space: %s\n " , humanize .Bytes (uint64 (totalJunk )))
158184 fmt .Println ("═════════════════════════════════════════════════════════════" )
159185 fmt .Println ()
160186
161187 // 4. System Data Analysis
162- fmt .Println ("🔍 Analyzing System Data (hidden space usage)..." )
188+ fmt .Println ("[*] Analyzing System Data (hidden space usage)..." )
163189 fmt .Println ()
164190
165191 systemScanner := scanner .NewSystemDataScanner ()
@@ -182,31 +208,29 @@ func diagnose() {
182208 name = name [:36 ] + "..."
183209 }
184210
211+ tag := sizeTag (item .Size , item .CanClean )
185212 sizeStr := humanize .Bytes (uint64 (item .Size ))
186- if ! item .CanClean {
187- sizeStr = "🔒 " + sizeStr
188- } else if item .Size > 1024 * 1024 * 1024 {
189- sizeStr = "🔴 " + sizeStr
190- } else if item .Size > 100 * 1024 * 1024 {
191- sizeStr = "🟡 " + sizeStr
213+ pad := 17 - (3 + 1 + len (sizeStr ))
214+ if pad < 0 {
215+ pad = 0
192216 }
193-
194- fmt .Printf ("│ %-39s │ %17s │\n " , name , sizeStr )
217+ visible := fmt . Sprintf ( "%s %s" , tag , sizeStr )
218+ fmt .Printf ("│ %-39s │ %s%s │\n " , name , strings . Repeat ( " " , pad ), visible )
195219 }
196220
197221 fmt .Println ("└─────────────────────────────────────────┴───────────────────┘" )
198222 fmt .Println ()
199223
200224 totalSystem := systemScanner .GetTotalSize ()
201225 cleanableSystem := systemScanner .GetCleanableSize ()
202- fmt .Printf ("💾 Total System Data: %s\n " , humanize .Bytes (uint64 (totalSystem )))
203- fmt .Printf ("✅ Cleanable System Data: %s\n " , humanize .Bytes (uint64 (cleanableSystem )))
226+ fmt .Printf ("[ Total] System Data: %s\n " , humanize .Bytes (uint64 (totalSystem )))
227+ fmt .Printf ("[OK] Cleanable System Data: %s\n " , humanize .Bytes (uint64 (cleanableSystem )))
204228 fmt .Println ()
205229 }
206230
207231 // 5. Show scan errors if any
208232 if errs := junkScanner .GetErrors (); len (errs ) > 0 {
209- fmt .Printf ("⚠️ %d warnings during scan (usually permission issues):\n " , len (errs ))
233+ fmt .Printf ("[!] %d warnings during scan (usually permission issues):\n " , len (errs ))
210234 for i , err := range errs {
211235 if i >= 5 {
212236 fmt .Printf (" ... and %d more\n " , len (errs )- 5 )
@@ -218,12 +242,12 @@ func diagnose() {
218242 }
219243
220244 // 6. Tips
221- fmt .Println ("💡 Tips:" )
245+ fmt .Println ("[ Tips] :" )
222246 fmt .Println (" 1. If some directories show 'No access', try running with sudo" )
223- fmt .Println (" 2. For 🔴 large directories, use TUI mode to view details" )
247+ fmt .Printf (" 2. For %s%s[!]%s large directories, use TUI mode to view details\n " , colorRed , colorBold , colorReset )
224248 fmt .Println (" 3. Docker data is usually in ~/Library/Containers/com.docker.docker" )
225249 fmt .Println (" 4. Xcode cache can be very large, DerivedData is safe to clean" )
226- fmt .Println (" 5. 🔒 items are system data that cannot be safely cleaned" )
250+ fmt .Printf (" 5. %s[L]%s items are system data that cannot be safely cleaned\n " , colorDim , colorReset )
227251 fmt .Println (" 6. Time Machine snapshots are automatically managed by macOS" )
228252 fmt .Println (" 7. System swap files are automatically managed by the OS" )
229253 fmt .Println ()
0 commit comments