@@ -60,6 +60,10 @@ type Config struct {
6060 Spinner bool
6161 // Prefix to show before the progress bar (can be updated while running using UpdatePrefix() or through Extra()).
6262 Prefix string
63+ // Suffix to show after the percentage information on the bar (can be updated while running using UpdateSuffix()).
64+ Suffix string
65+ // If NoPercent is true, the percentage is not shown on the bar (if the default %.1f%% format is not adequate).
66+ NoPercent bool
6367 // Minimum duration between updates (0 to update every time).
6468 UpdateInterval time.Duration
6569 // Option to avoid all ANSI sequences (useful for non terminal output/test/go playground),
@@ -96,6 +100,14 @@ func (bar *Bar) UpdatePrefix(p string) {
96100 bar .out .Unlock ()
97101}
98102
103+ // UpdateSuffix changes the suffix while the progress bar is running.
104+ // This is thread safe / acquires a shared lock to avoid issues on the output.
105+ func (bar * Bar ) UpdateSuffix (s string ) {
106+ bar .out .Lock ()
107+ bar .Suffix = s
108+ bar .out .Unlock ()
109+ }
110+
99111// Progress shows a progress bar percentage (0-100%). On the same line as current line,
100112// so when call repeatedly it will overwrite/update itself.
101113// Use MoveCursorUp to move up to update other lines as needed or use Writer()
@@ -118,7 +130,7 @@ func (bar *Bar) Progress(progressPercent float64) {
118130 }
119131 barStr := ""
120132 progressPercentStr := ""
121- if progressPercent >= 0 && progressPercent <= 100 {
133+ if progressPercent >= 0 && progressPercent <= 100 { //nolint:nestif // it's not that bad here
122134 width := float64 (bar .Width )
123135 if width == 0 {
124136 width = DefaultWidth
@@ -137,7 +149,9 @@ func (bar *Bar) Progress(progressPercent float64) {
137149 reset = "▻" // "◣"
138150 }
139151 barStr = color + strings .Repeat (Full , fullCount ) + FractionalBlocks [remainder ] + strings .Repeat (Space , spaceCount ) + reset
140- progressPercentStr = fmt .Sprintf (" %.1f%%" , progressPercent )
152+ if ! bar .NoPercent {
153+ progressPercentStr = fmt .Sprintf (" %.1f%%" , progressPercent )
154+ }
141155 }
142156 spinner := ""
143157 if bar .Spinner {
@@ -157,6 +171,7 @@ func (bar *Bar) Progress(progressPercent float64) {
157171 bar .out .buf = append (bar .out .buf , spinner ... )
158172 bar .out .buf = append (bar .out .buf , barStr ... )
159173 bar .out .buf = append (bar .out .buf , progressPercentStr ... )
174+ bar .out .buf = append (bar .out .buf , bar .Suffix ... )
160175 bar .out .buf = append (bar .out .buf , extra ... )
161176 bar .out .buf = append (bar .out .buf , bar .indexBasedMoveUp ()... )
162177 // bar.out.buf = append(bar.out.buf, '\n') // Uncomment to debug/see all the incremental updates.
0 commit comments