Crates.io | spinoff |
lib.rs | spinoff |
version | 0.8.0 |
source | src |
created_at | 2022-07-15 18:15:13.416228 |
updated_at | 2023-08-04 13:07:51.375358 |
description | Simple to use Rust library for displaying spinners in the terminal |
homepage | https://github.com/ad4mx/spinoff |
repository | https://github.com/ad4mx/spinoff |
max_upload_size | |
id | 626333 |
size | 50,830 |
an easy to use, robust library for displaying spinners in the terminal
Add as a dependency to your Cargo.toml
:
[dependencies]
spinoff = "0.8.0"
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!");
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()
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.");
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.
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();
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();
spinner
options, refer to the spinner
module.cargo run --example simple
cargo run --example stream
cargo run --example stop_and_persist
Other examples can be found in the documentation.
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.
This crate is licensed under the MIT license.