Skip to content

muesli/goprogressbar

Repository files navigation

goprogressbar

Latest Release Build Status Coverage Status Go ReportCard GoDoc

Golang helper to print one or many progress bars on the console

Installation

Make sure you have a working Go environment (Go 1.9 or higher is required). See the install instructions.

To install goprogressbar, simply run:

go get github.com/muesli/goprogressbar

Example

package main

import (
	"fmt"
	"strconv"
	"time"

	"github.com/muesli/goprogressbar"
)

func main() {
	mpb := goprogressbar.MultiProgressBar{}

	for i := 0; i < 10; i++ {
		pb := &goprogressbar.ProgressBar{
			Text:    "Progress " + strconv.FormatInt(int64(i+1), 10),
			Total:   100,
			Current: 0,
			Width:   60,
		}

		mpb.AddProgressBar(pb)
	}

	pb := &goprogressbar.ProgressBar{
		Text:    "Overall Progress",
		Total:   1000,
		Current: 0,
		Width:   60,
	}
	mpb.AddProgressBar(pb)

	// fill progress bars one after another
	for j := 0; j < 10; j++ {
		for i := 1; i <= 100; i++ {
			p := mpb.ProgressBars[j]
			p.Current = int64(i)
			p.RightAlignedText = fmt.Sprintf("%d of %d", i, p.Total)

			pb.Current++

			mpb.LazyPrint()
			time.Sleep(23 * time.Millisecond)
		}
	}

	fmt.Println()
}

What it looks like

Progress 1                  100 of 100 [#################################################] 100.00%
Progress 2                  100 of 100 [#################################################] 100.00%
Progress 3                   89 of 100 [###########################################>-----]  89.00%
Progress 4                             [#>-----------------------------------------------]   0.00%
Progress 5                             [#>-----------------------------------------------]   0.00%
Progress 6                             [#>-----------------------------------------------]   0.00%
Progress 7                             [#>-----------------------------------------------]   0.00%
Progress 8                             [#>-----------------------------------------------]   0.00%
Progress 9                             [#>-----------------------------------------------]   0.00%
Progress 10                            [#>-----------------------------------------------]   0.00%
Overall Progress                       [#############>-----------------------------------]  28.90%

About

Print progress bars on the console with Go

Topics

Resources

License

Stars

Watchers

Forks

Sponsor this project

 

Packages

No packages published

Languages