nanospinner: a minimal, zero-dependency terminal spinner

101 points SpaceJeans 5 comments

I made my first Rust project: nanospinner

It is mostly just for fun, but I noticed that there weren't any zero-dependency CLI spinners available on Cargo, so I used it as an opportunity to learn about vending a Rust project.

https://i.redd.it/4gbh6nvw64lg1.gif

The api is very simple:

// Create spinner
let handle = Spinner::new("Downloading files...").start();

// Finalize with success or fail
handle.success();           // ✔ Downloading files...
handle.fail();              // ✖ Downloading files...

You can also update the handler and/or stop without printing a symbol:

handle.update("Step 2...");
handle.stop(); // clears the line, no symbol printed

And write to a custom destination:

use std::io;

let handle = Spinner::with_writer("Processing...", io::stderr()).start();
thread::sleep(Duration::from_secs(1));
handle.success();

Basically it is just a super lightweight spinner, so if you don't need progress bars or multi-line support or any complex use cases, you could just use this instead of the heavier alternatives! A quick comparison to some other libraries in the space:

Crate Dependencies Clean Build Time Lines of Code
nanospinner 0 ~0.1s ~200
spinoff 3+ ~1.2s ~1,000+
indicatif 5+ ~1.4s ~5,000+

See docs: https://docs.rs/nanospinner/latest/nanospinner/

And Crate: https://crates.io/crates/nanospinner