Codebase list golang-github-vbauerster-mpb / 23d4934
Fix #24 Vladimir Bauer 8 years ago
2 changed file(s) with 19 addition(s) and 13 deletion(s). Raw diff Collapse all Expand all
6262 trimRightSpace bool
6363 toComplete bool
6464 dynamic bool
65 noBarOnComplete bool
65 barClearOnComplete bool
66 completeFlushed bool
6667 startTime time.Time
6768 blockStartTime time.Time
6869 timeElapsed time.Duration
320321 r = strings.NewReader(fmt.Sprintf(fmt.Sprintf("%%.%ds\n", tw), s.panicMsg))
321322 fmt.Fprintf(debugOut, "%s %s bar id %02d %v\n", "[mpb]", time.Now(), s.id, s.panicMsg)
322323 }
323 ch <- &bFrame{b, r, s.toComplete}
324 ch <- &bFrame{b, r, s.toComplete && !(s.barClearOnComplete && !s.completeFlushed)}
325 s.completeFlushed = s.toComplete
324326 }()
325327 r = s.draw(tw, pSyncer, aSyncer)
326328 }:
332334 } else {
333335 r = s.draw(tw, pSyncer, aSyncer)
334336 }
335 ch <- &bFrame{b, r, s.toComplete}
337 ch <- &bFrame{b, r, true}
336338 }
337339 }()
338340
360362 prependCount := utf8.RuneCount(s.bufP.Bytes())
361363 appendCount := utf8.RuneCount(s.bufA.Bytes())
362364
363 if s.toComplete && s.noBarOnComplete {
365 if s.barClearOnComplete && s.completeFlushed {
364366 return io.MultiReader(s.bufP, s.bufA)
365367 }
366368
439441 func newStatistics(s *bState) *decor.Statistics {
440442 return &decor.Statistics{
441443 ID: s.id,
442 Completed: s.toComplete,
444 Completed: s.completeFlushed,
443445 Total: s.total,
444446 Current: s.current,
445447 StartTime: s.startTime,
5959 }
6060 }
6161
62 // BarDynamicTotal enables dynamic total behaviour.
62 // BarDynamicTotal is a flag, if set enables dynamic total behaviour.
63 // If provided total <= 0, it is set implicitly.
6364 func BarDynamicTotal() BarOption {
6465 return func(s *bState) {
6566 s.dynamic = true
6667 }
6768 }
6869
69 // BarAutoIncrTotal auto increment total by amount, when trigger percentage remained till bar completion.
70 // BarAutoIncrTotal auto increment total by n, when trigger percentage remained till bar completion.
7071 // In other words: say you've set trigger = 10, then auto increment will start after bar reaches 90 %.
71 func BarAutoIncrTotal(trigger, amount int64) BarOption {
72 // Effective only if BarDynamicTotal option is set.
73 func BarAutoIncrTotal(trigger, n int64) BarOption {
7274 return func(s *bState) {
73 s.dynamic = true
7475 s.totalAutoIncrTrigger = trigger
75 s.totalAutoIncrBy = amount
76 s.totalAutoIncrBy = n
7677 }
7778 }
7879
79 // BarRemoveOnComplete is a flag, which will trigger bar auto remove on completion event.
80 // BarRemoveOnComplete is a flag, if set whole bar line will be removed on complete event.
81 // If both BarRemoveOnComplete and BarClearOnComplete are set, first bar section gets cleared
82 // and then whole bar line gets removed completely.
8083 func BarRemoveOnComplete() BarOption {
8184 return func(s *bState) {
8285 s.removeOnComplete = true
9194 }
9295 }
9396
94 // BarClearOnComplete clears the bar section on complete event.
97 // BarClearOnComplete is a flag, if set will clear bar section on complete event.
98 // If you need to remove a whole bar line, refer to BarRemoveOnComplete.
9599 func BarClearOnComplete() BarOption {
96100 return func(s *bState) {
97 s.noBarOnComplete = true
101 s.barClearOnComplete = true
98102 }
99103 }
100104