Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/schollz/progressbar
A really basic thread-safe progress bar for Golang applications
https://github.com/schollz/progressbar
command-line go golang hacktoberfest library progress-bar progressbar terminal
Last synced: 3 months ago
JSON representation
A really basic thread-safe progress bar for Golang applications
- Host: GitHub
- URL: https://github.com/schollz/progressbar
- Owner: schollz
- License: mit
- Created: 2017-10-26T18:28:10.000Z (about 7 years ago)
- Default Branch: main
- Last Pushed: 2024-05-20T13:04:59.000Z (8 months ago)
- Last Synced: 2024-05-20T15:12:54.668Z (8 months ago)
- Topics: command-line, go, golang, hacktoberfest, library, progress-bar, progressbar, terminal
- Language: Go
- Homepage: https://pkg.go.dev/github.com/schollz/progressbar/v3?tab=doc
- Size: 1.21 MB
- Stars: 3,855
- Watchers: 24
- Forks: 213
- Open Issues: 31
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
- awesome-go - progressbar - Basic thread-safe progress bar that works in every OS. (Command Line / Advanced Console UIs)
- fucking-awesome-go - progressbar - Basic thread-safe progress bar that works in every OS. (Command Line / Advanced Console UIs)
- Awesome - Progressbar - A really basic thread-safe progress bar for Golang applications (Development / Programming)
- awesome-go - progressbar - Basic thread-safe progress bar that works in every OS. (Command Line / Advanced Console UIs)
- awesome-github-star - progressbar - safe progress bar for Golang applications | schollz | 3497 | (Go)
- awesome-loading-indicators - progressbar - A really basic thread-safe progress bar for Golang applications. (Go)
- go-awesome - progressbar - print a progress bar on the terminal (Open source library / Command Line)
- awesome-golang-repositories - progressbar - safe progress bar for Golang applications (Repositories)
- awesome-go - progressbar - Basic thread-safe progress bar that works in every OS. (Command Line / Advanced Console UIs)
- awesome-go - progressbar - A really basic thread-safe progress bar for Golang applications - ★ 413 (Command Line)
- awesome-go-extra - progressbar - safe progress bar for Golang applications|2712|163|25|2017-10-26T18:28:10Z|2022-08-11T10:03:42Z| (Build Automation / Advanced Console UIs)
- awesome-go-with-stars - progressbar - Basic thread-safe progress bar that works in every OS. (Command Line / Advanced Console UIs)
- awesome-go - progressbar - Basic thread-safe progress bar that works in every OS. Stars:`4.2K`. (Command Line / Advanced Console UIs)
- awesome-go-cn - progressbar
- awesome-go-plus - progressbar - Basic thread-safe progress bar that works in every OS. ![stars](https://img.shields.io/badge/stars-4218-blue) (Command Line / Advanced Console UIs)
- awesome-go-plus - progressbar - Basic thread-safe progress bar that works in every OS. ![stars](https://img.shields.io/badge/stars-4144-blue) (Command Line / Advanced Console UIs)
README
# progressbar
[![CI](https://github.com/schollz/progressbar/actions/workflows/ci.yml/badge.svg?branch=main&event=push)](https://github.com/schollz/progressbar/actions/workflows/ci.yml)
[![go report card](https://goreportcard.com/badge/github.com/schollz/progressbar)](https://goreportcard.com/report/github.com/schollz/progressbar)
[![coverage](https://img.shields.io/badge/coverage-84%25-brightgreen.svg)](https://gocover.io/github.com/schollz/progressbar)
[![godocs](https://godoc.org/github.com/schollz/progressbar?status.svg)](https://godoc.org/github.com/schollz/progressbar/v3)A very simple thread-safe progress bar which should work on every OS without problems. I needed a progressbar for [croc](https://github.com/schollz/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](https://github.com/schollz/progressbar/issues/6).
## Install
```
go get -u github.com/schollz/progressbar/v3
```## Usage
### Basic usage
```golang
bar := progressbar.Default(100)
for i := 0; i < 100; i++ {
bar.Add(1)
time.Sleep(40 * time.Millisecond)
}
```which looks like:
![Example of basic bar](examples/basic/basic.gif)
### 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`.
```golang
req, _ := http.NewRequest("GET", "https://dl.google.com/go/go1.14.2.src.tar.gz", nil)
resp, _ := http.DefaultClient.Do(req)
defer resp.Body.Close()f, _ := os.OpenFile("go1.14.2.src.tar.gz", os.O_CREATE|os.O_WRONLY, 0644)
defer f.Close()bar := progressbar.DefaultBytes(
resp.ContentLength,
"downloading",
)
io.Copy(io.MultiWriter(f, bar), resp.Body)
```which looks like:
![Example of download bar](examples/download/download.gif)
### Progress bar with unknown length
A progressbar with unknown length is a spinner. Any bar with -1 length will automatically convert it to a spinner with a customizable spinner type. For example, the above code can be run and set the `resp.ContentLength` to `-1`.
which looks like:
![Example of download bar with unknown length](examples/download-unknown/download-unknown.gif)
### Customization
There is a lot of customization that you can do - change the writer, the color, the width, description, theme, etc. See [all the options](https://pkg.go.dev/github.com/schollz/progressbar/v3?tab=doc#Option).
```golang
bar := progressbar.NewOptions(1000,
progressbar.OptionSetWriter(ansi.NewAnsiStdout()), //you should install "github.com/k0kubun/go-ansi"
progressbar.OptionEnableColorCodes(true),
progressbar.OptionShowBytes(true),
progressbar.OptionSetWidth(15),
progressbar.OptionSetDescription("[cyan][1/3][reset] Writing moshable file..."),
progressbar.OptionSetTheme(progressbar.Theme{
Saucer: "[green]=[reset]",
SaucerHead: "[green]>[reset]",
SaucerPadding: " ",
BarStart: "[",
BarEnd: "]",
}))
for i := 0; i < 1000; i++ {
bar.Add(1)
time.Sleep(5 * time.Millisecond)
}
```which looks like:
![Example of customized bar](examples/customization/customization.gif)
## Contributing
Pull requests are welcome. Feel free to...
- Revise documentation
- Add new features
- Fix bugs
- Suggest improvements## Thanks
Thanks [@Dynom](https://github.com/dynom) for massive improvements in version 2.0!
Thanks [@CrushedPixel](https://github.com/CrushedPixel) for adding descriptions and color code support!
Thanks [@MrMe42](https://github.com/MrMe42) for adding some minor features!
Thanks [@tehstun](https://github.com/tehstun) for some great PRs!
Thanks [@Benzammour](https://github.com/Benzammour) and [@haseth](https://github.com/haseth) for helping create v3!
Thanks [@briandowns](https://github.com/briandowns) for compiling the list of spinners.
## License
MIT