Struct throbber::Throbber [−][src]
Representation of a throbber animation. It can start, succeed, fail or end at any point.
Note that a call to end
takes ownership of the struct and drops it, as such it should be called to completely remove the throbber animtion object. If you want to start another animation afterwards, you have to create a new Throbber
object. This is done because multiple calls to start do not actually create multiple threads, instead a call to a finish function (like success
) simply parks the thread and a following start
call unparks that thread again. As such, a call to end
kills the thread entirely. If you want to just stop the animation, but potentially start it again later on, use finish
instead.
Examples
use throbber::Throbber; use std::thread; use std::time::Duration; let mut throbber = Throbber::new() .message("calculating stuff".to_string()) .interval(Duration::from_millis(50)) .frames(&throbber::ROTATE_F); throbber.start(); // do stuff thread::sleep(Duration::from_secs(5)); throbber.success("calculation successful".to_string()); throbber.end();
Implementations
impl Throbber
[src]
pub fn new() -> Self
[src]
Creates a new Throbber object.
Default Values
If you do not customize your throbber animation with message
etc., these are the default values:
- message:
""
- interval:
Duration::from_millis(200)
- frames:
DEFAULT_F (⠋ ⠙ ⠹ ⠸ ⠼ ⠴ ⠦ ⠧ ⠇ ⠏)
pub fn message(self, msg: String) -> Self
[src]
Sets the message that’s supposed to print.
This does nothing if start
was called before. To change the message after start
was called, use change_message
instead.
pub fn interval(self, interval: Duration) -> Self
[src]
Sets the interval in which the animation frames are supposed to print.
This does nothing if start
was called before. To change the interval after start
was called, use change_interval
instead.
pub fn frames(self, frames: &'static [&'static str]) -> Self
[src]
Sets the animation frames that are supposed to print.
This does nothing if start
was called before. To change the animation frames after start
was called, use change_frames
instead.
pub fn change_message(&mut self, msg: String)
[src]
Changes the message that’s supposed to print.toml
Unlike message
, this will work both before and after start
was called.
pub fn change_interval(&mut self, interval: Duration)
[src]
Changes the interval in which the animation frames are supposed to print.
Unlike interval
, this will work both before and after start
was called.
pub fn change_frames(&mut self, frames: &'static [&'static str])
[src]
Changes the animation frames that are supposed to print.
Unlike frames
, this will work both before and after start
was called.
pub fn start(&mut self)
[src]
Starts the animation.
If this is the first call to start
, a new thread gets created to play the animation. Otherwise the thread that already exists gets unparked and starts the animation again.
pub fn start_with_msg(&mut self, msg: String)
[src]
Starts the animation with the specified msg
.
Equivalent to throbber.change_message(msg); throbber.start();
.
pub fn finish(&mut self)
[src]
Stops the current animation, leaving a blank line.
pub fn success(&mut self, msg: String)
[src]
Stops the current animation and prints msg
as a success message.
pub fn fail(&mut self, msg: String)
[src]
Stops the current animation and prints msg
as a fail message.
This does currently not print the fail message onto stderr, but stdout instead. That might change in a future version.
pub fn end(self)
[src]
Ends the animation thread and drops the throbber object. If you want to stop the animation without dropping the throbber object, use finish
instead.
Auto Trait Implementations
impl !RefUnwindSafe for Throbber
impl Send for Throbber
impl !Sync for Throbber
impl Unpin for Throbber
impl !UnwindSafe for Throbber
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,