@@ -342,89 +342,84 @@ func printTable(title string, m []Mount, opts TableOptions) {
342342 // Define barTransformerFunc
343343 barTransformerFunc := func (val interface {}) string {
344344 usage := val .(float64 )
345- s := termenv .String ()
346- if usage > 0 {
347- if barWidth > 0 {
348- bw := barWidth
349- var filledChar , halfChar , emptyChar string
350- if opts .StyleName == "unicode" {
351- filledChar = "█"
352- halfChar = "▌"
353- emptyChar = " "
354- } else {
355- bw -= 2
356- filledChar = "#"
357- halfChar = "#"
358- emptyChar = "."
359- }
345+ if barWidth <= 0 {
346+ s := fmt .Sprintf ("%*s" , percentWidth , fmt .Sprintf ("%.1f%%" , usage * 100 ))
347+ return termenv .String (s ).String ()
348+ }
360349
361- filled := int (usage * float64 (bw ))
362- partial := usage * float64 (bw ) - float64 (filled )
363- empty := bw - filled
350+ bw := barWidth
351+ var filledChar , halfChar , emptyChar string
352+ if opts .StyleName == "unicode" {
353+ filledChar = "█"
354+ halfChar = "▌"
355+ emptyChar = " "
356+ } else {
357+ bw -= 2
358+ filledChar = "#"
359+ halfChar = "#"
360+ emptyChar = "."
361+ }
364362
365- var filledStr , emptyStr string
366- filledStr = strings .Repeat (filledChar , filled )
363+ filled := int (usage * float64 (bw ))
364+ partial := usage * float64 (bw ) - float64 (filled )
365+ empty := bw - filled
367366
368- // If we have a sufficiently large partial, render a half block.
369- if partial >= 0.5 {
370- filledStr += halfChar
371- empty --
372- }
367+ var filledStr , emptyStr string
368+ filledStr = strings .Repeat (filledChar , filled )
373369
374- if empty < 0 {
375- empty = 0
376- }
377- emptyStr = strings .Repeat (emptyChar , empty )
370+ // If we have a sufficiently large partial, render a half block.
371+ if partial >= 0.5 {
372+ filledStr += halfChar
373+ empty --
374+ }
378375
379- var format string
380- if opts .StyleName == "unicode" {
381- format = "%s%s %*s"
382- } else {
383- format = "[%s%s] %*s"
384- }
376+ if empty < 0 {
377+ empty = 0
378+ }
379+ emptyStr = strings .Repeat (emptyChar , empty )
385380
386- // Apply colors
387- redUsage , _ := strconv .ParseFloat (strings .Split (* usageThreshold , "," )[1 ], 64 )
388- yellowUsage , _ := strconv .ParseFloat (strings .Split (* usageThreshold , "," )[0 ], 64 )
389-
390- var fgColor termenv.Color
391- switch {
392- case usage >= redUsage :
393- fgColor = theme .colorRed
394- case usage >= yellowUsage :
395- fgColor = theme .colorYellow
396- default :
397- fgColor = theme .colorGreen
398- }
381+ var format string
382+ if opts .StyleName == "unicode" {
383+ format = "%s%s %*s"
384+ } else {
385+ format = "[%s%s] %*s"
386+ }
399387
400- filledPart := termenv .String (filledStr ).Foreground (fgColor )
401- emptyPart := termenv .String (emptyStr )
402- if opts .StyleName == "unicode" {
403- // Add background to filled part to prevent black spaces in half blocks
404- // Use a background color that complements the foreground
405- var bgColor termenv.Color
406- switch {
407- case usage >= redUsage :
408- bgColor = theme .colorBgRed
409- case usage >= yellowUsage :
410- bgColor = theme .colorBgYellow
411- default :
412- bgColor = theme .colorBgGreen
413- }
414- filledPart = filledPart .Background (bgColor ).Foreground (fgColor )
415- // Use a neutral background for empty areas
416- emptyPart = emptyPart .Background (bgColor )
417- }
388+ // Apply colors
389+ redUsage , _ := strconv .ParseFloat (strings .Split (* usageThreshold , "," )[1 ], 64 )
390+ yellowUsage , _ := strconv .ParseFloat (strings .Split (* usageThreshold , "," )[0 ], 64 )
391+
392+ var fgColor termenv.Color
393+ switch {
394+ case usage >= redUsage :
395+ fgColor = theme .colorRed
396+ case usage >= yellowUsage :
397+ fgColor = theme .colorYellow
398+ default :
399+ fgColor = theme .colorGreen
400+ }
418401
419- percentStr := fmt .Sprintf ("%.1f%%" , usage * 100 )
420- s = termenv .String (fmt .Sprintf (format , filledPart , emptyPart , percentWidth , percentStr ))
421- } else {
422- percentStr := fmt .Sprintf ("%.1f%%" , usage * 100 )
423- s = termenv .String (fmt .Sprintf ("%*s" , percentWidth , percentStr ))
402+ filledPart := termenv .String (filledStr ).Foreground (fgColor )
403+ emptyPart := termenv .String (emptyStr )
404+ if opts .StyleName == "unicode" {
405+ // Add background to filled part to prevent black spaces in half blocks
406+ // Use a background color that complements the foreground
407+ var bgColor termenv.Color
408+ switch {
409+ case usage >= redUsage :
410+ bgColor = theme .colorBgRed
411+ case usage >= yellowUsage :
412+ bgColor = theme .colorBgYellow
413+ default :
414+ bgColor = theme .colorBgGreen
424415 }
416+ filledPart = filledPart .Background (bgColor ).Foreground (fgColor )
417+ // Use a neutral background for empty areas
418+ emptyPart = emptyPart .Background (bgColor )
425419 }
426420
427- return s .String ()
421+ s := fmt .Sprintf (format , filledPart , emptyPart , percentWidth , fmt .Sprintf ("%.1f%%" , usage * 100 ))
422+ return termenv .String (s ).String ()
428423 }
429424
430425 setColumnConfigs (tab , maxColContent , assigned , opts , barTransformerFunc )
0 commit comments