pterm / pterm

✨ #PTerm is a modern Go module to easily beautify console output. Featuring charts, progressbars, tables, trees, text input, select menus and much more 🚀 It's completely configurable and 100% cross-platform compatible.

Home Page:https://pterm.sh

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

mutli-live-printers + spinner update text not working

kpurdon opened this issue · comments

calling Spinner.UpdateText seems to not work in the mult-live-printers situation. Updating the multi live printer example to include update spinner text illustrates the issue:

Screen.Recording.2023-11-01.at.4.24.35.PM.mov
package main

import (
	"github.com/pterm/pterm"
	"time"
	"fmt"
)

func main() {
	multi := pterm.DefaultMultiPrinter

	spinner1, _ := pterm.DefaultSpinner.WithWriter(multi.NewWriter()).Start("Spinner 1")
	spinner2, _ := pterm.DefaultSpinner.WithWriter(multi.NewWriter()).Start("Spinner 2")
	pb1, _ := pterm.DefaultProgressbar.WithTotal(100).WithWriter(multi.NewWriter()).Start("Progressbar 1")
	pb2, _ := pterm.DefaultProgressbar.WithTotal(100).WithWriter(multi.NewWriter()).Start("Progressbar 2")
	pb3, _ := pterm.DefaultProgressbar.WithTotal(100).WithWriter(multi.NewWriter()).Start("Progressbar 3")
	pb4, _ := pterm.DefaultProgressbar.WithTotal(100).WithWriter(multi.NewWriter()).Start("Progressbar 4")
	pb5, _ := pterm.DefaultProgressbar.WithTotal(100).WithWriter(multi.NewWriter()).Start("Progressbar 5")

	multi.Start()

	// Randomly increment progress bars for demo purposes.
	for i := 1; i <= 100; i++ {
		pb1.Increment()

		if i%2 == 0 {
			pb2.Add(3)
		}

		if i%5 == 0 {
			pb3.Increment()
			spinner1.UpdateText(fmt.Sprintf("New Spinner 1 %d", i))
		}

		if i%10 == 0 {
			pb4.Increment()
		}

		if i%3 == 0 {
			pb5.Increment()
			spinner2.UpdateText(fmt.Sprintf("New Spinner 2 %d", i))
		}

		if i%50 == 0 {
			spinner1.Success("Spinner 1 is done!")
		}

		if i%60 == 0 {
			spinner2.Fail("Spinner 2 failed!")
		}

		time.Sleep(time.Millisecond * 50)
	}

	multi.Stop()
}

Update, this appears to just be a formatting issue ... maybe not a bug? I expected this to just_work with most terminals ... thoughts?

Screen.Recording.2023-11-02.at.8.36.09.AM.mov

Seems likely to be a mostly duplicate of #446 (light terminal not tested)