Skip to content

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

Closed
@vyasgun

Description

@vyasgun

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions