| Abhay Kumar | a61c522 | 2025-11-10 07:32:50 +0000 | [diff] [blame^] | 1 | //go:build windows |
| 2 | // +build windows |
| 3 | |
| 4 | package pb |
| 5 | |
| 6 | import ( |
| 7 | "fmt" |
| 8 | "log" |
| 9 | "strings" |
| 10 | |
| 11 | "github.com/cheggaaa/pb/v3/termutil" |
| 12 | ) |
| 13 | |
| 14 | func (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 | } |