piotrmurach / tty-spinner

A terminal spinner for tasks that have non-deterministic time frame.
https://ttytoolkit.org
MIT License
427 stars 28 forks source link

Multi spinners always display in the same order #25

Closed piotrmurach closed 7 years ago

piotrmurach commented 7 years ago

@austb I have recently implemented multi bar rendering in tty-progressbar and along the way realised a rather important bug in the TTY::Spinner::Multi implementation.

The multi spinners display always renders the spinners in the order they were registered with. This is a rather dangerous assumption, especially in multi threaded environment when you don't know when each spinner will be started. This in turn means that the logic for moving to the correct line is wrong as it assumes the registered index is the line that spinner needs to be rendered at.

Initially it was hard to observe this bug due to the fact that each spinner has the same display width and they simply paint over each other, but when I was working with different sized progress bars the situation was quickly obvious.

The solution is to register spinners without index and assign the actual row number when the spinner is rendered for the first time. I'm going to add this fix soon, just wanted to note it and let you know. I've attached reference to test case that shows this issue.