#spinner #spin #loader #cli #terminal

spinoff

Simple to use Rust library for displaying spinners in the terminal

13 releases (7 breaking)

0.8.0 Aug 4, 2023
0.7.0 Jan 29, 2023
0.6.0 Jan 2, 2023
0.5.4 Sep 11, 2022
0.5.3 Jul 31, 2022

#31 in Command-line interface

Download history 1854/week @ 2023-10-20 1712/week @ 2023-10-27 1933/week @ 2023-11-03 2260/week @ 2023-11-10 2454/week @ 2023-11-17 3115/week @ 2023-11-24 2385/week @ 2023-12-01 3289/week @ 2023-12-08 2428/week @ 2023-12-15 2167/week @ 2023-12-22 2110/week @ 2023-12-29 3245/week @ 2024-01-05 1853/week @ 2024-01-12 2038/week @ 2024-01-19 1277/week @ 2024-01-26 847/week @ 2024-02-02

6,306 downloads per month
Used in 28 crates (27 directly)

MIT license

49KB
728 lines

spinoff

an easy to use, robust library for displaying spinners in the terminal

Version Downloads Docs License Actions

πŸ”¨ Install

Add as a dependency to your Cargo.toml:

[dependencies]
spinoff = "0.8.0"

⚑ Usage

use spinoff::{Spinner, spinners, Color};
use std::thread::sleep;
use std::time::Duration;

let mut spinner = Spinner::new(spinners::Dots, "Loading...", Color::Blue); 
sleep(Duration::from_secs(3));
spinner.success("Done!");

Update a spinner

use spinoff::{Spinner, spinners, Color};
use std::thread::sleep;
use std::time::Duration;

let mut spinner = Spinner::new(spinners::Aesthetic, "Loading...", Color::Red); 
sleep(Duration::from_secs(3));
spinner.update(Spinners::Dots2, "Retrying...", None);
sleep(Duration::from_secs(3));
spinner.stop()

Specify an output stream

use spinoff::{Spinner, spinners, Color, Streams};
use std::thread::sleep;
use std::time::Duration;

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

πŸ’« Spinners

spinoff includes over 80+ spinner variants out of the box. All spinner variants are treated as features that can be enabled or disabled. By default, all of them are enabled for ease of use. To disable/enable variants, you will have to edit your cargo.toml file:

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

Any suggestions for new spinner variants are welcome.

Creating your own spinner

You can create your own spinner using the spinner! macro:

use spinoff::*;
use std::thread::sleep;
use std::time::Duration;

let frames = spinner!([">", ">>", ">>>"], 100);
let mut sp = Spinner::new(frames, "Hello World!", None);
sleep(Duration::from_millis(800));
sp.stop();

❗Note for Windows Users

For colors to work properly, you need to add a few extra lines to your code:

use colored::control
control::enable_virtual_terminal(true).unwrap();

πŸ“– Documentation

βš™ Examples

cargo run --example simple
cargo run --example stream
cargo run --example stop_and_persist

Other examples can be found in the documentation.

🚧 Contributing

Any contributions to this crate are highly appreciated. If you have any ideas/suggestions/bug fixes, please open an issue or a pull request. If you like the project, star this project on GitHub.

πŸ“‘ License

This crate is licensed under the MIT license.

Dependencies

~0.1–8.5MB
~50K SLoC