pb
pb copied to clipboard
ProgressBar Pool on Windows: Inconsistent printing on Windows when using ProgressBarTemplate
I am trying to use Pool
to print progressbars with a custom template but adding the color attribute is causing unexpected output on Windows. A workaround that seems to fix this is by turning off the RawMode
Test code:
package main
import (
"fmt"
"math/rand"
"time"
"github.com/cheggaaa/pb/v3"
)
func main() {
tmpl := `{{ red "first" }} {{ bar . "[" "|" "|" "-" "]" }} {{ percent . }} `
myBar := pb.ProgressBarTemplate(tmpl).New(101)
myPool := pb.NewPool(myBar)
err := myPool.Start()
if err != nil {
fmt.Println("Error starting pool", err)
}
defer func() {
if err := myPool.Stop(); err != nil {
fmt.Println("Error stopping pool", err)
}
}()
for i := 0; i < 10; i++ {
myBar.SetTotal(100)
myBar.SetCurrent(rand.Int63() % 101)
time.Sleep(time.Second)
}
}
Expected output:
Actual output:
The issue goes away on Windows by turning off the raw mode after starting the pool:
if runtime.GOOS == "windows" {
if err := termutil.RawModeOff(); err != nil {
fmt.Println("Error turning off raw mode", err)
}
}
Did you check it with the Windows command line or powershell? Because it could be different for IDE terminal
Yes, I have.
-
Powershell:
-
cmd:
FYI: We had several of our users reports this; https://github.com/crc-org/crc/issues/3936. At first we thought this was related to Windows Terminal or an IDE hosted terminal, but seems the console host does the same.
Version v3.1.5 created