spinners icon indicating copy to clipboard operation
spinners copied to clipboard

`spinner.stop()` doesn't remove the spinner or text from the console

Open samuela opened this issue 6 years ago • 6 comments

  let sp = spinners::Spinner::new(
    spinners::Spinners::Dots9,
    "Checking for a new version".into(),
  );
  let v = get_version();
  sp.stop();
  println!("{}", "all done!");

Outputs:

$ ./my-binary
⢼ Checking for a new versionall done!

whereas I would expect it to flash the spinner for a second and then end up printing:

$ ./my-binary
all done!

a la https://github.com/sindresorhus/ora.

samuela avatar Mar 23 '19 22:03 samuela

I ran into the same issue. As a temporary solution I brought in the console crate and call term.clear_line(); immediately after sp.stop();

It's not the best solution since it's bringing a whole other crate into the mix just to clear the line but it works.

Edit: Realized I forgot to mention it also needs term to be defined.

This will need to be set somewhere towards the top for this to work

let term = Term::stdout();

booth-f avatar Jul 11 '19 18:07 booth-f

I can open a PR for this if there is still interest.

mainrs avatar Jul 16 '20 14:07 mainrs

@mainrs yes please

peepo5 avatar Oct 01 '21 18:10 peepo5

I will accept a PR for this yes :)

FGRibreau avatar Oct 04 '21 11:10 FGRibreau

You can use print!("\r") to clear the last line in theory. Not sure if this works in practice.

jewlexx avatar Feb 15 '22 06:02 jewlexx

print!("\x1b[2K\r") is a better option (and it has worked well in my experience). Basically, just \r will only move the cursor to the first column of the line and then overwrite any text printed after that but if the text printed after that is not as big or bigger than the text that already existed, the old text will remain.

Source: This SO post - https://stackoverflow.com/questions/1508490/erase-the-current-printed-console-line Note: the escape sequence in rust has to be hexadecimal so it looks a little different here

AnishDe12020 avatar Jun 15 '22 11:06 AnishDe12020

@AnishDe12020 works flawlessly, thanks.

im-n1 avatar Apr 14 '23 19:04 im-n1

please use sp.stop_with_symbol("\x1b[32m🗸\x1b[0m");

FGRibreau avatar May 23 '23 06:05 FGRibreau