Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork234
A really basic thread-safe progress bar for Golang applications
License
schollz/progressbar
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
A very simple thread-safe progress bar which should work on every OS without problems. I needed a progressbar forcroc and everything I tried had problems, so I made another one. In order to be OS agnostic I do not plan to supportmulti-line outputs.
go get -u github.com/schollz/progressbar/v3
bar:=progressbar.Default(100)fori:=0;i<100;i++ {bar.Add(1)time.Sleep(40*time.Millisecond)}
which looks like:
Theprogressbar
implements anio.Writer
so it can automatically detect the number of bytes written to a stream, so you can use it as a progressbar for anio.Reader
.
req,_:=http.NewRequest("GET","https://dl.google.com/go/go1.14.2.src.tar.gz",nil)resp,_:=http.DefaultClient.Do(req)deferresp.Body.Close()f,_:=os.OpenFile("go1.14.2.src.tar.gz",os.O_CREATE|os.O_WRONLY,0644)deferf.Close()bar:=progressbar.DefaultBytes(resp.ContentLength,"downloading",)io.Copy(io.MultiWriter(f,bar),resp.Body)
which looks like:
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 theresp.ContentLength
to-1
.
which looks like:
There is a lot of customization that you can do - change the writer, the color, the width, description, theme, etc. Seeall the options.
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:"]", }))fori:=0;i<1000;i++ {bar.Add(1)time.Sleep(5*time.Millisecond)}
which looks like:
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!
Thanks@Benzammour and@haseth for helping create v3!
Thanks@briandowns for compiling the list of spinners.
MIT
About
A really basic thread-safe progress bar for Golang applications
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Sponsor this project
Uh oh!
There was an error while loading.Please reload this page.
Packages0
Uh oh!
There was an error while loading.Please reload this page.