7 stable releases

3.0.0 Aug 23, 2024
2.1.0 Mar 26, 2022
1.2.0 Mar 24, 2022

#108 in Command-line interface

Download history 108/week @ 2024-07-29 76/week @ 2024-08-05 124/week @ 2024-08-12 203/week @ 2024-08-19 86/week @ 2024-08-26 49/week @ 2024-09-02 54/week @ 2024-09-09 157/week @ 2024-09-16 98/week @ 2024-09-23 118/week @ 2024-09-30 93/week @ 2024-10-07 148/week @ 2024-10-14 257/week @ 2024-10-21 179/week @ 2024-10-28 999/week @ 2024-11-04 747/week @ 2024-11-11

2,207 downloads per month
Used in 8 crates

GPL-3.0-or-later

18KB
230 lines

🥬 spinach

Crates.io Docs.rs License CI

Practical spinner for Rust — v3 now with method chaining

Install

Add as a dependency to your Cargo.toml.

[dependencies]
spinach = "3"

Usage

Basic example.

use spinach::Spinner;

fn main() {
    let s = Spinner::new("Cutting spinaches...").start();
    // Cut spinaches
    s.text("Cutting tomatoes...").update();
    // Cut tomatoes
    s.text("Vegetables cut").symbols(vec!["🔪"]).stop();
}

Starting

use spinach::{Color, Spinner};

// With custom text
let s = Spinner::new("workin'...").start();

// With custom text, spinner, spinner speed and spinner color
let symbols = vec!["",""];
let s = Spinner::new("blip... blop...")
    .color(Color::Red)
    .symbols(symbols)
    .frames_duration(80)
    .start();

Updating

use spinach::{Color, Spinner};

let s = Spinner::new("workin'...").start();

// Updating text
s.text("new text").update();

// Updating color
s.color(Color::White).update();

// Updating spinner symbols
s.symbols(vec!["", "", "", ""]).update();

// Updating spinner speed
s.frames_duration(80).update();

// Updating multiple at once
s.text("new text").color(Color::Red);

Stopping

use spinach::{Color, Spinner};

let s = Spinner::new("workin'...").start();

// Stop with final `✔` frame and green color.
s.text("gg!").success();

// Stop with final `✖` frame and red color.
s.text("ups").failure();

// Stop with final `⚠` frame and yellow color.
s.text("something may have happened?").warn();

// Stop with final `ℹ` frame and blue color.
s.text("notice").stop();

// Stop current spinner (sends update at the same time)
s.stop(); // freeze
s.text("spinach'd").symbols(vec!["🥬"]).stop(); // stop with the text "spinach'd" and a vegetable as the spinner

FAQ

How to avoid leaving terminal without prompt on interupt (ctrl^c)?

You can use a library like ctrlc to handle interupts.

The most basic way to handle it would be in conjuction with this lib QoL show_cursor function like this:

use spinach::{show_cursor, Spinner};

fn main() {
    ctrlc::set_handler(|| {
        show_cursor();
        std::process::exit(0);
    })
    .expect("Error setting Ctrl-C handler");

    let s = Spinner::new("workin'...").start();
    // ...

Inspired by:

No runtime deps