pub struct Spinner { /* private fields */ }Expand description
Progress spinner for long-running CLI operations.
When stderr is a TTY, draws an animated spinner via indicatif,
ticks in the background, and disables stdin echo to prevent
keypress jank. When stderr is not a TTY, skips all indicatif
machinery and falls back to plain stderr writes.
Call finish with a completion message to replace it with a
final line, or let it drop to remove it silently; Drop also
restores echo and clears the bar so a panic or early ?
propagation leaves the terminal in a usable state. Under
panic = "abort", Drop does NOT run on a panic — the panic hook
installed by install_spinner_termios_panic_hook restores
termios instead, so the panic message renders cleanly before
SIGABRT kills the process. Note: Drop also does NOT run on
SIGINT/SIGTERM kill; if the spinner is interrupted mid-operation,
run stty sane to restore echo.
Implementations§
Source§impl Spinner
impl Spinner
Sourcepub fn start(msg: impl Into<Cow<'static, str>>) -> Self
pub fn start(msg: impl Into<Cow<'static, str>>) -> Self
Start a spinner with the given message (e.g. “Building kernel…”).
When stderr is not a TTY, no ProgressBar or ticker thread is
created — all output methods fall back to plain eprintln!.
Sourcepub fn set_message(&self, msg: impl Into<Cow<'static, str>>)
pub fn set_message(&self, msg: impl Into<Cow<'static, str>>)
Update the spinner message.
Sourcepub fn finish(self, msg: impl Into<Cow<'static, str>>)
pub fn finish(self, msg: impl Into<Cow<'static, str>>)
Finish the spinner, replacing it with a completion message.
In non-TTY mode, prints the message to stderr directly.
Sourcepub fn println(&self, msg: impl AsRef<str>)
pub fn println(&self, msg: impl AsRef<str>)
Print a line above the spinner. The spinner redraws below.
In non-TTY mode, prints directly to stderr.
Sourcepub fn suspend<F: FnOnce() -> R, R>(&self, f: F) -> R
pub fn suspend<F: FnOnce() -> R, R>(&self, f: F) -> R
Suspend the spinner tick, execute a closure, then resume. Use for terminal output that must not race with the spinner.
In non-TTY mode, calls f directly (no spinner to suspend).
Sourcepub fn with_progress<T, E, F>(
start_msg: impl Into<Cow<'static, str>>,
success_msg: impl Into<Cow<'static, str>>,
f: F,
) -> Result<T, E>
pub fn with_progress<T, E, F>( start_msg: impl Into<Cow<'static, str>>, success_msg: impl Into<Cow<'static, str>>, f: F, ) -> Result<T, E>
Run f under a spinner that starts with start_msg, replaces
itself with success_msg on Ok, and drops silently on Err
so the error propagates without a stale progress bar obscuring
the caller’s diagnostics. The closure receives the live
&Spinner so it can call Self::println / Self::suspend
/ Self::set_message during the operation.
Trait Implementations§
Source§impl Drop for Spinner
impl Drop for Spinner
Source§fn drop(&mut self)
fn drop(&mut self)
Restore terminal echo and clear any live progress bar on drop.
finish calls Self::teardown and takes
self.pb via Option::take, so this impl is a no-op after
an explicit end. When the spinner is dropped implicitly
(panic, ? propagation, drop(sp), or scope exit), this
restores the termios saved in Self::disable_echo and
clears the live bar so stdin is usable afterwards.
Auto Trait Implementations§
impl Freeze for Spinner
impl RefUnwindSafe for Spinner
impl Send for Spinner
impl Sync for Spinner
impl Unpin for Spinner
impl UnwindSafe for Spinner
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more