Skip to content

Progress bars in Go terminal apps with uiprogress

uiprogress is a small Go package that draws progress bars in the terminal. It redraws the bars on a timer (every 10 ms by default) using uilive, so you only call Incr() or Set() and the package handles the rendering. It is a good fit for CLI tools that download files, process batches, or run several jobs at once.

The package is small and stable rather than actively developed: the only tagged release is v0.0.1 (2017).

Inside a Go module:

Terminal window
go get github.com/gosuri/uiprogress
package main
import (
"time"
"github.com/gosuri/uiprogress"
)
func main() {
uiprogress.Start() // start the render loop
defer uiprogress.Stop() // draw the final state and stop rendering
bar := uiprogress.AddBar(100)
bar.Width = 50
bar.AppendCompleted() // show "NN%" after the bar
bar.PrependElapsed() // show elapsed time before the bar
for bar.Incr() {
time.Sleep(20 * time.Millisecond)
}
}

Incr() returns false once the bar reaches its total, so the loop ends on its own. Do the work in the main goroutine (or wait for it); if main returns straight after Start(), the program exits before anything is drawn.

If you know the absolute position rather than incrementing by one, use bar.Set(n). It returns uiprogress.ErrMaxCurrentReached if n is above the total.

Fill, Head, Empty, LeftEnd and RightEnd are byte fields on the bar (defaults =, >, -, [, ]):

bar.Fill = '#'
bar.Head = '#'
bar.Empty = '.'

Because they are bytes, you can’t use multi-byte characters such as █.

Text before and after the bar comes from decorator functions of type uiprogress.DecoratorFunc, which is func(b *uiprogress.Bar) string. Add them with PrependFunc and AppendFunc (this snippet also needs fmt imported):

steps := []string{"downloading", "unpacking", "compiling", "installing"}
bar := uiprogress.AddBar(len(steps))
bar.PrependFunc(func(b *uiprogress.Bar) string {
if b.Current() == 0 {
return "starting"
}
return steps[b.Current()-1]
})
bar.AppendFunc(func(b *uiprogress.Bar) string {
return fmt.Sprintf("%d/%d", b.Current(), b.Total)
})

Other helpers on Bar: CompletedPercent(), CompletedPercentString() and TimeElapsedString().

Each call to AddBar adds another line. Run the work for each bar in its own goroutine and wait for all of them before stopping:

package main
import (
"sync"
"time"
"github.com/gosuri/uiprogress"
)
func main() {
uiprogress.Start()
var wg sync.WaitGroup
for _, total := range []int{20, 40, 60} {
bar := uiprogress.AddBar(total).AppendCompleted().PrependElapsed()
wg.Add(1)
go func() {
defer wg.Done()
for bar.Incr() {
time.Sleep(50 * time.Millisecond)
}
}()
}
wg.Wait()
uiprogress.Stop()
}

AppendCompleted and PrependElapsed return the bar, so they chain.

  • The package-level functions (Start, AddBar, Stop) use a single default Progress. If you need separate groups of bars or a different output, create one with uiprogress.New() and call SetOut or SetRefreshInterval on it.
  • Anything else you print to stdout while bars are rendering will be overwritten or garbled. Use Progress.Bypass() to get a writer that prints above the bars.

© 2026 David Li · Home · Blog · RSS ·Classic site · Built with Astro, Starlight and three.js · Logos:Font Awesome Free (CC BY 4.0)