Codebase list golang-github-vbauerster-mpb / cebd2ca example / simple / simple.go
cebd2ca

Tree @cebd2ca (Download .tar.gz)

simple.go @cebd2caraw · history · blame

package main

import (
	"fmt"
	"math/rand"
	"time"

	"github.com/vbauerster/uiprogress"
)

const (
	totalItem    = 1000
	maxBlockSize = 20
)

func main() {
	p := uiprogress.New()
	bar := p.AddBar(totalItem) // Add a new bar

	// optionally, append and prepend completion and elapsed time
	bar.AppendETA()
	// bar.PrependElapsed()

	blockSize := rand.Intn(maxBlockSize) + 1
	for i := 1; i <= totalItem; i += blockSize {
		time.Sleep(time.Duration(blockSize) * (50*time.Millisecond + time.Duration(rand.Intn(5*int(time.Millisecond)))))
		bar.Incr(blockSize)
		blockSize = rand.Intn(maxBlockSize) + 1
	}

	fmt.Println("stop")

	p.Stop()
}