`spinner.stop()` doesn't remove the spinner or text from the console
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.
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();
I can open a PR for this if there is still interest.
@mainrs yes please
I will accept a PR for this yes :)
You can use print!("\r") to clear the last line in theory. Not sure if this works in practice.
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 works flawlessly, thanks.
please use sp.stop_with_symbol("\x1b[32m🗸\x1b[0m");