Expand description
This crate serves as an alternative to loading. It is used to display a throbber animation in the terminal while other calculations are done in the main program.

§Usage
Add this to your Cargo.toml:
[dependencies]
throbber = "1.0"To display a throbber animation, first create a Throbber object:
use throbber::Throbber;
let mut throbber = Throbber::default();You can also customize certain settings like the displayed animation and the displayed message:
let mut throbber = Throbber::default()
.message("calculating stuff")
.frames(&throbber::MOVE_EQ_F); // this crate comes with a few predefined animations
// see the Constants sectionThen you can simply call start wherever you want to start the animation and a finish function like success where you want to stop it.
throbber.start();
// do calculations
throbber.success("calculations successful!");After, you can call start or start_with_msg again to start the animation again.
Setters are also provided, e.g. set_message and set_frames. This also works while an animation is running.
§Thread Lifetime
The Throbber thread gets spawned on the first call to start or start_with_msg. After that, the thread only ever gets parked.
If you want to end the thread, you must drop the Throbber object:
drop(throbber);§Examples
This is the example from the gif above:
use std::thread;
use std::time::Duration;
use throbber::Throbber;
fn main() {
let mut throbber = Throbber::default().message("calculating stuff");
throbber.start();
// do stuff
thread::sleep(Duration::from_secs(2));
throbber.success("Success");
throbber.start_with_msg("calculating more stuff");
// do other stuff
thread::sleep(Duration::from_secs(2));
throbber.fail("Fail");
}You can also keep track of progress with set_message:
use std::thread;
use std::time::Duration;
use throbber::Throbber;
fn main() {
let mut throbber = Throbber::new(
"Downloading file1 0%",
Duration::from_millis(100),
&throbber::ROTATE_F,
);
throbber.start();
for i in 0..100 {
throbber.set_message(format!("Downloading file1 {}%", i));
thread::sleep(Duration::from_millis(30));
}
throbber.success("Downloaded file1");
throbber.start_with_msg("Downloading file2 0%");
for i in 0..69 {
throbber.set_message(format!("Downloading file2 {}%", i));
thread::sleep(Duration::from_millis(30));
}
throbber.fail("Download of file2 failed");
}Structs§
- Throbber
- Representation of a throbber animation. It can start, succeed, fail or finish at any point.
Constants§
- CIRCLE_
F ◐ ◓ ◑ ◒- DEFAULT_
F ⠋ ⠙ ⠹ ⠸ ⠼ ⠴ ⠦ ⠧ ⠇ ⠏- MOVE_
EQ_ F [= ] [ = ] [ =] [ = ]- MOVE_
EQ_ LONG_ F [= ] [== ] [ == ] [ == ] [ ==] [ =] [ ==] [ == ] [ == ] [== ]- MOVE_
MIN_ F [- ] [ - ] [ -] [ - ]- MOVE_
MIN_ LONG_ F [- ] [-- ] [ -- ] [ -- ] [ --] [ -] [ --] [ -- ] [ -- ] [-- ]- ROTATE_
F | / - \