11 stable releases

2.1.1 Nov 11, 2023
2.0.2 Nov 26, 2022
1.0.5 Dec 5, 2019
1.0.3 Aug 8, 2017
1.0.2 Jul 31, 2017

#221 in Command-line interface

Download history 923/week @ 2024-03-14 1188/week @ 2024-03-21 944/week @ 2024-03-28 931/week @ 2024-04-04 939/week @ 2024-04-11 1159/week @ 2024-04-18 921/week @ 2024-04-25 922/week @ 2024-05-02 801/week @ 2024-05-09 1040/week @ 2024-05-16 821/week @ 2024-05-23 998/week @ 2024-05-30 704/week @ 2024-06-06 770/week @ 2024-06-13 828/week @ 2024-06-20 682/week @ 2024-06-27

3,166 downloads per month
Used in 43 crates (29 directly)

Apache-2.0

7KB
53 lines

Rustastic Prompt

rprompt makes it easy to prompt for input in a console application on all platforms, Unix and Windows alike.

rprompt is made available free of charge. You can support its development through Liberapay 💪

Usage

Add rprompt as a dependency in Cargo.toml:

[dependencies]
rprompt = "2.1"

See examples and docs at https://docs.rs/rprompt.

License

The source code is released under the Apache 2.0 license.


lib.rs:

This library makes it easy to prompt for input in a console application on all platforms, Unix and Windows alike.

Here's how you can prompt for a reply:

let name = rprompt::prompt_reply("What's your name? ").unwrap();
println!("Your name is {}", name);

Alternatively, you can read the reply without prompting:

let name = rprompt::read_reply().unwrap();
println!("Your name is {}", name);

If you need more control over the source of the input, which can be useful if you want to unit test your CLI or handle pipes gracefully, you can use from_bufread versions of the functions and pass any reader you want:

let stdin = std::io::stdin();
let stdout = std::io::stdout();
let name = rprompt::prompt_reply_from_bufread(&mut stdin.lock(), &mut stdout.lock(), "What's your name? ").unwrap();
println!("Your name is {}", name);

Dependencies

~0–12MB
~91K SLoC