From 408578507f70883162298b7da66e339629036077 Mon Sep 17 00:00:00 2001 From: Adrien Delorme Date: Wed, 5 Sep 2018 18:22:45 +0200 Subject: [PATCH] also prefix bar with number of items processing --- packer/progressbar.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/packer/progressbar.go b/packer/progressbar.go index 2a1ed97d6..ac181757e 100644 --- a/packer/progressbar.go +++ b/packer/progressbar.go @@ -1,6 +1,7 @@ package packer import ( + "fmt" "io" "sync" "sync/atomic" @@ -18,6 +19,7 @@ type ProgressBar interface { } type StackableProgressBar struct { + items int32 total uint64 started bool BasicProgressBar @@ -42,13 +44,21 @@ func (spb *StackableProgressBar) start() { func (spb *StackableProgressBar) Start(total uint64) { atomic.AddUint64(&spb.total, total) + atomic.AddInt32(&spb.items, 1) spb.group.Add(1) 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() { + atomic.AddInt32(&spb.items, -1) spb.group.Done() + spb.prefix() } type BasicProgressBar struct {