schollz / progressbar

A really basic thread-safe progress bar for Golang applications
https://pkg.go.dev/github.com/schollz/progressbar/v3?tab=doc
MIT License
4.08k stars 220 forks source link

Other logs while progressbar is running #185

Closed chirag-ghosh closed 4 months ago

chirag-ghosh commented 4 months ago

If other logs are printed while the progressbar runs, this happens image

Is there a way to remove those leftover progressbar lines?

schollz commented 4 months ago

what you do mean exactly? you want things to be logged and also show a progressbar, like at the bottom of the terminal?

you could log to a file instead and track the log there instead of in the same stdout

chirag-ghosh commented 4 months ago

what you do mean exactly? you want things to be logged and also show a progressbar, like at the bottom of the terminal?

Yes

you could log to a file instead and track the log there instead of in the same stdout

Sure but I wanted to log to the terminal itself and wondered if there's a way. Not a big deal though

csw commented 4 months ago

I do this by clearing the bar, logging what I need to, and then re-rendering the bar, like

pBar.Clear()
logStuff()
pBar.RenderBlank()

It works, but you'll need to make sure there aren't concurrent progress bar updates, there isn't any inappropriate buffering, etc.

schollz commented 4 months ago

good advice @csw, it is tricky though if you have multiple logging lines and have to sandwich all of them.

@chirag-ghosh you might need to look at another project like mpb or something (not sure if that doesn't either). I think generally logging + progressbars are not a thing...I've only seen them in the docker build functions so maybe that codebase will give you a hint (though I bet its complicated).

I'm closing this because its not part of the scope