Skip to content
A really basic thread-safe progress bar for Golang applications
Branch: master
Clone or download
Latest commit 040caca Nov 17, 2019
Type Name Latest commit message Commit time
Failed to load latest commit information.
examples bump Nov 17, 2019
.gitignore Removed *install files and added .gitignore Sep 19, 2019
.travis.yml Fixing line-ending May 18, 2018
LICENSE Fixing line endings May 18, 2018 Update Sep 27, 2019
go.mod show the final mb/s after finish Nov 17, 2019
go.sum update deps Jun 4, 2019
progressbar.go show the final it/s too Nov 17, 2019
progressbar_test.go Added ExampleOptionSetPredictTime for documentation Sep 19, 2019


travis go report card coverage godocs

A very simple thread-safe progress bar which should work on every OS without problems. I needed a progressbar for croc and everything I tried had problems, so I made another one. In order to be OS agnostic I do not plan to support multi-line outputs.

Example of progress bar


go get -u


Basic usage

bar := progressbar.New(100)
for i := 0; i < 100; i++ {
    time.Sleep(10 * time.Millisecond)

which looks like:

 100% |████████████████████████████████████████| [1s:0s]

The times at the end show the elapsed time and the remaining time, respectively.

Long running processes

For long running processes, you might want to render from a 0% state.

// Renders the bar right on construction
bar := progressbar.NewOptions(100, progressbar.OptionSetRenderBlankState(true))

Alternatively, when you want to delay rendering, but still want to render a 0% state

bar := progressbar.NewOptions(100)

// Render the current state, which is 0% in this case

// Emulate work
for i := 0; i < 10; i++ {
    time.Sleep(10 * time.Minute)

Use a custom writer

The default writer is standard output (os.Stdout), but you can set it to whatever satisfies io.Writer.

bar := NewOptions(
    OptionSetTheme(Theme{Saucer: "#", SaucerPadding: "-", BarStart: ">", BarEnd: "<"}),

result := strings.TrimSpace(buf.String())

// Result equals:
// 50% >#####-----< [0s:0s]

Progress for I/O operations

The progressbar implements an io.Writer so it can automatically detect the number of bytes written to a stream, so you can use it as a progressbar for an io.Reader.

urlToGet := ""
req, _ := http.NewRequest("GET", urlToGet, nil)
resp, _ := http.DefaultClient.Do(req)
defer resp.Body.Close()

var out io.Writer
f, _ := os.OpenFile("", os.O_CREATE|os.O_WRONLY, 0644)
out = f
defer f.Close()

bar := progressbar.NewOptions(
out = io.MultiWriter(out, bar)
io.Copy(out, resp.Body)

See the tests for another example.

Changing max value

The progressbar implements ChangeMax and ChangeMax64 functions to change the max value of the progress bar.

bar := progressbar.New(100)
bar.ChangeMax(200) // Change the max of the progress bar to 200, not 100

You can also use ChangeMax64 to minimize casting in the library. See the tests for another example.

Displaying Total Increment Over Predicted Time

By default the progress bar will attempt to predict the remaining amount of time left. This can be change to just show the current increment over the total maximum amount set for the progress bar. Do this by using the OptionSetPredictTime option during progress bar creation.

bar := progressbar.NewOptions(100, progressbar.OptionSetPredictTime(false))

// this result equals:
// "20% |██        |  [20:100]"

// default result equals:
// "20% |██        |  [3s:15s]"


Pull requests are welcome. Feel free to...

  • Revise documentation
  • Add new features
  • Fix bugs
  • Suggest improvements


Thanks @Dynom for massive improvements in version 2.0!

Thanks @CrushedPixel for adding descriptions and color code support!

Thanks @MrMe42 for adding some minor features!

Thanks @tehstun for some great PRs!



You can’t perform that action at this time.