https://github.com/astromechza/pbars
Need a progress bar in your Golang CLI? This might help you
https://github.com/astromechza/pbars
cli golang progress-bar
Last synced: over 1 year ago
JSON representation
Need a progress bar in your Golang CLI? This might help you
- Host: GitHub
- URL: https://github.com/astromechza/pbars
- Owner: astromechza
- License: mit
- Created: 2017-04-08T16:02:26.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2018-09-04T22:20:21.000Z (almost 8 years ago)
- Last Synced: 2025-03-09T03:41:24.260Z (over 1 year ago)
- Topics: cli, golang, progress-bar
- Language: Go
- Size: 16.6 KB
- Stars: 5
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# `pbars` `|██████████▏ |`
[](https://godoc.org/github.com/AstromechZA/pbars)
[](https://travis-ci.org/AstromechZA/pbars/)
[](https://opensource.org/licenses/MIT)
```golang
// setup the printer
pp := pbars.NewProgressPrinter("My Title", 50, true)
// go!
for i := 0; i < 400; i++ {
pp.Update(int64(i+1), 400)
time.Sleep(16 * time.Millisecond)
}
// new line required afterwards :)
pp.Done()
```
## Example
There's an [example in the /example directory](example/main.go) which does the following:

\* *cursor flickering is just the high (16ms) update rate and the way the gif was rendered*
## Features
- UTF8 blocks vs pure ASCII (sometimes a terminal doesn't support utf8 chars)
```golang
pbars.NewProgressPrinter("My Title", 50, true) // utf8 mode
pbars.NewProgressPrinter("My Title", 50, false) // ascii mode
```
- When writing to Non-TTY output streams like files or those that don't support the `\r` character, you can set `ProgressPrinter{}.NonTTY = true`. This will disable the progress bar until the `Done` function is called upon which it will print the final progress bar, rate, and elapsed time as normal.
- Uses the overall units per second and elapsed time once you call `Done`
- Customisable unit formats
By default the progress bar rate is formatted as 'units' per second. But often you'll want a measure of bytes or bits. The `ProgressPrinter` struct allows you to set the `UnitFunc` to be whatever you want as long as it looks like `func(v float64) string`. An example is the `pbars.ByteFormatFunc` that will convert to `B`, `KB`, `MB` etc.
- `Interruptf` method for printing messages while the progress bar continues (see the example)
- `Clear` method for clearing and removing the progress bar once you no longer need it