Categorygithub.com/cheggaaa/pb
modulepackage
3.1.7+incompatible
Repository: https://github.com/cheggaaa/pb.git
Documentation: pkg.go.dev

# README

Terminal progress bar for Go

Coverage Status

Installation

go get github.com/cheggaaa/pb/v3

Documentation for v1 bar available here.

Quick start

package main

import (
	"time"

	"github.com/cheggaaa/pb/v3"
)

func main() {
	count := 100000

	// create and start new bar
	bar := pb.StartNew(count)

	// start bar from 'default' template
	// bar := pb.Default.Start(count)

	// start bar from 'simple' template
	// bar := pb.Simple.Start(count)

	// start bar from 'full' template
	// bar := pb.Full.Start(count)

	for i := 0; i < count; i++ {
		bar.Increment()
		time.Sleep(time.Millisecond)
	}

	// finish bar
	bar.Finish()
}

Result will be like this:

> go run test.go
37158 / 100000 [---------------->_______________________________] 37.16% 916 p/s

Settings

// create bar
bar := pb.New(count)

// refresh info every second (default 200ms)
bar.SetRefreshRate(time.Second)

// force set io.Writer, by default it's os.Stderr
bar.SetWriter(os.Stdout)

// bar will format numbers as bytes (B, KiB, MiB, etc)
bar.Set(pb.Bytes, true)

// bar use SI bytes prefix names (B, kB) instead of IEC (B, KiB)
bar.Set(pb.SIBytesPrefix, true)

// set custom bar template
bar.SetTemplateString(myTemplate)

// check for error after template set
if err := bar.Err(); err != nil {
    return
}

// start bar
bar.Start()

Progress bar for IO Operations

package main

import (
	"crypto/rand"
	"io"
	"io/ioutil"

	"github.com/cheggaaa/pb/v3"
)

func main() {
	var limit int64 = 1024 * 1024 * 500

	// we will copy 500 MiB from /dev/rand to /dev/null
	reader := io.LimitReader(rand.Reader, limit)
	writer := ioutil.Discard

	// start new bar
	bar := pb.Full.Start64(limit)

	// create proxy reader
	barReader := bar.NewProxyReader(reader)

	// copy from proxy reader
	io.Copy(writer, barReader)

	// finish bar
	bar.Finish()
}

Custom Progress Bar templates

Rendering based on builtin text/template package. You can use existing pb's elements or create you own.

All available elements are described in the element.go file.

All in one example:

tmpl := `{{ red "With funcs:" }} {{ bar . "<" "-" (cycle . "↖" "↗" "↘" "↙" ) "." ">"}} {{speed . | rndcolor }} {{percent .}} {{string . "my_green_string" | green}} {{string . "my_blue_string" | blue}}`

// start bar based on our template
bar := pb.ProgressBarTemplate(tmpl).Start64(limit)

// set values for string elements
bar.Set("my_green_string", "green").Set("my_blue_string", "blue")

# Functions

No description provided by the author
GetTerminalWidth - returns terminal width for all platforms.
Create new progress bar object.
Create new progress bar object using int64 as total.
NewPool initialises a pool with progress bars, but doesn't start it.
Create new object and start.
Create and start new pool with given bars You need call pool.Stop() after work.

# Constants

Default refresh rate - 200ms.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
U_BYTES units are formatted in a human readable way (B, KiB, MiB, ...).
U_BYTES_DEC units are like U_BYTES, but base 10 (B, KB, MB, ...).
U_DURATION units are formatted in a human readable way (3h14m15s).
U_NO are default units, they represent a simple value and are not formatted at all.
Current version.

# Variables

DEPRECATED variables for backward compatibility, from now do not work use pb.Format and pb.SetRefreshRate.
DEPRECATED variables for backward compatibility, from now do not work use pb.Format and pb.SetRefreshRate.
DEPRECATED variables for backward compatibility, from now do not work use pb.Format and pb.SetRefreshRate.
DEPRECATED variables for backward compatibility, from now do not work use pb.Format and pb.SetRefreshRate.
DEPRECATED variables for backward compatibility, from now do not work use pb.Format and pb.SetRefreshRate.
DEPRECATED variables for backward compatibility, from now do not work use pb.Format and pb.SetRefreshRate.
No description provided by the author

# Structs

No description provided by the author
No description provided by the author
It's proxy reader, implement io.Reader.
It's proxy Writer, implement io.Writer.

# Type aliases

Callback for custom output For example: bar.Callback = func(s string) { mySuperPrint(s) } .
No description provided by the author