simple library for displaying spinners in the terminal
Add as a dependency to your Cargo.toml
:
toml
[dependencies]
spinoff = "0.7.0"
```rust use spinoff::{Spinner, spinners, Color}; use std::thread::sleep; use std::time::Duration;
let spinner = Spinner::new(spinners::Dots, "Loading...", Color::Blue); sleep(Duration::from_secs(3)); spinner.success("Done!"); ```
```rust 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::fromsecs(3)); spinner.update(Spinners::Dots2, "Retrying...", None); sleep(Duration::fromsecs(3)); spinner.stop() ```
```rust use spinoff::{Spinner, spinners, Color, Streams}; use std::thread::sleep; use std::time::Duration;
let spinner = Spinner::newwithstream(spinners::Line, "Loading...", Color::Yellow, Streams::Stderr); sleep(Duration::fromsecs(3)); spinner.stopand_persist("π", "Task done."); ```
Note: This has been introduced in version 0.7.0
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:
toml
[dependencies]
spinoff = { version = "0.7.0", features = ["dots, arc, line"] }
You can create your own spinner using the spinner!
macro:
```rust use spinoff::*; use std::thread::sleep; use std::time::Duration;
let frames = spinner!([">", ">>", ">>>"], 100); let 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:
rust
use colored::control
control::enable_virtual_terminal(true).unwrap();
Other examples can be found in the documentation.
spinner
options, refer to the source code.bash
cargo run --example simple
bash
cargo run --example stream
bash
cargo run --example stop_and_persist
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.