Skip to content

Commit 39ed47a

Browse files
committed
pool: fill line with spaces
1 parent 1e17fcc commit 39ed47a

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

v3/pool_win.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//go:build windows
12
// +build windows
23

34
package pb
@@ -24,7 +25,7 @@ func (p *Pool) print(first bool) bool {
2425
}
2526
coords.X = 0
2627

27-
err = termutil.SetCursorPos(coords)
28+
err = termutil.SetCursorPos(coords)
2829
if err != nil {
2930
log.Panic(err)
3031
}
@@ -34,7 +35,11 @@ func (p *Pool) print(first bool) bool {
3435
if !bar.IsFinished() {
3536
isFinished = false
3637
}
37-
out += fmt.Sprintf("\r%s\n", bar.String())
38+
result := bar.String()
39+
if r := cols - CellCount(result); r > 0 {
40+
result += strings.Repeat(" ", r)
41+
}
42+
out += fmt.Sprintf("\r%s\n", result)
3843
}
3944
if p.Output != nil {
4045
fmt.Fprint(p.Output, out)

v3/pool_x.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1+
//go:build linux || darwin || freebsd || netbsd || openbsd || solaris || dragonfly || plan9 || aix
12
// +build linux darwin freebsd netbsd openbsd solaris dragonfly plan9 aix
23

34
package pb
45

56
import (
67
"fmt"
78
"os"
9+
"strings"
810

911
"github.com/cheggaaa/pb/v3/termutil"
1012
)
@@ -31,7 +33,11 @@ func (p *Pool) print(first bool) bool {
3133
isFinished = false
3234
}
3335
bar.SetWidth(cols)
34-
out += fmt.Sprintf("\r%s\n", bar.String())
36+
result := bar.String()
37+
if r := cols - CellCount(result); r > 0 {
38+
result += strings.Repeat(" ", r)
39+
}
40+
out += fmt.Sprintf("\r%s\n", result)
3541
}
3642
if p.Output != nil {
3743
fmt.Fprint(p.Output, out)

0 commit comments

Comments
 (0)