pool_x.go 540 B

1234567891011121314151617181920212223242526272829
  1. // +build linux darwin freebsd netbsd openbsd solaris dragonfly
  2. package pb
  3. import "fmt"
  4. func (p *Pool) print(first bool) bool {
  5. p.m.Lock()
  6. defer p.m.Unlock()
  7. var out string
  8. if !first {
  9. out = fmt.Sprintf("\033[%dA", p.lastBarsCount)
  10. }
  11. isFinished := true
  12. for _, bar := range p.bars {
  13. if !bar.IsFinished() {
  14. isFinished = false
  15. }
  16. bar.Update()
  17. out += fmt.Sprintf("\r%s\n", bar.String())
  18. }
  19. if p.Output != nil {
  20. fmt.Fprint(p.Output, out)
  21. } else {
  22. fmt.Print(out)
  23. }
  24. p.lastBarsCount = len(p.bars)
  25. return isFinished
  26. }