progress

package
v0.0.0-...-30262a5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 4, 2017 License: MIT Imports: 1 Imported by: 4

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DummyProgress

type DummyProgress struct{}

DummyProgress doesn't report progress to anyone

func (*DummyProgress) Add

func (p *DummyProgress) Add(value int)

Add does nothing

func (*DummyProgress) AddTotal

func (p *DummyProgress) AddTotal(toTotal int)

AddTotal does nothing

func (*DummyProgress) Done

func (p *DummyProgress) Done()

Done does nothing

func (*DummyProgress) Set

func (p *DummyProgress) Set(value int)

Set does nothing

func (*DummyProgress) SetTotal

func (d *DummyProgress) SetTotal(total int)

SetTotal does nothing

type Progress

type Progress interface {
	SetTotal(total int)
	Set(value int)
	AddTotal(toTotal int)
	Add(toValue int)
	Done()
}

Progress

type ProgressBar

type ProgressBar struct {
	pb.ProgressBar
}

ProgressBar is a console progress bar which displays much info

Example
bar := StartProgressBar(20, "counting from 1 to 20")
for i := 0; i < 20; i++ {
	time.Sleep(1)
	bar.Add(1)
}
bar.Done()
Output:

Example (ManyThreads)
// the progressbar is thread-safe!
// this example should produce the same result as the above one

foos := make(chan string)
go func() {
	for i := 0; i < 20; i++ {
		time.Sleep(1)
		foos <- "foo"
	}
	close(foos)
}()

bar := StartProgressBar(20, "counting foos with 4 parallel threads")

wg := sync.WaitGroup{}
for i := 0; i < 4; i++ {
	go func() {
		for _ = range foos {
			bar.Add(1)
		}
		wg.Done()
	}()
}

wg.Wait()
bar.Done()
Output:

func NewProgressBar

func NewProgressBar(total int) *ProgressBar

NewProgressBar creates a progressbar with a 0/total progress. It's pretty useless until you call Start() to make it show up.

func StartProgressBar

func StartProgressBar(total int, prefix string) *ProgressBar

StartProgressBar creates a progressbar and makes it show up immediately. Prefix shows as a title to the progressbar.

func (*ProgressBar) Add

func (p *ProgressBar) Add(value int)

func (*ProgressBar) AddTotal

func (p *ProgressBar) AddTotal(toTotal int)

func (*ProgressBar) Done

func (p *ProgressBar) Done()

func (*ProgressBar) Set

func (p *ProgressBar) Set(value int)

func (*ProgressBar) SetTotal

func (p *ProgressBar) SetTotal(max int)

type ProgressChannel

type ProgressChannel struct {
	// contains filtered or unexported fields
}

ProgressChannel provides a way to communicate progress to a caller

func NewProgressChannel

func NewProgressChannel() *ProgressChannel

NewProgressChannel initializes a progress channel object

func (*ProgressChannel) Add

func (p *ProgressChannel) Add(value int)

Add adds to the current value

func (*ProgressChannel) AddTotal

func (p *ProgressChannel) AddTotal(toTotal int)

AddTotal adds to the current total

func (*ProgressChannel) Done

func (p *ProgressChannel) Done()

Done closes the channels

func (*ProgressChannel) DoneChan

func (p *ProgressChannel) DoneChan() <-chan struct{}

DoneChan returns a channel which is closed when Done() is called

func (*ProgressChannel) Set

func (p *ProgressChannel) Set(value int)

Set updates the current progress

func (*ProgressChannel) SetTotal

func (p *ProgressChannel) SetTotal(total int)

SetTotal sets the total progress

func (*ProgressChannel) Total

func (p *ProgressChannel) Total() <-chan int

Total returns a channel which receives updates to the total value

func (*ProgressChannel) Value

func (p *ProgressChannel) Value() <-chan int

Value returns a channel which receives updates to the current value

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL