Trait conciliator::spin::Animate

source ·
pub trait Animate {
    type State: Default + Send;

    // Required methods
    fn step(&self, state: &mut Self::State, buf: &mut Buffer) -> Duration;
    fn finish(&self, state: Self::State, buf: &mut Buffer);
}
Expand description

Define a custom animation

This uses a separate mutable State to allow defining animations as constants.

Make sure that every “frame” or step of the animation has the same width!
Otherwise, the animation will overlap with the message or previous frames will not be overwritten completely. Note that the width is not strictly just the amount of characters, because the color codes and such are also emitted as characters – because the terminal doesn’t print these, you don’t have to make sure you emit the same amount of color codes in every frame. Just make sure the amount of characters that actually get printed stays the same.

Required Associated Types§

source

type State: Default + Send

Mutable state passed to the step function

For Animation this is just a usize index into the array of frames.

Required Methods§

source

fn step(&self, state: &mut Self::State, buf: &mut Buffer) -> Duration

Write the next frame of the animation into an empty Buffer

This method gets called once when the Spinner is created, and then again and again after each returned Duration has elapsed, until the Spinner is stopped.

source

fn finish(&self, state: Self::State, buf: &mut Buffer)

Write the final frame to an empty Buffer

Because this is the last frame, written as the Spinner is stopped, it won’t get overwritten later and will stick around in the terminal scrollback buffer.

This “frame” does not need to be the same width as the other frames.

Implementors§