diff --git a/bar.go b/bar.go index a53aa61..d20524b 100644 --- a/bar.go +++ b/bar.go @@ -33,7 +33,7 @@ index int // pointer to running bar, which this bar should replace - waitBar *Bar + runningBar *Bar // completed is set from master Progress goroutine only completed bool @@ -77,7 +77,7 @@ // following options are assigned to the *Bar priority int removeOnComplete bool - waitBar *Bar + runningBar *Bar } refill struct { char rune @@ -115,14 +115,14 @@ b := &Bar{ priority: s.priority, removeOnComplete: s.removeOnComplete, - waitBar: s.waitBar, + runningBar: s.runningBar, operateState: make(chan func(*bState)), done: make(chan struct{}), shutdown: make(chan struct{}), } - if b.waitBar != nil { - b.priority = b.waitBar.priority + if b.runningBar != nil { + b.priority = b.runningBar.priority } go b.serve(wg, s, cancel) diff --git a/bar_option.go b/bar_option.go index fb62f29..d097c78 100644 --- a/bar_option.go +++ b/bar_option.go @@ -84,19 +84,11 @@ } } -// BarPriority sets bar's priority. -// Zero is highest priority, i.e. bar will be on top. -// If `BarReplaceOnComplete` option is supplied, this option is ignored. -func BarPriority(priority int) BarOption { +// BarReplaceOnComplete is indicator for delayed bar start, after the `runningBar` is complete. +// To achive bar replacement effect, `runningBar` should has its `BarRemoveOnComplete` option set. +func BarReplaceOnComplete(runningBar *Bar) BarOption { return func(s *bState) { - s.priority = priority - } -} - -// BarReplaceOnComplete provided `b` is usually already running bar which this bar should replace. -func BarReplaceOnComplete(b *Bar) BarOption { - return func(s *bState) { - s.waitBar = b + s.runningBar = runningBar } } @@ -104,6 +96,15 @@ func BarClearOnComplete() BarOption { return func(s *bState) { s.noBarOnComplete = true + } +} + +// BarPriority sets bar's priority. +// Zero is highest priority, i.e. bar will be on top. +// If `BarReplaceOnComplete` option is supplied, this option is ignored. +func BarPriority(priority int) BarOption { + return func(s *bState) { + s.priority = priority } } diff --git a/decor/decorators.go b/decor/decorators.go index 8ada6cc..49948e8 100644 --- a/decor/decorators.go +++ b/decor/decorators.go @@ -119,7 +119,7 @@ // counters unit is multiple by 1000. // `pairFormat` must contain two printf compatible verbs, like "%f" or "%d". // First verb substituted with Current, second one with Total. -// Example: `"%.1f / %.1f" = "1.0MiB / 12.0MiB"` or `"% .1f / % .1f" = "1.0 MiB / 12.0 MiB"`. +// Example: `"%.1f / %.1f" = "1.0MB / 12.0MB"` or `"% .1f / % .1f" = "1.0 MB / 12.0 MB"`. // If you set `DwidthSync` bit in `conf` param, `minWidth` param is ignored. // `DwidthSync` is effective with multiple bars only, if set decorator will participate // in width synchronization process with other decorators in the same column group. diff --git a/progress.go b/progress.go index bc2c012..f1d3106 100644 --- a/progress.go +++ b/progress.go @@ -94,8 +94,8 @@ case p.operateState <- func(s *pState) { options = append(options, barWidth(s.width), barFormat(s.format)) b := newBar(p.wg, s.idCounter, total, s.cancel, options...) - if b.waitBar != nil { - s.waitBars[b.waitBar] = b + if b.runningBar != nil { + s.waitBars[b.runningBar] = b } else { heap.Push(s.bHeap, b) s.heapUpdated = true