Documentation
¶
Index ¶
- type DummyProgress
- type Progress
- type ProgressBar
- type ProgressChannel
- func (p *ProgressChannel) Add(value int)
- func (p *ProgressChannel) AddTotal(toTotal int)
- func (p *ProgressChannel) Done()
- func (p *ProgressChannel) DoneChan() <-chan struct{}
- func (p *ProgressChannel) Set(value int)
- func (p *ProgressChannel) SetTotal(total int)
- func (p *ProgressChannel) Total() <-chan int
- func (p *ProgressChannel) Value() <-chan int
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) AddTotal ¶
func (p *DummyProgress) AddTotal(toTotal int)
AddTotal 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()
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()
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) 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