From 27083f820d15285a0ac646e2f929f684bbf02de4 Mon Sep 17 00:00:00 2001 From: ad4mx Date: Tue, 19 Jul 2022 20:01:23 +0200 Subject: [PATCH] new: version 0.4.0 --- Cargo.toml | 2 +- README.md | 6 +++--- examples/stop_and_persist.rs | 2 +- src/lib.rs | 13 ++++++++----- 4 files changed, 13 insertions(+), 10 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index d99d732..d8a57e7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "spinoff" -version = "0.3.0" +version = "0.4.0" edition = "2021" authors = ["ad4m"] description = "🔨 Simple to use Rust library for displaying spinners in the terminal." diff --git a/README.md b/README.md index 367935e..1cc06bf 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ use spinoff::{Spinner, Spinners, Color}; use std::thread::sleep; use std::time::Duration; -let spinner = Spinner::new(Spinners::Dots, "Loading...", Some(Color::Blue)); +let spinner = Spinner::new(Spinners::Dots, "Loading...", Color::Blue); sleep(Duration::from_secs(3)); spinner.success("Done!"); ``` @@ -25,7 +25,7 @@ use spinoff::{Spinner, Spinners, Color}; use std::thread::sleep; use std::time::Duration; -let mut spinner = Spinner::new(Spinners::Dots, "Loading...", Some(Color::Red)); +let mut spinner = Spinner::new(Spinners::Dots, "Loading...", Color::Red); sleep(Duration::from_secs(3)); spinner.update(Spinners::Dots2, "Loading...", None); sleep(Duration::from_secs(3)); @@ -39,7 +39,7 @@ use spinoff::{Spinner, Spinners, Color}; use std::thread::sleep; use std::time::Duration; -let mut spinner = Spinner::new(Spinners::Dots, "Loading...", Some(Color::Green)); +let mut spinner = Spinner::new(Spinners::Dots, "Loading...", Color::Green); sleep(Duration::from_secs(3)); spinner.stop_and_persist("📜", "Task done."); ``` diff --git a/examples/stop_and_persist.rs b/examples/stop_and_persist.rs index 766a23a..e6d4f6f 100644 --- a/examples/stop_and_persist.rs +++ b/examples/stop_and_persist.rs @@ -2,7 +2,7 @@ use spinoff::{Color, Spinner, Spinners}; use std::{thread::sleep, time::Duration}; fn main() { - let sp = Spinner::new(Spinners::Dots, "Loading...", Some(Color::Blue)); + let sp = Spinner::new(Spinners::Dots, "Loading...", Color::Blue); sleep(Duration::from_secs(5)); sp.stop_and_persist("🍕", "Pizza!"); } diff --git a/src/lib.rs b/src/lib.rs index 23def2b..280b12f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -79,7 +79,7 @@ impl Spinner { /// # use std::thread::sleep; /// # use std::time::Duration; /// # - /// let sp = Spinner::new(Spinners::Dots, "Hello World!", Some(Color::Blue)); + /// let sp = Spinner::new(Spinners::Dots, "Hello World!", Color::Blue); /// sleep(Duration::from_millis(800)); /// sp.clear(); /// ``` @@ -88,13 +88,15 @@ impl Spinner { /// /// * The spinner immediately starts spinning upon creation. /// - pub fn new(spinner_type: Spinners, msg: T, color: Option) -> Self + pub fn new(spinner_type: Spinners, msg: T, color: U) -> Self where T: Into>, + U: Into>, { let still_spinning = Arc::new(AtomicBool::new(true)); - // Gain ownership of the message for the thread to use + // Gain ownership of the message and color for the thread to use let msg = msg.into(); + let color = color.into(); // We use atomic bools to make the thread stop itself when the `spinner.stop()` method is called. let handle = thread::spawn({ // Clone the atomic bool so that we can use it in the thread and return the original one later. @@ -232,7 +234,7 @@ impl Spinner { /// # use std::thread::sleep; /// # use std::time::Duration; /// # - /// let sp = Spinner::new(Spinners::BouncingBar, "Executing code...", Some(Color::Green)); + /// let sp = Spinner::new(Spinners::BouncingBar, "Executing code...", Color::Green); /// sleep(Duration::from_millis(800)); /// sp.fail("Code failed to compile!"); /// ``` @@ -283,9 +285,10 @@ impl Spinner { /// sp.stop(); /// ``` /// - pub fn update(&mut self, spinner: Spinners, msg: T, color: Option) + pub fn update(&mut self, spinner: Spinners, msg: T, color: U) where T: Into>, + U: Into>, { self.stop_spinner_thread(); let _ = std::mem::replace(self, Self::new(spinner, msg, color));