pb icon indicating copy to clipboard operation
pb copied to clipboard

ProgressBar Pool on Windows: Inconsistent printing on Windows when using ProgressBarTemplate

Open vyasgun opened this issue 1 year ago • 2 comments

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: Screenshot 2024-01-17 221701

Actual output: Screenshot 2024-01-17 221713

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)
	}
}

vyasgun avatar Jan 17 '24 16:01 vyasgun

Did you check it with the Windows command line or powershell? Because it could be different for IDE terminal

cheggaaa avatar Jan 19 '24 15:01 cheggaaa

Yes, I have.

  • Powershell: Screenshot 2024-01-22 160057

  • cmd:

Screenshot 2024-01-22 160128

vyasgun avatar Jan 22 '24 10:01 vyasgun

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.

daemon1

gbraad avatar Jan 23 '24 06:01 gbraad

Version v3.1.5 created

cheggaaa avatar Jan 25 '24 10:01 cheggaaa