Expand description
Build async prompts for non-blocking user input!
Asynchronous I/O allows the (usually slow) I/O operations run concurrently with the rest of your (highlt efficient) code.
§Features
- Asynchronous - You can work while the user inputs something and even timeout!
- Common patterns - Built-in common question patterns including
- Cross-platform - Generic on
reader
andwriter
! Help
messages - Help the user to input a correct answer.Test
with feedback - Test the input and, optionally, give feedback upon errors.- Default values - Add a value for empty inputs.
- Standardized
error
handling - You can manage errors! Feedback
- Display a final message depending on the accepted value.
§Quick example
Give only five seconds to the user to confirm something, and continue upon no input! (instead of keep waiting)
use asking::error::Processing;
use std::time::Duration;
let question = asking::yn()
.message("Shall I continue? (you have 5 seconds to answer)")
.default_value(true) // value upon empty input
.timeout(Duration::from_secs(5_u64))
.ask();
match async_std::task::block_on(question) { // we decide to just wait, at most five secs
Ok(true) => println!("Super!"),
Ok(false) => println!("Okay, shutting down..."),
Err(Processing::Timeout { .. }) => println!("I think you are not here, I will continue :)"), // Automatic decision!,
_ => eprintln!("Error with questionnaire, try again later"),
}
Check out more examples!
Modules§
- error
- Errors while asking a question.
Structs§
- Question
Builder - Async I/O handler (in builder form).
Functions§
- date
- Date question.
- question
- Question for types implementing
FromStr
trait. - select
- Test if the value is inside an iterator
- select_
with_ msg - Test if the value is inside an iterator
- text
- Text question.
- yn
- Yes/No questions.
Type Aliases§
- StdQuestion
Builder - Question in the standard input/output of the current process.