@@ -15,9 +15,10 @@ import (
15
15
16
16
// TableOptions contains all options for the table.
17
17
type TableOptions struct {
18
- Columns []int
19
- SortBy int
20
- Style table.Style
18
+ Columns []int
19
+ SortBy int
20
+ Style table.Style
21
+ StyleName string
21
22
}
22
23
23
24
// Column defines a column.
@@ -330,29 +331,84 @@ func printTable(title string, m []Mount, opts TableOptions) {
330
331
s := termenv .String ()
331
332
if usage > 0 {
332
333
if barWidth > 0 {
333
- bw := barWidth - 2
334
- s = termenv .String (fmt .Sprintf ("[%s%s] %5.1f%%" ,
335
- strings .Repeat ("#" , int (usage * float64 (bw ))),
336
- strings .Repeat ("." , bw - int (usage * float64 (bw ))),
337
- usage * 100 ,
338
- ))
334
+ bw := barWidth
335
+ var filledChar , halfChar , emptyChar string
336
+ if opts .StyleName == "unicode" {
337
+ filledChar = "█"
338
+ halfChar = "▌"
339
+ emptyChar = " "
340
+ } else {
341
+ bw -= 2
342
+ filledChar = "#"
343
+ halfChar = "#"
344
+ emptyChar = "."
345
+ }
346
+
347
+ filled := int (usage * float64 (bw ))
348
+ partial := usage * float64 (bw ) - float64 (filled )
349
+ empty := bw - filled
350
+
351
+ var filledStr , emptyStr string
352
+ if partial >= 0.5 {
353
+ if filled > 0 {
354
+ filledStr = strings .Repeat (filledChar , filled - 1 ) + halfChar
355
+ emptyStr = strings .Repeat (emptyChar , empty )
356
+ } else {
357
+ filledStr = halfChar
358
+ emptyStr = strings .Repeat (emptyChar , empty - 1 )
359
+ empty -= 1
360
+ }
361
+ } else {
362
+ filledStr = strings .Repeat (filledChar , filled )
363
+ emptyStr = strings .Repeat (emptyChar , empty )
364
+ }
365
+
366
+ var format string
367
+ if opts .StyleName == "unicode" {
368
+ format = "%s%s %5.1f%%"
369
+ } else {
370
+ format = "[%s%s] %5.1f%%"
371
+ }
372
+
373
+ // Apply colors
374
+ redUsage , _ := strconv .ParseFloat (strings .Split (* usageThreshold , "," )[1 ], 64 )
375
+ yellowUsage , _ := strconv .ParseFloat (strings .Split (* usageThreshold , "," )[0 ], 64 )
376
+
377
+ var fgColor termenv.Color
378
+ switch {
379
+ case usage >= redUsage :
380
+ fgColor = theme .colorRed
381
+ case usage >= yellowUsage :
382
+ fgColor = theme .colorYellow
383
+ default :
384
+ fgColor = theme .colorGreen
385
+ }
386
+
387
+ filledPart := termenv .String (filledStr ).Foreground (fgColor )
388
+ emptyPart := termenv .String (emptyStr )
389
+ if opts .StyleName == "unicode" {
390
+ // Add background to filled part to prevent black spaces in half blocks
391
+ // Use a background color that complements the foreground
392
+ var bgColor termenv.Color
393
+ switch {
394
+ case usage >= redUsage :
395
+ bgColor = env .Color ("#2d1b1b" ) // dark red background
396
+ case usage >= yellowUsage :
397
+ bgColor = env .Color ("#2d2d1b" ) // dark yellow background
398
+ default :
399
+ bgColor = env .Color ("#1b2d1b" ) // dark green background
400
+ }
401
+ filledPart = filledPart .Background (bgColor ).Foreground (fgColor )
402
+ // Use a neutral background for empty areas
403
+ emptyPart = emptyPart .Background (bgColor )
404
+ }
405
+
406
+ s = termenv .String (fmt .Sprintf (format , filledPart , emptyPart , usage * 100 ))
339
407
} else {
340
408
s = termenv .String (fmt .Sprintf ("%5.1f%%" , usage * 100 ))
341
409
}
342
410
}
343
411
344
- // apply color to progress-bar
345
- redUsage , _ := strconv .ParseFloat (strings .Split (* usageThreshold , "," )[1 ], 64 )
346
- yellowUsage , _ := strconv .ParseFloat (strings .Split (* usageThreshold , "," )[0 ], 64 )
347
- switch {
348
- case usage >= redUsage :
349
- s = s .Foreground (theme .colorRed )
350
- case usage >= yellowUsage :
351
- s = s .Foreground (theme .colorYellow )
352
- default :
353
- s = s .Foreground (theme .colorGreen )
354
- }
355
-
356
412
return s .String ()
357
413
}
358
414
0 commit comments