7 releases

0.3.0 Feb 6, 2020
0.2.0 Dec 14, 2019
0.1.5 Jul 29, 2018
0.1.4 May 31, 2018

#85 in Command-line interface

Download history 868/week @ 2021-02-26 906/week @ 2021-03-05 1052/week @ 2021-03-12 1065/week @ 2021-03-19 1040/week @ 2021-03-26 593/week @ 2021-04-02 790/week @ 2021-04-09 740/week @ 2021-04-16 1123/week @ 2021-04-23 699/week @ 2021-04-30 870/week @ 2021-05-07 1539/week @ 2021-05-14 1444/week @ 2021-05-21 833/week @ 2021-05-28 748/week @ 2021-06-04 800/week @ 2021-06-11

3,807 downloads per month
Used in 14 crates (13 directly)

MIT license

19KB
280 lines

promptly

A simple, opinionated prompting library

Features include:

  • Re-prompt until valid
  • Prompts for several types, and extensible
  • Sane handling of escapes via rustyline
  • Path completion when prompting for paths
  • Dead simple to use. Perhaps too simple.

Usage

Simply call prompt or prompt_default to prompt for any Promptable type:

  • prompt(msg) - prompt until input can be parsed as the inferred return type. Re-prompts for empty string input unless type is an Option<T>
  • prompt_default(msg, default) - prompt until input can be parsed as the inferred return type. Uses default value if input is empty string.
use promptly::{prompt, prompt_default};

// Prompt until a non-empty string is provided
let name: String = prompt("Enter your name");

// Prompt for other `FromStr` types
let age: u32 = prompt("Enter your age");

// Prompt for optional paths with path completion. Returns `None` if empty input.
let photo: Option<PathBuf> = prompt("Enter a path to a profile picture");

// Prompt Y/n with a default value when input is empty
let fallback = prompt_default("Would you like to receive marketing emails", true);

// Prompt for a url using the url crate (requires either 'nightly' or 'url' feature)
let website: Url = prompt("Enter a website URL");

More...

The API surface of this crate is opinionated and experimental, but open to fresh ideas. Some additional bits hiding under the surface:

  • Promptable trait provides implementations that prompt for many common types, and provides a way to add support for additional types.
  • Prompter struct provides lower-level control that powers the friendly readline experience. It's especially unclear how this type will evolve.

Dependencies

~1–1.7MB
~34K SLoC