also prefix bar with number of items processing
This commit is contained in:
parent
541c68aed5
commit
408578507f
|
@ -1,6 +1,7 @@
|
||||||
package packer
|
package packer
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"sync"
|
"sync"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
|
@ -18,6 +19,7 @@ type ProgressBar interface {
|
||||||
}
|
}
|
||||||
|
|
||||||
type StackableProgressBar struct {
|
type StackableProgressBar struct {
|
||||||
|
items int32
|
||||||
total uint64
|
total uint64
|
||||||
started bool
|
started bool
|
||||||
BasicProgressBar
|
BasicProgressBar
|
||||||
|
@ -42,13 +44,21 @@ func (spb *StackableProgressBar) start() {
|
||||||
|
|
||||||
func (spb *StackableProgressBar) Start(total uint64) {
|
func (spb *StackableProgressBar) Start(total uint64) {
|
||||||
atomic.AddUint64(&spb.total, total)
|
atomic.AddUint64(&spb.total, total)
|
||||||
|
atomic.AddInt32(&spb.items, 1)
|
||||||
spb.group.Add(1)
|
spb.group.Add(1)
|
||||||
spb.startOnce.Do(spb.start)
|
spb.startOnce.Do(spb.start)
|
||||||
spb.SetTotal64(int64(spb.total))
|
spb.SetTotal64(int64(atomic.LoadUint64(&spb.total)))
|
||||||
|
spb.prefix()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (spb *StackableProgressBar) prefix() {
|
||||||
|
spb.BasicProgressBar.ProgressBar.Prefix(fmt.Sprintf("%d items: ", atomic.LoadInt32(&spb.items)))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (spb *StackableProgressBar) Finish() {
|
func (spb *StackableProgressBar) Finish() {
|
||||||
|
atomic.AddInt32(&spb.items, -1)
|
||||||
spb.group.Done()
|
spb.group.Done()
|
||||||
|
spb.prefix()
|
||||||
}
|
}
|
||||||
|
|
||||||
type BasicProgressBar struct {
|
type BasicProgressBar struct {
|
||||||
|
|
Loading…
Reference in New Issue