Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/anowell/promptly
Simple, opinionated prompting library
https://github.com/anowell/promptly
Last synced: 3 days ago
JSON representation
Simple, opinionated prompting library
- Host: GitHub
- URL: https://github.com/anowell/promptly
- Owner: anowell
- License: mit
- Created: 2018-05-20T07:15:44.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2022-08-12T23:55:55.000Z (over 2 years ago)
- Last Synced: 2024-04-25T07:44:19.793Z (9 months ago)
- Language: Rust
- Size: 25.4 KB
- Stars: 44
- Watchers: 3
- Forks: 3
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 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.```rust
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 = 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.