Skip to content

Commit

Permalink
0.8 (#21)
Browse files Browse the repository at this point in the history
* fix: add support for locking behind mutex (#20)
---------

Co-authored-by: Christopher Schear <chris@schear.us>
  • Loading branch information
ad4mx and cschear committed Aug 4, 2023
1 parent 13f6d1e commit 1d81b51
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 30 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "spinoff"
version = "0.7.0"
version = "0.8.0"
edition = "2021"
authors = ["ad4m"]
description = "Simple to use Rust library for displaying spinners in the terminal"
Expand Down
10 changes: 5 additions & 5 deletions README.md
Expand Up @@ -10,7 +10,7 @@ Add as a dependency to your `Cargo.toml`:

```toml
[dependencies]
spinoff = "0.7.0"
spinoff = "0.8.0"
```

## ⚡ Usage
Expand All @@ -20,7 +20,7 @@ use spinoff::{Spinner, spinners, Color};
use std::thread::sleep;
use std::time::Duration;

let spinner = Spinner::new(spinners::Dots, "Loading...", Color::Blue);
let mut spinner = Spinner::new(spinners::Dots, "Loading...", Color::Blue);
sleep(Duration::from_secs(3));
spinner.success("Done!");
```
Expand All @@ -46,7 +46,7 @@ use spinoff::{Spinner, spinners, Color, Streams};
use std::thread::sleep;
use std::time::Duration;

let spinner = Spinner::new_with_stream(spinners::Line, "Loading...", Color::Yellow, Streams::Stderr);
let mut spinner = Spinner::new_with_stream(spinners::Line, "Loading...", Color::Yellow, Streams::Stderr);
sleep(Duration::from_secs(3));
spinner.stop_and_persist("📜", "Task done.");
```
Expand All @@ -59,7 +59,7 @@ To disable/enable variants, you will have to edit your `cargo.toml` file:

```toml
[dependencies]
spinoff = { version = "0.7.0", features = ["dots", "arc", "line"] }
spinoff = { version = "0.8.0", features = ["dots", "arc", "line"] }
```

Any suggestions for new spinner variants are welcome.
Expand All @@ -73,7 +73,7 @@ use std::thread::sleep;
use std::time::Duration;

let frames = spinner!([">", ">>", ">>>"], 100);
let sp = Spinner::new(frames, "Hello World!", None);
let mut sp = Spinner::new(frames, "Hello World!", None);
sleep(Duration::from_millis(800));
sp.stop();
```
Expand Down
2 changes: 1 addition & 1 deletion examples/simple.rs
Expand Up @@ -4,7 +4,7 @@ use std::{thread::sleep, time::Duration};

#[cfg(feature = "dots")]
fn main() {
let sp = Spinner::new(spinners::Dots, "Loading...", Color::Blue);
let mut sp = Spinner::new(spinners::Dots, "Loading...", Color::Blue);
sleep(Duration::from_millis(8000));
sp.success("Done!");
}
Expand Down
2 changes: 1 addition & 1 deletion examples/stop_and_persist.rs
Expand Up @@ -4,7 +4,7 @@ use std::{thread::sleep, time::Duration};

#[cfg(feature = "arc")]
fn main() {
let sp = Spinner::new(spinners::Arc, "Loading...", Color::Blue);
let mut sp = Spinner::new(spinners::Arc, "Loading...", Color::Blue);
sleep(Duration::from_secs(5));
sp.stop_and_persist("🍕", "Pizza!");
}
Expand Down
2 changes: 1 addition & 1 deletion examples/stream.rs
Expand Up @@ -4,7 +4,7 @@ use std::{thread::sleep, time::Duration};

#[cfg(feature = "aesthetic")]
fn main() {
let sp = Spinner::new_with_stream(spinners::Aesthetic, "Loading in stderr...", None, Streams::Stderr);
let mut sp = Spinner::new_with_stream(spinners::Aesthetic, "Loading in stderr...", None, Streams::Stderr);
sleep(Duration::from_millis(8000));
sp.success("Done!");
}
Expand Down
42 changes: 21 additions & 21 deletions src/lib.rs
Expand Up @@ -10,7 +10,7 @@
# use std::thread::sleep;
# use std::time::Duration;
#
let sp = Spinner::new(spinners::Dots, "Loading...", None);
let mut sp = Spinner::new(spinners::Dots, "Loading...", None);
sleep(Duration::from_millis(800));
sp.success("Success!");
```
Expand All @@ -32,7 +32,7 @@ If you want to use a custom spinner, you can use the [`spinner!`] macro.
# use std::time::Duration;
#
let frames = spinner!([">", ">>", ">>>"], 100);
let sp = Spinner::new(frames, "Loading...", None);
let mut sp = Spinner::new(frames, "Loading...", None);
sleep(Duration::from_millis(800));
sp.success("Success!");
```
Expand Down Expand Up @@ -94,7 +94,7 @@ Create a new `SpinnerFrames` struct
# use std::time::Duration;
#
let frames = spinner!([">", ">>", ">>>"], 100);
let sp = Spinner::new(frames, "Hello World!", None);
let mut sp = Spinner::new(frames, "Hello World!", None);
sleep(Duration::from_millis(800));
sp.stop();
```
Expand Down Expand Up @@ -126,7 +126,7 @@ impl Spinner {
# use std::thread::sleep;
# use std::time::Duration;
#
let sp = Spinner::new(spinners::Dots, "Hello World!", Color::Blue);
let mut sp = Spinner::new(spinners::Dots, "Hello World!", Color::Blue);
sleep(Duration::from_millis(800));
sp.stop();
```
Expand Down Expand Up @@ -161,7 +161,7 @@ impl Spinner {
# use std::thread::sleep;
# use std::time::Duration;
#
let sp = Spinner::new_with_stream(spinners::Dots, "I'm outputting to stderr!", Color::Yellow, Streams::Stderr);
let mut sp = Spinner::new_with_stream(spinners::Dots, "I'm outputting to stderr!", Color::Yellow, Streams::Stderr);
sleep(Duration::from_millis(800));
sp.clear();
```
Expand Down Expand Up @@ -236,7 +236,7 @@ impl Spinner {
# use std::thread::sleep;
# use std::time::Duration;
#
let sp = Spinner::new(spinners::Dots9, "Spinning...", None);
let mut sp = Spinner::new(spinners::Dots9, "Spinning...", None);
sleep(Duration::from_millis(800));
sp.stop();
#
Expand All @@ -247,7 +247,7 @@ impl Spinner {
* The spinner will be dropped after this method is called, the message will remain though.
*/
pub fn stop(mut self) {
pub fn stop(&mut self) {
self.stop_spinner_thread();
// print message
writeln!(self.stream, "{}", self.msg);
Expand All @@ -263,14 +263,14 @@ impl Spinner {
# use std::thread::sleep;
# use std::time::Duration;
#
let sp = Spinner::new(spinners::Dots2, "Hello", None);
let mut sp = Spinner::new(spinners::Dots2, "Hello", None);
sleep(Duration::from_millis(800));
sp.stop_with_message("Bye");
#
```
*/
pub fn stop_with_message(mut self, msg: &str) {
pub fn stop_with_message(&mut self, msg: &str) {
self.stop_spinner_thread();
// put the message over the spinner
writeln!(self.stream, "{msg}");
Expand All @@ -286,14 +286,14 @@ impl Spinner {
# use std::thread::sleep;
# use std::time::Duration;
#
let sp = Spinner::new(spinners::Mindblown, "Guess what's coming...", None);
let mut sp = Spinner::new(spinners::Mindblown, "Guess what's coming...", None);
sleep(Duration::from_millis(800));
sp.stop_and_persist("🍕", "Pizza!");
#
```
*/
pub fn stop_and_persist(mut self, symbol: &str, msg: &str) {
pub fn stop_and_persist(&mut self, symbol: &str, msg: &str) {
self.stop_spinner_thread();
writeln!(self.stream, "{symbol} {msg}");
}
Expand All @@ -308,14 +308,14 @@ impl Spinner {
# use std::thread::sleep;
# use std::time::Duration;
#
let sp = Spinner::new(spinners::Aesthetic, "Trying to load information...", None);
let mut sp = Spinner::new(spinners::Aesthetic, "Trying to load information...", None);
sleep(Duration::from_millis(800));
sp.success("Success!");
#
```
*/
pub fn success(mut self, msg: &str) {
pub fn success(&mut self, msg: &str) {
self.stop_spinner_thread();
writeln!(self.stream, "{} {}", colorize(Some(Color::Green), "✓").bold(), msg);
}
Expand All @@ -330,14 +330,14 @@ impl Spinner {
# use std::thread::sleep;
# use std::time::Duration;
#
let sp = Spinner::new(spinners::BouncingBar, "Executing code...", Color::Green);
let mut sp = Spinner::new(spinners::BouncingBar, "Executing code...", Color::Green);
sleep(Duration::from_millis(800));
sp.fail("Code failed to compile!");
#
```
*/
pub fn fail(mut self, msg: &str) {
pub fn fail(&mut self, msg: &str) {
self.stop_spinner_thread();
writeln!(self.stream, "{} {}", colorize(Some(Color::Red), "✗").bold(), msg);
}
Expand All @@ -352,14 +352,14 @@ impl Spinner {
# use std::thread::sleep;
# use std::time::Duration;
#
let sp = Spinner::new(spinners::Material, "Measuring network speed...", None);
let mut sp = Spinner::new(spinners::Material, "Measuring network speed...", None);
sleep(Duration::from_millis(800));
sp.warn("You might want to check your internet connection...");
#
```
*/
pub fn warn(mut self, msg: &str) {
pub fn warn(&mut self, msg: &str) {
self.stop_spinner_thread();
writeln!(self.stream, "{} {}", colorize(Some(Color::Yellow), "⚠").bold(), msg);
}
Expand All @@ -373,14 +373,14 @@ impl Spinner {
# use std::thread::sleep;
# use std::time::Duration;
#
let sp = Spinner::new(spinners::Dots9, "Loading info message...", None);
let mut sp = Spinner::new(spinners::Dots9, "Loading info message...", None);
sleep(Duration::from_millis(800));
sp.info("This is an info message!");
#
```
*/
pub fn info(mut self, msg: &str) {
pub fn info(&mut self, msg: &str) {
self.stop_spinner_thread();
writeln!(self.stream, "{} {}", colorize(Some(Color::Blue), "ℹ").bold(), msg);
}
Expand Down Expand Up @@ -493,14 +493,14 @@ impl Spinner {
# use std::thread::sleep;
# use std::time::Duration;
#
let sp = Spinner::new(spinners::Grenade, "Clearing...", None);
let mut sp = Spinner::new(spinners::Grenade, "Clearing...", None);
sleep(Duration::from_millis(800));
sp.clear();
#
```
*/
pub fn clear(mut self) {
pub fn clear(&mut self) {
self.stop_spinner_thread();
}

Expand Down

0 comments on commit 1d81b51

Please sign in to comment.