Crate rprompt

Source
Expand description

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);

Functions§

prompt_reply
Displays a message on the TTY, then reads user input from stdin
prompt_reply_from_bufread
Displays a message on the TTY, then reads user input from anything that implements BufRead
read_reply
Reads user input from stdin
read_reply_from_bufread
Reads user input from anything that implements BufRead