Skip to content

Commit

Permalink
pool: fill line with spaces
Browse files Browse the repository at this point in the history
  • Loading branch information
cheggaaa committed Jul 11, 2023
1 parent 1e17fcc commit 39ed47a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
9 changes: 7 additions & 2 deletions v3/pool_win.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build windows
// +build windows

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

err = termutil.SetCursorPos(coords)
err = termutil.SetCursorPos(coords)
if err != nil {
log.Panic(err)
}
Expand All @@ -34,7 +35,11 @@ func (p *Pool) print(first bool) bool {
if !bar.IsFinished() {
isFinished = false
}
out += fmt.Sprintf("\r%s\n", bar.String())
result := bar.String()
if r := cols - CellCount(result); r > 0 {
result += strings.Repeat(" ", r)
}
out += fmt.Sprintf("\r%s\n", result)
}
if p.Output != nil {
fmt.Fprint(p.Output, out)
Expand Down
8 changes: 7 additions & 1 deletion v3/pool_x.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
//go:build linux || darwin || freebsd || netbsd || openbsd || solaris || dragonfly || plan9 || aix
// +build linux darwin freebsd netbsd openbsd solaris dragonfly plan9 aix

package pb

import (
"fmt"
"os"
"strings"

"github.com/cheggaaa/pb/v3/termutil"
)
Expand All @@ -31,7 +33,11 @@ func (p *Pool) print(first bool) bool {
isFinished = false
}
bar.SetWidth(cols)
out += fmt.Sprintf("\r%s\n", bar.String())
result := bar.String()
if r := cols - CellCount(result); r > 0 {
result += strings.Repeat(" ", r)
}
out += fmt.Sprintf("\r%s\n", result)
}
if p.Output != nil {
fmt.Fprint(p.Output, out)
Expand Down

0 comments on commit 39ed47a

Please sign in to comment.