diff --git a/bar.go b/bar.go index a114846..ef883de 100644 --- a/bar.go +++ b/bar.go @@ -59,7 +59,6 @@ trimLeftSpace bool trimRightSpace bool toComplete bool - removeOnComplete bool dynamic bool startTime time.Time timeElapsed time.Duration @@ -70,6 +69,10 @@ refill *refill bufP, bufB, bufA *bytes.Buffer panicMsg string + + // following options are assigned to the *Bar + priority int + removeOnComplete bool } refill struct { char rune @@ -89,6 +92,7 @@ s := &bState{ id: id, + priority: id, total: total, etaAlpha: etaAlpha, } @@ -104,7 +108,7 @@ s.bufA = bytes.NewBuffer(make([]byte, 0, s.width)) b := &Bar{ - priority: id, + priority: s.priority, removeOnComplete: s.removeOnComplete, operateState: make(chan func(*bState)), done: make(chan struct{}), diff --git a/bar_option.go b/bar_option.go index 82feeea..54b3f8e 100644 --- a/bar_option.go +++ b/bar_option.go @@ -82,6 +82,14 @@ } } +// BarPriority sets bar's priority. +// Zero is highest priority, i.e. bar will be on top. +func BarPriority(priority int) BarOption { + return func(s *bState) { + s.priority = priority + } +} + func barWidth(w int) BarOption { return func(s *bState) { s.width = w diff --git a/priority_queue.go b/priority_queue.go index f60e222..c1e054f 100644 --- a/priority_queue.go +++ b/priority_queue.go @@ -2,7 +2,7 @@ import "container/heap" -// A priorityQueue implements heap.Interface and holds Items. +// A priorityQueue implements heap.Interface type priorityQueue []*Bar func (pq priorityQueue) Len() int { return len(pq) } @@ -33,7 +33,7 @@ return bar } -// update modifies the priority of an Bar in the queue. +// update modifies the priority of a Bar in the queue. func (pq *priorityQueue) update(bar *Bar, priority int) { bar.priority = priority heap.Fix(pq, bar.index)