spinoff icon indicating copy to clipboard operation
spinoff copied to clipboard

Displaying two spinners together

Open ClementNerma opened this issue 3 years ago • 5 comments

Hi there!

I'm currently building a project where I need to show two spinners for two different long-running tasks.

Is there a way to achieve this?

Thanks in advance for your help!

ClementNerma avatar Sep 22 '22 08:09 ClementNerma

It is doable, however the tricky part is stopping them. The library was initially designed for only one spinner to be run at a time, so if you would want to stop the first spinner before the second one, it would stop the second one instead. This is because "stopping" the spinner in the code is effectively just deleting the last line and rewriting it without the spinner.

I think in this use case there could be a work around (maybe doing some print!("\r") stuff, I'm not entirely sure), I could look into it in my free time.

ad4mx avatar Sep 26 '22 17:09 ad4mx

That would in fact require to move the cursor manually using a library like crossterm.

I opened this issue as I didn't know how the internal crate worked but if it's just a line rewrite currently it's a bit of work to make two spinners (or more) work together.

The good point being that if two spinners can be displayed together then si can be three, four, five etc.

ClementNerma avatar Sep 26 '22 17:09 ClementNerma

I dont think a library like crossterm is needed.

you can get the term position printing "\033[6n" and reading from input "^[[row;columnR". Save the position you get, and always go to that position when printing.

Pytness avatar Jan 30 '23 11:01 Pytness

@ad4mx Can I take a crack at it? I'm seeing if we can use an mpsc to output spinners from multiple threads into one stream.

peaske7 avatar Feb 06 '23 03:02 peaske7

@ad4mx Can I take a crack at it? I'm seeing if we can use an mpsc to output spinners from multiple threads into one stream.

Of course.

ad4mx avatar Feb 06 '23 15:02 ad4mx