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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
use Write;
/// Prompts the user with a question and expects a response indicating confirmation.
///
/// This function displays a specified prompt message to the standard output and waits
/// for the user to input a response. It assesses the response to check whether it
/// indicates agreement (e.g., "y", "Y", "yes", "YES", "Yes") and returns a corresponding
/// boolean value (`true` for agreement, `false` otherwise). Optionally, an abort message
/// can be displayed if the user does not confirm.
///
/// # Arguments
///
/// * `prompt` - A `String` containing the message to be displayed to the user.
/// * `abort_message` - An `Option<String>` containing a message to display if the user
/// does not confirm. If `None` or an empty string is provided, no abort message is displayed.
///
/// # Returns
///
/// * `true` - If the user provides a response indicating agreement (e.g., "y", "Y", "yes").
/// * `false` - If the user provides a response not indicating agreement, or otherwise.
///
/// # Panics
///
/// This function will panic if there is an error while:
/// - Flushing the standard output.
/// - Reading a line from the standard input.
///
/// # Examples
///
/// ```
/// use my_crate::ask_response;
///
/// let prompt = "Do you want to proceed? (y/n): ".to_string();
/// let abort_message = Some("Operation aborted by the user.".to_string());
///
/// if ask_response(prompt, abort_message) {
/// println!("User confirmed!");
/// } else {
/// println!("User did not confirm.");
/// }
/// ```
///
/// In the above example:
/// 1. If the user types "y" or "yes" (case-insensitive), `ask_response` returns `true`.
/// 2. If the user types anything else, `ask_response` prints the `abort_message`
/// (if provided) and returns `false`.
///