Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
vyasgun opened this issue Jan 17, 2024 · 4 comments

Comments

@vyasgun
Copy link
Contributor

vyasgun commented Jan 17, 2024

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)
	}
}
@cheggaaa
Copy link
Owner

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

@vyasgun
Copy link
Contributor Author

vyasgun commented Jan 22, 2024

Yes, I have.

  • Powershell:
Screenshot 2024-01-22 160057
  • cmd:
Screenshot 2024-01-22 160128

@gbraad
Copy link

gbraad commented Jan 23, 2024

FYI: We had several of our users reports this; crc-org/crc#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

@cheggaaa
Copy link
Owner

Version v3.1.5 created

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants