progress bar styling improvements

This commit is contained in:
Jeffrey Morgan 2023-11-19 09:54:33 -05:00
parent e1d7056496
commit 04cbf5ccc0

View file

@ -55,7 +55,7 @@ func (b *Bar) String() string {
pre.WriteString(" ") pre.WriteString(" ")
} }
fmt.Fprintf(&pre, "%.1f%% ", b.percent()) fmt.Fprintf(&pre, "%.0f%% ", b.percent())
fmt.Fprintf(&suf, "(%s/%s, %s/s, %s)", fmt.Fprintf(&suf, "(%s/%s, %s/s, %s)",
format.HumanBytes(b.currentValue), format.HumanBytes(b.currentValue),
@ -63,26 +63,20 @@ func (b *Bar) String() string {
format.HumanBytes(int64(b.rate())), format.HumanBytes(int64(b.rate())),
b.elapsed()) b.elapsed())
mid.WriteString("[") mid.WriteString("")
// pad 3 for last = or > and "] " f := termWidth - pre.Len() - suf.Len() - 2
f := termWidth - pre.Len() - mid.Len() - suf.Len() - 3
n := int(float64(f) * b.percent() / 100) n := int(float64(f) * b.percent() / 100)
if n > 0 {
mid.WriteString(strings.Repeat("=", n))
}
if b.currentValue >= b.maxValue { if n > 0 {
mid.WriteString("=") mid.WriteString(strings.Repeat("█", n))
} else {
mid.WriteString(">")
} }
if f-n > 0 { if f-n > 0 {
mid.WriteString(strings.Repeat(" ", f-n)) mid.WriteString(strings.Repeat(" ", f-n))
} }
mid.WriteString("] ") mid.WriteString("")
return pre.String() + mid.String() + suf.String() return pre.String() + mid.String() + suf.String()
} }