blob: 7002e85fc368d67296cb0c43c0a041832d4b288c [file] [log] [blame]
Abhay Kumara61c5222025-11-10 07:32:50 +00001//go:build windows
2// +build windows
3
4package pb
5
6import (
7 "fmt"
8 "log"
9 "strings"
10
11 "github.com/cheggaaa/pb/v3/termutil"
12)
13
14func (p *Pool) print(first bool) bool {
15 p.m.Lock()
16 defer p.m.Unlock()
17 var out string
18 if !first {
19 coords, err := termutil.GetCursorPos()
20 if err != nil {
21 log.Panic(err)
22 }
23 coords.Y -= int16(p.lastBarsCount)
24 if coords.Y < 0 {
25 coords.Y = 0
26 }
27 coords.X = 0
28
29 err = termutil.SetCursorPos(coords)
30 if err != nil {
31 log.Panic(err)
32 }
33 }
34 cols, err := termutil.TerminalWidth()
35 if err != nil {
36 cols = defaultBarWidth
37 }
38 isFinished := true
39 for _, bar := range p.bars {
40 if !bar.IsFinished() {
41 isFinished = false
42 }
43 result := bar.String()
44 if r := cols - CellCount(result); r > 0 {
45 result += strings.Repeat(" ", r)
46 }
47 out += fmt.Sprintf("\r%s\n", result)
48 }
49 if p.Output != nil {
50 fmt.Fprint(p.Output, out)
51 } else {
52 fmt.Print(out)
53 }
54 p.lastBarsCount = len(p.bars)
55 return isFinished
56}