From 7e5ef42924320d820d9645ecf2e9ef58e6c91e71 Mon Sep 17 00:00:00 2001 From: Christian Rocha Date: Wed, 18 Nov 2020 18:49:26 -0500 Subject: [PATCH] Add ability to style percentage readout --- progress/progress.go | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/progress/progress.go b/progress/progress.go index c8793ca..38ca7f0 100644 --- a/progress/progress.go +++ b/progress/progress.go @@ -89,8 +89,9 @@ type Model struct { EmptyColor string // Settings for rendering the numeric percentage - ShowPercentage bool - PercentFormat string // a fmt string for a float + ShowPercentage bool + PercentFormat string // a fmt string for a float + PercentageStyle *termenv.Style useRamp bool rampColorA colorful.Color @@ -127,9 +128,12 @@ func NewModel(opts ...Option) (*Model, error) { func (m Model) View(percent float64) string { b := strings.Builder{} if m.ShowPercentage { - s := fmt.Sprintf(m.PercentFormat, percent*100) - m.bar(&b, percent, ansi.PrintableRuneWidth(s)) - b.WriteString(s) + percentage := fmt.Sprintf(m.PercentFormat, percent*100) + if m.PercentageStyle != nil { + percentage = m.PercentageStyle.Styled(percentage) + } + m.bar(&b, percent, ansi.PrintableRuneWidth(percentage)) + b.WriteString(percentage) } else { m.bar(&b, percent, 0) }