pub struct Spinner { /* private fields */ }
Expand description
Terminal spinner.
Implementations§
source§impl Spinner
impl Spinner
sourcepub fn new<S, T, U>(spinner_type: S, msg: T, color: U) -> Selfwhere
S: Into<SpinnerFrames>,
T: Into<Cow<'static, str>>,
U: Into<Option<Color>>,
pub fn new<S, T, U>(spinner_type: S, msg: T, color: U) -> Selfwhere S: Into<SpinnerFrames>, T: Into<Cow<'static, str>>, U: Into<Option<Color>>,
Create a new spinner.
Arguments
spinner_type
- The spinner to use.msg
- The message to display.color
- The color of the spinner.
Example
let mut sp = Spinner::new(spinners::Dots, "Hello World!", Color::Blue);
sleep(Duration::from_millis(800));
sp.stop();
Notes
- The spinner immediately starts spinning upon creation.
- This function outputs to the
stdout
stream. If you want to use a different stream, use theSpinner::new_with_stream
function.
sourcepub fn new_with_stream<S, T, U>(
spinner_type: S,
msg: T,
color: U,
stream: Streams
) -> Selfwhere
S: Into<SpinnerFrames>,
T: Into<Cow<'static, str>>,
U: Into<Option<Color>>,
pub fn new_with_stream<S, T, U>( spinner_type: S, msg: T, color: U, stream: Streams ) -> Selfwhere S: Into<SpinnerFrames>, T: Into<Cow<'static, str>>, U: Into<Option<Color>>,
Create a new spinner outputting to a specific stream.
Arguments
spinner_type
- The spinner to use.msg
- The message to display.color
- The color of the spinner.stream
- The stream to output to.
Example
let mut sp = Spinner::new_with_stream(spinners::Dots, "I'm outputting to stderr!", Color::Yellow, Streams::Stderr);
sleep(Duration::from_millis(800));
sp.clear();
Notes
- The spinner immediately starts spinning upon creation.
sourcepub fn stop_with_message(&mut self, msg: &str)
pub fn stop_with_message(&mut self, msg: &str)
Stops the spinner and prints a message on a new line.
Example
let mut sp = Spinner::new(spinners::Dots2, "Hello", None);
sleep(Duration::from_millis(800));
sp.stop_with_message("Bye");
sourcepub fn stop_and_persist(&mut self, symbol: &str, msg: &str)
pub fn stop_and_persist(&mut self, symbol: &str, msg: &str)
Deletes the spinner and message and prints a new line with a symbol and message.
Example
let mut sp = Spinner::new(spinners::Mindblown, "Guess what's coming...", None);
sleep(Duration::from_millis(800));
sp.stop_and_persist("🍕", "Pizza!");
sourcepub fn success(&mut self, msg: &str)
pub fn success(&mut self, msg: &str)
Deletes the last line of the terminal and prints a success symbol with a message.
Example
let mut sp = Spinner::new(spinners::Aesthetic, "Trying to load information...", None);
sleep(Duration::from_millis(800));
sp.success("Success!");
sourcepub fn fail(&mut self, msg: &str)
pub fn fail(&mut self, msg: &str)
Deletes the last line of the terminal and prints a failure symbol with a message to stderr.
Example
let mut sp = Spinner::new(spinners::BouncingBar, "Executing code...", Color::Green);
sleep(Duration::from_millis(800));
sp.fail("Code failed to compile!");
sourcepub fn warn(&mut self, msg: &str)
pub fn warn(&mut self, msg: &str)
Deletes the last line of the terminal and prints a warning symbol with a message.
Example
let mut sp = Spinner::new(spinners::Material, "Measuring network speed...", None);
sleep(Duration::from_millis(800));
sp.warn("You might want to check your internet connection...");
sourcepub fn info(&mut self, msg: &str)
pub fn info(&mut self, msg: &str)
Deletes the last line of the terminal and prints an info symbol with a message.
Example
let mut sp = Spinner::new(spinners::Dots9, "Loading info message...", None);
sleep(Duration::from_millis(800));
sp.info("This is an info message!");
sourcepub fn update<S, T, U>(&mut self, spinner: S, msg: T, color: U)where
S: Into<SpinnerFrames>,
T: Into<Cow<'static, str>>,
U: Into<Option<Color>>,
pub fn update<S, T, U>(&mut self, spinner: S, msg: T, color: U)where S: Into<SpinnerFrames>, T: Into<Cow<'static, str>>, U: Into<Option<Color>>,
Updates the spinner.
Example
let mut sp = Spinner::new(spinners::Dots, "Hello", None);
sleep(Duration::from_millis(800));
sp.update(spinners::Dots2, "World", None);
sleep(Duration::from_millis(800));
sp.stop();
sourcepub fn update_text<T>(&mut self, msg: T)where
T: Into<Cow<'static, str>>,
pub fn update_text<T>(&mut self, msg: T)where T: Into<Cow<'static, str>>,
Update the spinner text.
Example
let mut sp = Spinner::new(spinners::Arc, "Loading...", Color::Magenta);
sleep(Duration::from_millis(800));
sp.update_text("Not quite finished...");
sleep(Duration::from_millis(800));
sp.update_text("Almost done...");
sleep(Duration::from_millis(800));
sp.success("Done!");
sourcepub fn update_after_time<T>(&mut self, updated_msg: T, duration: Duration)where
T: Into<Cow<'static, str>>,
pub fn update_after_time<T>(&mut self, updated_msg: T, duration: Duration)where T: Into<Cow<'static, str>>,
Updates the spinner text after a certain amount of time has passed since the initial ::new
call.
Example
let mut sp = Spinner::new(spinners::Arc, "Loading...", Color::Blue);
sp.update_after_time("Not Done Yet...", Duration::from_secs(2));
sleep(Duration::from_millis(800));
sp.success("Done!");
Notes
- This could be used to assure the user that the program is still running.
Auto Trait Implementations§
impl !RefUnwindSafe for Spinner
impl Send for Spinner
impl Sync for Spinner
impl Unpin for Spinner
impl !UnwindSafe for Spinner
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more