PackageManager just because
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

41 lines
661 B

  1. package ProgressBar
  2. import (
  3. "sync"
  4. "github.com/vbauerster/mpb"
  5. "github.com/vbauerster/mpb/decor"
  6. )
  7. var (
  8. BarWG sync.WaitGroup
  9. P = mpb.New(mpb.WithWaitGroup(&BarWG))
  10. )
  11. func InitBar(name string, total int) *mpb.Bar {
  12. var (
  13. bar *mpb.Bar
  14. )
  15. BarWG.Add(1)
  16. bar = P.AddBar(int64(total),
  17. mpb.PrependDecorators(
  18. decor.Name(name),
  19. decor.Percentage(decor.WCSyncSpace),
  20. ),
  21. mpb.AppendDecorators(
  22. // replace ETA decorator with "done" message, OnComplete event
  23. decor.OnComplete(
  24. decor.AverageETA(decor.ET_STYLE_GO, decor.WC{W: 4}), "done",
  25. ),
  26. ),
  27. )
  28. return bar
  29. }
  30. func CloseBar(bar *mpb.Bar) {
  31. bar.Abort(false)
  32. BarWG.Done()
  33. }