spinners icon indicating copy to clipboard operation
spinners copied to clipboard

Is there a way to place the spinner on a chosen column?

Open Tyrn opened this issue 4 years ago • 4 comments

Hi,

Say, the second console column, instead of the first one by default. It looks like SpinnerBuilder is responsible for customization, but it is unavailable in the spinners context. Or is it just my lack of experience?

This example does precisely what I want:

extern crate spinner;

use std::time::Duration;
use std::thread;

use spinner::SpinnerBuilder;

fn main() {
    let sp = SpinnerBuilder::new("Long Running op!".into()).
        format(|sp, status|{
            format!("   {spin} -- Currently working on: \'{status}\' -- {spin}",
                    spin = sp, status = status)
        }).start();
    thread::sleep(Duration::from_millis(2000));
    sp.message("Updating...".into());
    sp.update("Fixing things...".into());
    thread::sleep(Duration::from_millis(2000));
    sp.message("Done!".into());
    sp.close();
}

The line

            format!("   {spin} -- Currently working on: \'{status}\' -- {spin}",

Is all I need.

Tyrn avatar Dec 18 '21 14:12 Tyrn

Hello!

Yes I will accept a PR that let you specify a lambda instead of a string as a second argument of Spinner::new

Spinner::new(Spinners::Dots9, |sp, status| {format!("   {spin} -- Currently working on: \'{status}\' -- {spin}"});

We could leverage trait to do that.

FGRibreau avatar Jan 02 '22 09:01 FGRibreau

Thanks! I am not very well versed with pull requests and things. I understand that some coding is supposed be mine, and some yours. I am not sure about which responsibility goes to whom.

Tyrn avatar Jan 10 '22 06:01 Tyrn

It can go that way, try to make the change you want and submit the patch (the pull-request) and from there we will see what to do next :)

FGRibreau avatar Jan 10 '22 06:01 FGRibreau

I've made a fork, messed around with it a bit. I can probably make a patch, formally, but I can't see a reasonably clean solution so far. First thing you'd have to do, is to trash it :)

I did it, finally. Not sure whether to be proud of the result.

Tyrn avatar Jan 12 '22 09:01 Tyrn