Struct conciliator::spin::Spinner

source ·
pub struct Spinner<'c> { /* private fields */ }
Expand description

Show that something is ongoing with an animated tag & message

This starts a separate thread (or task) that periodically overwrites the last line of the output to show the next frame of the animation. Any other output would interfere with this, so this struct tries to guard against that by holding a mutable reference to the Claw that spawned it. This ensures that that particular Claw can’t be used for the lifetime of the Spinner.

See the module-level documentation for more.

Implementations§

source§

impl<'c> Spinner<'c>

source

pub fn new<A, I>(claw: &'c mut Claw, animate: A, message: I) -> Self
where A: Animate + Send + 'static, I: InitialContent,

Create a new Spinner using the given animation and message

source

pub fn message<I: InitialContent>(&self, init: I) -> Message<'_>

Update the spinner message

The message should be short enough to fit on a single line in the terminal, and it should not contain any newlines. If the message line wraps to another line, the spinner will get messed up and leave behind lines that it shouldn’t.

source

pub async fn finish(self)

Available on crate feature tokio only.

Stop spinning

This changes the animation frame to show the spinner is done and un-hides the cursor. The last message set will be written out and become part of the normal output.

Note that without the tokio feature, this function is not async.

source

pub async fn clear(self)

Available on crate feature tokio only.

Stop spinning & remove the message line

Note that without the tokio feature, this function is not async.

Trait Implementations§

source§

impl<'c> Conciliator for Spinner<'c>

source§

fn line<I: InitialContent>(&self, init: I) -> <Self as GetLine<'_>>::Line

Get a plain buffer without a tag
source§

fn status<I: InitialContent>(&self, init: I) -> <Self as GetLine<'_>>::Line

Get a line buffer with the status tag
source§

fn info<I: InitialContent>(&self, init: I) -> <Self as GetLine<'_>>::Line

Get a line buffer with the info tag
source§

fn warn<I: InitialContent>(&self, init: I) -> <Self as GetLine<'_>>::Line

Get a line buffer with the warn tag
source§

fn error<I: InitialContent>(&self, init: I) -> <Self as GetLine<'_>>::Line

Get a line buffer with the error tag
source§

fn print<T: Print>(&self, thing: T)

Print a multi-line text segment
source§

impl<'l, 'c> GetLine<'l> for Spinner<'c>

§

type Line = Line<'l>

Type of the line buffer (does not have to be the struct Line)
source§

fn get_line(&'l self) -> Self::Line

Obtain a new line buffer

Auto Trait Implementations§

§

impl<'c> !RefUnwindSafe for Spinner<'c>

§

impl<'c> Send for Spinner<'c>

§

impl<'c> Sync for Spinner<'c>

§

impl<'c> Unpin for Spinner<'c>

§

impl<'c> !UnwindSafe for Spinner<'c>

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where 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 T
where 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 T
where 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 T
where 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.