1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
use std::fmt::Display;
mod multiple_choice;
pub use multiple_choice::*;
#[cfg(feature = "cli-prompter")]
mod cli_prompter;
#[cfg(feature = "cli-prompter")]
pub use cli_prompter::*;
pub trait OkayPrompter {
/// Tells the prompter to start an "Okay" prompt
///
/// This prompt just requires user input for a confirmation something happend.
/// An example usage is "Press any key to continue..."
fn okay<T: Display>(&self, msg: T);
}
pub trait AskPrompter {
/// Tells the prompter to start a "Yes/No" prompt
///
/// This prompt just requires user input for a confirmation if they want to do something.
/// An example usage is "Are you sure you want to do this? \[Y/n\]"
///
/// This function should return [`None`] if the result couldn't be parsed
fn ask<T: Display>(&self, msg: T, default: bool) -> Option<bool>;
}
pub trait TextPrompter {
/// Tells the prompter to start a text input prompt
///
/// This prompt requires the user to input a string.
/// An example usage is "Enter your name below"
///
/// If `secret` is true, the prompt is meant for secretive inputs, like entering passwords, where the text should be hidden
///
/// This function should return [`None`] if the result couldn't be parsed
fn text_prompt<T: Display>(
&self,
msg: T,
secret: bool,
default: Option<String>,
) -> Option<String>;
}
pub trait Prompter: OkayPrompter + AskPrompter {}
impl<T: OkayPrompter + AskPrompter> Prompter for T {}