8 releases

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

#173 in Command-line interface

Download history 10685/week @ 2023-11-19 11487/week @ 2023-11-26 10657/week @ 2023-12-03 10721/week @ 2023-12-10 9732/week @ 2023-12-17 6713/week @ 2023-12-24 8131/week @ 2023-12-31 11743/week @ 2024-01-07 15513/week @ 2024-01-14 11320/week @ 2024-01-21 14661/week @ 2024-01-28 12359/week @ 2024-02-04 12910/week @ 2024-02-11 12356/week @ 2024-02-18 11323/week @ 2024-02-25 13439/week @ 2024-03-03

50,718 downloads per month
Used in 30 crates (26 directly)

MIT license

19KB
281 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 if input is empty.
  • prompt_opt(msg) - prompt until input can be parsed as the inferred return type. Returns None if input is empty.
  • prompt_default(msg, default) - prompt until input can be parsed as the inferred return type. Uses default value if input is empty.
use promptly::{prompt, prompt_default, prompt_opt};

// 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_opt("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.

Dependencies

~5–16MB
~193K SLoC