🥬 Practical spinner for Rust

Overview

🥬 spinach

Crates.io Docs.rs License CI

Practical spinner for Rust

Install

Add as a dependency to your Cargo.toml.

[dependencies]
spinach = "2"

Usage

Basic example.

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

use spinach::Spinach;

fn main() {
    let s = Spinach::new("Running task 1");
    sleep(Duration::from_secs(1));

    s.text("Running task 2");
    sleep(Duration::from_secs(1));

    s.succeed("Ran tasks successfully");
}

For general convenience, text can be passed as String or &str. When an Option, can be passed as String, &str or Option<String>

Creating

use spinach::{Color, Spinach, Spinner};

// Using defaults + custom text
let s = Spinach::new("custom text");

// Using custom spinner
let spinner = Spinner::new(vec!["â–®","â–¯"], 80);
let s = Spinach::new_with(spinner, "custom text", Color::Red));

// Also with partial config (fallback to defaults)
let s = Spinach::new_with(None, "custom text", Color::Green);

Updating

use spinach::{Color, Spinach};

let s = Spinach::new("custom text");

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

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

// Updating multiple
s.update_with("new text", Color::Red);

// Also with partial update (keep current)
s.update_with(None, Color::Red);

Stopping

use spinach::{Color, Spinach};

let s = Spinach::new("custom text");

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

// Stop with final `✖` frame, red color and optional text change.
s.fail("ups");

// Stop with final `âš ` frame, yellow color and optional text change.
s.warn(None);

// Stop with final `ℹ` frame, blue color and optional text change.
s.info("notice");

// Stop current spinner (freeze the frame)
s.stop();

// Stopping with custom final frame, text and color
s.stop_with("🥬", "spinach'd", Color::Ignore);

// Also with partial update (keep current)
s.stop_with(None, None, Color::Blue);

Freezing

Will freeze the current line with passed options and continue on a new line.

use spinach::{Color, Spinach};

let s = Spinach::new("Cutting spinaches");

// Similar to `stop_with`, but with an extra argument to change the spinner text.
s.freeze("🥬", "Spinaches cut", None, "Cutting carottes");

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::{term, Spinach};

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

    let s = Spinach::new("spinnin'");
    // ...

Related

Inspired by:

You might also like...
This rust compiler backend emmits valid CLR IR, enambling you to use Rust in .NET projects

What is rustc_codegen_clr? NOTE: this project is a very early proof-of-concept This is a compiler backend for rustc which targets the .NET platform an

RustGPT is a ChatGPT UI built with Rust + HTMX: the power of Rust coupled with the simplicity of HTMX 💚

RustGPT 🦀✨ RustGPT.Blog.Post.mp4 Welcome to the RustGPT repository! Here, you'll find a web ChatGPT clone entirely crafted using Rust and HTMX, where

Rust API Server: A versatile template for building RESTful interfaces, designed for simplicity in setup and configuration using the Rust programming language.
Rust API Server: A versatile template for building RESTful interfaces, designed for simplicity in setup and configuration using the Rust programming language.

RUST API SERVER Introduction Welcome to the Rust API Server! This server provides a simple REST interface for your applications. This README will guid

Rust File Management CLI is a command-line tool written in Rust that provides essential file management functionalities. Whether you're working with files or directories, this tool simplifies common file operations with ease.

Rust FileOps Rust File Management CLI is a command-line tool written in Rust that provides essential file management functionalities. Whether you're w

Experimental engine agnostic 3D CSG library for game development written in Rust. Started as a port of csg.js to Rust.

brusher Experimental engine agnostic 3D CSG library for game development written in Rust. Started as a port of csg.js to Rust. ultimate goal My hope i

A full featured, fast Command Line Argument Parser for Rust

clap Command Line Argument Parser for Rust It is a simple-to-use, efficient, and full-featured library for parsing command line arguments and subcomma

Docopt for Rust (command line argument parser).

THIS CRATE IS UNMAINTAINED This crate is unlikely to see significant future evolution. The primary reason to choose this crate for a new project is if

Quickly build cool CLI apps in Rust.

QuiCLI Quickly build cool CLI apps in Rust. Getting started Read the Getting Started guide! Thanks This is only possible because of all the awesome li

A minimal CLI framework written in Rust
A minimal CLI framework written in Rust

seahorse A minimal CLI framework written in Rust Features Easy to use No dependencies Typed flags(Bool, String, Int, Float) Documentation Here Usage T

Comments
Releases(v2.1.0)
  • v2.1.0(Mar 26, 2022)

    What's Changed

    • Add freeze command by @etienne-napoleone in https://github.com/etienne-napoleone/spinach/pull/7
    • Take optional string instead of optional slice by @etienne-napoleone in https://github.com/etienne-napoleone/spinach/pull/8

    Full Changelog: https://github.com/etienne-napoleone/spinach/compare/v2.0.0...v2.1.0

    Source code(tar.gz)
    Source code(zip)
  • v2.0.0(Mar 26, 2022)

    What's Changed

    • Manage strings as input by @etienne-napoleone in https://github.com/etienne-napoleone/spinach/pull/6

    Full Changelog: https://github.com/etienne-napoleone/spinach/compare/v1.2.0...v2.0.0

    Source code(tar.gz)
    Source code(zip)
  • v1.2.0(Mar 24, 2022)

    What's Changed

    • Expose term::show_console() for QoL help with signal handling by @etienne-napoleone in https://github.com/etienne-napoleone/spinach/pull/5

    Full Changelog: https://github.com/etienne-napoleone/spinach/compare/v1.1.0...v1.2.0

    Source code(tar.gz)
    Source code(zip)
  • v1.1.0(Mar 24, 2022)

    What's Changed

    • Simplify API by using bound trait Into for optional arguments by @etienne-napoleone in https://github.com/etienne-napoleone/spinach/pull/2
    • Refactor internal module organization by @etienne-napoleone in https://github.com/etienne-napoleone/spinach/pull/3
    • Make spinner clonable by @etienne-napoleone in https://github.com/etienne-napoleone/spinach/pull/4

    Full Changelog: https://github.com/etienne-napoleone/spinach/compare/v1.0.2...v1.1.0

    Source code(tar.gz)
    Source code(zip)
  • v1.0.2(Mar 23, 2022)

  • v1.0.1(Mar 23, 2022)

Owner
Etienne Napoleone
ᕦ(ò_óˇ)ᕤ
Etienne Napoleone
Ryan: a configuration language for the practical programmer

Ryan: a configuration language for the practical programmer Say hello to Ryan! Ryan is a minimal programming language that produces JSON (and therefor

Pedro B. Arruda 7 Mar 5, 2023
Rust-advent - Learning Rust by solving advent of code challenges (Streaming live on Twitch every Monday)

Rust advent ?? ?? Learning Rust by implementing solutions for Advent of Code problems. ?? HEY, we are live-streaming our attempts to solve the exercis

Luciano Mammino 20 Nov 11, 2022
Rust-clippy - A bunch of lints to catch common mistakes and improve your Rust code

Clippy A collection of lints to catch common mistakes and improve your Rust code. There are over 450 lints included in this crate! Lints are divided i

The Rust Programming Language 8.7k Dec 31, 2022
Rust-battery - Rust crate providing cross-platform information about the notebook batteries.

battery Rust crate providing cross-platform information about the notebook batteries. Table of contents Overview Supported platforms Install Examples

svartalf 326 Dec 21, 2022
A Rust-based shell script to create a folder structure to use for a single class every semester. Mostly an excuse to use Rust.

A Rust Course Folder Shell Script PROJECT IN PROGRESS (Spring 2022) When completed, script will create a folder structure of the following schema: [ro

Sebastián Romero Cruz 1 Apr 10, 2022
Rust Imaging Library's Python binding: A performant and high-level image processing library for Python written in Rust

ril-py Rust Imaging Library for Python: Python bindings for ril, a performant and high-level image processing library written in Rust. What's this? Th

Cryptex 13 Dec 6, 2022
FTL Rust Demangler is a command-line tool for demangling symbol names that are mangled with the Rust convention

FTL Rust Demangler is a command-line tool for demangling symbol names that are mangled with the Rust convention. It takes a mangled symbol name as input and returns the demangled name

timetravel3 7 Mar 30, 2023
rpm (Rust project manager) is a tool that helps you to manage your rust projects

rpm rpm (Rust project manager) is a open source tool for managing your rust project in an organized way Installation # make sure you have rust install

Dilshad 4 May 4, 2023
auto-rust is an experimental project that aims to automatically generate Rust code with LLM (Large Language Models) during compilation, utilizing procedural macros.

Auto Rust auto-rust is an experimental project that aims to automatically generate Rust code with LLM (Large Language Models) during compilation, util

Minsky 6 May 14, 2023
Rusty Shellcode Reflective DLL Injection (sRDI) - A small reflective loader in Rust 4KB in size for generating position-independent code (PIC) in Rust.

Shellcode Reflective DLL Injection (sRDI) Shellcode reflective DLL injection (sRDI) is a process injection technique that allows us to convert a given

null 242 Jul 5, 2023