From 04cbf5ccc0e837ff4caf6e801e6456a994d2b19c Mon Sep 17 00:00:00 2001 From: Jeffrey Morgan Date: Sun, 19 Nov 2023 09:54:33 -0500 Subject: [PATCH] progress bar styling improvements --- progress/bar.go | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/progress/bar.go b/progress/bar.go index f69fb87b..5ebc203d 100644 --- a/progress/bar.go +++ b/progress/bar.go @@ -55,7 +55,7 @@ func (b *Bar) String() string { pre.WriteString(" ") } - fmt.Fprintf(&pre, "%.1f%% ", b.percent()) + fmt.Fprintf(&pre, "%.0f%% ", b.percent()) fmt.Fprintf(&suf, "(%s/%s, %s/s, %s)", format.HumanBytes(b.currentValue), @@ -63,26 +63,20 @@ func (b *Bar) String() string { format.HumanBytes(int64(b.rate())), b.elapsed()) - mid.WriteString("[") + mid.WriteString("▕") - // pad 3 for last = or > and "] " - f := termWidth - pre.Len() - mid.Len() - suf.Len() - 3 + f := termWidth - pre.Len() - suf.Len() - 2 n := int(float64(f) * b.percent() / 100) - if n > 0 { - mid.WriteString(strings.Repeat("=", n)) - } - if b.currentValue >= b.maxValue { - mid.WriteString("=") - } else { - mid.WriteString(">") + if n > 0 { + mid.WriteString(strings.Repeat("█", n)) } if f-n > 0 { mid.WriteString(strings.Repeat(" ", f-n)) } - mid.WriteString("] ") + mid.WriteString("▏") return pre.String() + mid.String() + suf.String() }