Skip to content

Commit

Permalink
Merge pull request #208 from cheggaaa/pool-redraw-line
Browse files Browse the repository at this point in the history
pool: fill line with spaces
  • Loading branch information
cheggaaa authored Jul 11, 2023
2 parents 1e17fcc + 39ed47a commit 0eed328
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 0eed328

Please sign in to comment.