Struct spinoff::Spinner

source ·
pub struct Spinner { /* private fields */ }
Expand description

Terminal spinner.

Implementations§

source§

impl Spinner

source

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 the Spinner::new_with_stream function.
source

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.
source

pub fn stop(&mut self)

Stop the spinner.

Example
let mut sp = Spinner::new(spinners::Dots9, "Spinning...", None);
sleep(Duration::from_millis(800));
sp.stop();
Notes
  • The spinner will be dropped after this method is called, the message will remain though.
source

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");
source

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!");
source

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!");
source

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!");
source

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...");
source

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!");
source

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();
source

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!");
source

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.
source

pub fn clear(&mut self)

Deletes the last line of the terminal.

Example
let mut sp = Spinner::new(spinners::Grenade, "Clearing...", None);
sleep(Duration::from_millis(800));
sp.clear();

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.