pool_win.go 691 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. // +build windows
  2. package pb
  3. import (
  4. "fmt"
  5. "log"
  6. )
  7. func (p *Pool) print(first bool) bool {
  8. p.m.Lock()
  9. defer p.m.Unlock()
  10. var out string
  11. if !first {
  12. coords, err := getCursorPos()
  13. if err != nil {
  14. log.Panic(err)
  15. }
  16. coords.Y -= int16(p.lastBarsCount)
  17. if coords.Y < 0 {
  18. coords.Y = 0
  19. }
  20. coords.X = 0
  21. err = setCursorPos(coords)
  22. if err != nil {
  23. log.Panic(err)
  24. }
  25. }
  26. isFinished := true
  27. for _, bar := range p.bars {
  28. if !bar.IsFinished() {
  29. isFinished = false
  30. }
  31. bar.Update()
  32. out += fmt.Sprintf("\r%s\n", bar.String())
  33. }
  34. if p.Output != nil {
  35. fmt.Fprint(p.Output, out)
  36. } else {
  37. fmt.Print(out)
  38. }
  39. p.lastBarsCount = len(p.bars)
  40. return isFinished
  41. }