Skip to content

Commit

Permalink
Merge pull request #29 from AnishDe12020/feat/new-stuff
Browse files Browse the repository at this point in the history
Added functions to print a message and symbol after stopping
  • Loading branch information
FGRibreau authored Jun 17, 2022
2 parents 782a658 + a5eb2e6 commit ce6bf7a
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
14 changes: 14 additions & 0 deletions examples/stop_persist.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
use spinners::{Spinner, Spinners};
use std::{env, str::FromStr, thread::sleep, time::Duration};

fn main() {
let mut args = env::args();
let spinner_name = args.nth(1).unwrap_or_else(|| "Dots9".to_string());

let mut sp = Spinner::new(
Spinners::from_str(&spinner_name).unwrap(),
"Waiting for 3 seconds".into(),
);
sleep(Duration::from_secs(3));
sp.stop_and_persist("✔", "That worked!".to_string())
}
20 changes: 19 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,25 @@ impl Spinner {
/// ```
pub fn stop_with_message(&mut self, msg: String) {
self.stop();
print!("\r{}", msg);
println!("\x1b[2K\r{}", msg);
}

/// Stops the spinner with a provided symbol and message
///
/// # Examples
///
/// Basic Usage:
///
/// ```
/// use spinners::{Spinner, Spinners};
///
/// let mut sp = Spinner::new(Spinners::Dots, "Loading things into memory...".into());
///
/// sp.stop_and_persist("✔", "Finished loading things into memory!".into());
/// ```
pub fn stop_and_persist(&mut self, symbol: &str, msg: String) {
self.stop();
println!("\x1b[2K\r{} {}", symbol, msg);
}

fn stop_inner(&mut self, stop_time: Instant, stop_symbol: Option<String>) {
Expand Down

0 comments on commit ce6bf7a

Please sign in to comment.