Struct termprogress::spinner::Spin
source · pub struct Spin<T: ?Sized = Stdout> { /* private fields */ }
Expand description
A single character spinner with optional title that can be told to spin whenever it wants. It implements Spinner
trait, and is the default spinner.
The spinner takes up a line, and renders it’s spinner on the end of its title. Calling the Spinner::bump()
function will cause the character sequence to advance.
Usage
To use the spinner you can provide it a Wheel
(see [wheel] module), or it implements the Default
trait, creating a traditional looking spinner (|/-\
)
let mut spin = Spin::default(); //Default new spinner without a title.
How it looks
It renders in the terminal like:
This is a spinner /
Thread Sync
safety
This type is safely Sync
(where T
is), the behaviour is defined to prevent overlapping writes to T
.
Though it is advised to not render a Spin
from more than a single thread, you still safely can.
A display operation on one thread will cause any other threads attempting on to silently and safely abort their display attempt before anything is written to output.
Implementations§
source§impl Spin
impl Spin
sourcepub fn with_title_default(title: &str, whl: Wheel) -> Self
pub fn with_title_default(title: &str, whl: Wheel) -> Self
Create a new spinner with title and wheel writing to stdout
.
To give it the default wheel, you can pass whl
Default::default()
to use the default one.
sourcepub fn new_default(whl: Wheel) -> Self
pub fn new_default(whl: Wheel) -> Self
Create a new blank spinner with a wheel writing to stdout
.
Example
Spin::new_default(Default::default()); // Create a spinner with the default wheel ('|/-\') that writes to stdout.
source§impl<T> Spin<T>
impl<T> Spin<T>
sourcepub fn into_inner(self) -> T
pub fn into_inner(self) -> T
Return the backing write object
source§impl<T: ?Sized> Spin<T>
impl<T: ?Sized> Spin<T>
sourcepub fn inner(&self) -> Option<AtomicRef<'_, T>>
pub fn inner(&self) -> Option<AtomicRef<'_, T>>
Get a shared reference to the inner object
Returns
None
is returned if a display operation is currently in progress on another thread.
Operation suspension
As long as the returned reference lives, all display operations will fail silently, on this thread and any other. This method should be avoided in favour of &*inner_mut()
when exclusive ownership is avaliable.
source§impl<T: Write> Spin<T>
impl<T: Write> Spin<T>
sourcepub fn with_title(output: T, title: &str, whl: Wheel) -> Self
pub fn with_title(output: T, title: &str, whl: Wheel) -> Self
Create a new spinner with title and wheel writing to output
.
To give it the default wheel, you can pass whl
Default::default()
to use the default one.
sourcepub fn new(output: T, whl: Wheel) -> Self
pub fn new(output: T, whl: Wheel) -> Self
Create a new blank spinner with a wheel writing to output
.
Example
Spin::new(std::io::stdout(), Default::default()); // Create a spinner with the default wheel ('|/-\') that writes to stdout.
sourcepub fn complete(self) -> Result<()>
pub fn complete(self) -> Result<()>
Consume the spinner and complete it. Removes the spin character.
sourcepub fn complete_with(self, msg: &str) -> Result<()>
pub fn complete_with(self, msg: &str) -> Result<()>
Consume the spinner and complete it with a message. Removes the spin character and then prints the message.