pub struct Spinner { /* private fields */ }Available on crate feature
spinner only.Expand description
A single-line terminal spinner with a live message.
Implementations§
Source§impl Spinner
impl Spinner
Sourcepub fn start(message: impl Into<String>) -> Self
pub fn start(message: impl Into<String>) -> Self
Start the spinner with an initial message.
When stderr is not a TTY no thread is spawned and ticks are
suppressed; terminal completion lines (success/failure)
are still printed so logs remain informative.
The first TTY-bound call also installs a process-wide SIGINT /
SIGTERM / SIGHUP handler and a panic hook that restore the
cursor before letting the process die: Drop is skipped on
signal-induced termination and on panic = abort, so without
these hooks cursor::Hide from the render loop would leak
past process exit.
Examples found in repository?
examples/spinner.rs (line 12)
11fn main() {
12 let spinner = Spinner::start("Resolving MX records for example.com…");
13 sleep(Duration::from_secs(1));
14
15 spinner.set_message("Probing imap.example.com:993");
16 sleep(Duration::from_secs(1));
17
18 spinner.set_message("Probing smtp.example.com:465");
19 sleep(Duration::from_secs(1));
20
21 spinner.success("Found IMAP at imap.example.com:993 and SMTP at smtp.example.com:465");
22
23 let spinner = Spinner::start("Probing pop.example.com:995");
24 sleep(Duration::from_secs(1));
25 spinner.failure("No POP server reachable at pop.example.com:995");
26}Sourcepub fn set_message(&self, message: impl Into<String>)
pub fn set_message(&self, message: impl Into<String>)
Replace the message displayed next to the spinner frame.
Examples found in repository?
examples/spinner.rs (line 15)
11fn main() {
12 let spinner = Spinner::start("Resolving MX records for example.com…");
13 sleep(Duration::from_secs(1));
14
15 spinner.set_message("Probing imap.example.com:993");
16 sleep(Duration::from_secs(1));
17
18 spinner.set_message("Probing smtp.example.com:465");
19 sleep(Duration::from_secs(1));
20
21 spinner.success("Found IMAP at imap.example.com:993 and SMTP at smtp.example.com:465");
22
23 let spinner = Spinner::start("Probing pop.example.com:995");
24 sleep(Duration::from_secs(1));
25 spinner.failure("No POP server reachable at pop.example.com:995");
26}Sourcepub fn success(self, message: impl AsRef<str>)
pub fn success(self, message: impl AsRef<str>)
Stop the spinner and print a green ✓ followed by message.
Examples found in repository?
examples/spinner.rs (line 21)
11fn main() {
12 let spinner = Spinner::start("Resolving MX records for example.com…");
13 sleep(Duration::from_secs(1));
14
15 spinner.set_message("Probing imap.example.com:993");
16 sleep(Duration::from_secs(1));
17
18 spinner.set_message("Probing smtp.example.com:465");
19 sleep(Duration::from_secs(1));
20
21 spinner.success("Found IMAP at imap.example.com:993 and SMTP at smtp.example.com:465");
22
23 let spinner = Spinner::start("Probing pop.example.com:995");
24 sleep(Duration::from_secs(1));
25 spinner.failure("No POP server reachable at pop.example.com:995");
26}Sourcepub fn failure(self, message: impl AsRef<str>)
pub fn failure(self, message: impl AsRef<str>)
Stop the spinner and print a red ✗ followed by message.
Examples found in repository?
examples/spinner.rs (line 25)
11fn main() {
12 let spinner = Spinner::start("Resolving MX records for example.com…");
13 sleep(Duration::from_secs(1));
14
15 spinner.set_message("Probing imap.example.com:993");
16 sleep(Duration::from_secs(1));
17
18 spinner.set_message("Probing smtp.example.com:465");
19 sleep(Duration::from_secs(1));
20
21 spinner.success("Found IMAP at imap.example.com:993 and SMTP at smtp.example.com:465");
22
23 let spinner = Spinner::start("Probing pop.example.com:995");
24 sleep(Duration::from_secs(1));
25 spinner.failure("No POP server reachable at pop.example.com:995");
26}Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for Spinner
impl !UnwindSafe for Spinner
impl Freeze for Spinner
impl Send for Spinner
impl Sync for Spinner
impl Unpin for Spinner
impl UnsafeUnpin 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
Mutably borrows from an owned value. Read more