new: version 0.4.0

This commit is contained in:
ad4mx 2022-07-19 20:01:23 +02:00
parent 337bf118d4
commit 27083f820d
4 changed files with 13 additions and 10 deletions

View file

@ -1,6 +1,6 @@
[package] [package]
name = "spinoff" name = "spinoff"
version = "0.3.0" version = "0.4.0"
edition = "2021" edition = "2021"
authors = ["ad4m"] authors = ["ad4m"]
description = "🔨 Simple to use Rust library for displaying spinners in the terminal." description = "🔨 Simple to use Rust library for displaying spinners in the terminal."

View file

@ -13,7 +13,7 @@ use spinoff::{Spinner, Spinners, Color};
use std::thread::sleep; use std::thread::sleep;
use std::time::Duration; 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)); sleep(Duration::from_secs(3));
spinner.success("Done!"); spinner.success("Done!");
``` ```
@ -25,7 +25,7 @@ use spinoff::{Spinner, Spinners, Color};
use std::thread::sleep; use std::thread::sleep;
use std::time::Duration; 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)); sleep(Duration::from_secs(3));
spinner.update(Spinners::Dots2, "Loading...", None); spinner.update(Spinners::Dots2, "Loading...", None);
sleep(Duration::from_secs(3)); sleep(Duration::from_secs(3));
@ -39,7 +39,7 @@ use spinoff::{Spinner, Spinners, Color};
use std::thread::sleep; use std::thread::sleep;
use std::time::Duration; 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)); sleep(Duration::from_secs(3));
spinner.stop_and_persist("📜", "Task done."); spinner.stop_and_persist("📜", "Task done.");
``` ```

View file

@ -2,7 +2,7 @@ use spinoff::{Color, Spinner, Spinners};
use std::{thread::sleep, time::Duration}; use std::{thread::sleep, time::Duration};
fn main() { 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)); sleep(Duration::from_secs(5));
sp.stop_and_persist("🍕", "Pizza!"); sp.stop_and_persist("🍕", "Pizza!");
} }

View file

@ -79,7 +79,7 @@ impl Spinner {
/// # use std::thread::sleep; /// # use std::thread::sleep;
/// # use std::time::Duration; /// # 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)); /// sleep(Duration::from_millis(800));
/// sp.clear(); /// sp.clear();
/// ``` /// ```
@ -88,13 +88,15 @@ impl Spinner {
/// ///
/// * The spinner immediately starts spinning upon creation. /// * The spinner immediately starts spinning upon creation.
/// ///
pub fn new<T>(spinner_type: Spinners, msg: T, color: Option<Color>) -> Self pub fn new<T, U>(spinner_type: Spinners, msg: T, color: U) -> Self
where where
T: Into<Cow<'static, str>>, T: Into<Cow<'static, str>>,
U: Into<Option<Color>>,
{ {
let still_spinning = Arc::new(AtomicBool::new(true)); 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 msg = msg.into();
let color = color.into();
// We use atomic bools to make the thread stop itself when the `spinner.stop()` method is called. // We use atomic bools to make the thread stop itself when the `spinner.stop()` method is called.
let handle = thread::spawn({ let handle = thread::spawn({
// Clone the atomic bool so that we can use it in the thread and return the original one later. // 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::thread::sleep;
/// # use std::time::Duration; /// # 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)); /// sleep(Duration::from_millis(800));
/// sp.fail("Code failed to compile!"); /// sp.fail("Code failed to compile!");
/// ``` /// ```
@ -283,9 +285,10 @@ impl Spinner {
/// sp.stop(); /// sp.stop();
/// ``` /// ```
/// ///
pub fn update<T>(&mut self, spinner: Spinners, msg: T, color: Option<Color>) pub fn update<T, U>(&mut self, spinner: Spinners, msg: T, color: U)
where where
T: Into<Cow<'static, str>>, T: Into<Cow<'static, str>>,
U: Into<Option<Color>>,
{ {
self.stop_spinner_thread(); self.stop_spinner_thread();
let _ = std::mem::replace(self, Self::new(spinner, msg, color)); let _ = std::mem::replace(self, Self::new(spinner, msg, color));