new: version 0.4.0

main v0.4.0
ad4mx 2022-07-19 20:01:23 +02:00
parent 49245d275b
commit 0264b71f93
4 changed files with 13 additions and 10 deletions

View File

@ -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."

View File

@ -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.");
```

View File

@ -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!");
}

View File

@ -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<T>(spinner_type: Spinners, msg: T, color: Option<Color>) -> Self
pub fn new<T, U>(spinner_type: Spinners, msg: T, color: U) -> Self
where
T: Into<Cow<'static, str>>,
U: Into<Option<Color>>,
{
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<T>(&mut self, spinner: Spinners, msg: T, color: Option<Color>)
pub fn update<T, U>(&mut self, spinner: Spinners, msg: T, color: U)
where
T: Into<Cow<'static, str>>,
U: Into<Option<Color>>,
{
self.stop_spinner_thread();
let _ = std::mem::replace(self, Self::new(spinner, msg, color));