Crate spinner [] [src]

This library is useful for console applications with long running processes. You create a Spinner and then update it however you see fit. Since this happens asynchronously, your user will not be left in the dark about what your app is doing.

There are two parts to Spinner, one part is the spinner itself, the other a simple interface to build menus.


To use a Spinner simply go and create one using the SpinnerBuilder:

use spinner::SpinnerBuilder;
let sp = SpinnerBuilder::new("Long Running operation, please wait...".into()).start();

Will inform the user that your app currently is doing background processing. sp is a SpinnerHandle, through which you can tell the user for example how far along the process you are, or perhaps a message in between.

use spinner::SpinnerBuilder;
let sp = SpinnerBuilder::new("Long Running operation, please wait...".into()).start();
sp.update(format!("Finished {} out of {}.", i, max));


A spinner can be customized in three ways:

Menus are simple, type checked ways to ask the user for information.

A simple menu might look like this:

use spinner::menu::*;
let m = Menu::new(vec![
    MenuOption("First Name".into(), MenuType::Text, MenuOptional::Optional, None),
    MenuOption("Last Name".into(), MenuType::Text, MenuOptional::Required, None),
    MenuOption("Age".into(), MenuType::Integer, MenuOptional::Optional, Some(MenuValue::Integer(1))),
    MenuOption("How much Ketchup?".into(), MenuType::Float, MenuOptional::Optional, None),

let results = m.display();

In results will then be an array of MenuValue, which can then be retrieved by either get_{string,int,float}, calling one of these on the wrong type will panic!. So be careful to take out the correct value out of the correct menu questions.

A MenuOption is a NewType. It consists of a string which will constitute the question being presented to the user. Then a MenuType, telling the checker what input is expected. If you need something else use MenuType::Text and work with that. You also have to tell whether that input is optional or not. (true=optional, false=not optional). At last, an Option<MenuValue> which allows you to put in either None, for no default value or Some<MenuValue> which will be used if the user inputs nothing.


pub use menu::Menu;
pub use menu::MenuOption;



Module defining the menu part of this crate



The struct with which to create a Spinner, check out the crate documentation for some more details


A handle to the Spinner Thread.



A possible string for the spinner, check out the kirby example for a possible use case.