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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/// Procedural macro for type-safe user input with validation.
///
/// This macro displays a prompt, reads user input from stdin, trims it,
/// and attempts to parse it according to the expected return type.
/// If the input is empty or cannot be parsed, it displays an error
/// and prompts the user again.
///
/// # Features
/// - Automatically parses input to the target type
/// - Displays colorized error messages on invalid input
/// - Prevents empty input submission
/// - Handles various primitive types with appropriate validation
/// - Seamless integration with println! macro color syntax
/// - Automatic retry loop until valid input is provided
///
/// # Supported Types
/// - All primitive numeric types (`i8`, `i16`, `i32`, `i64`, `i128`, `isize`,
/// `u8`, `u16`, `u32`, `u64`, `u128`, `usize`, `f32`, `f64`)
/// - `String` - Returns the trimmed input without further parsing
/// - `bool` - Accepts "true"/"false", "yes"/"no", "y"/"n", "1"/"0"
/// - `char` - Accepts a single character input
///
/// # Examples
///
/// ## Basic Type-Safe Input
/// let name: String = input!("Enter your name: ");
/// let age: i32 = input!("Enter your age: ");
/// let height: f64 = input!("Enter your height in meters: ");
/// let proceed: bool = input!("Would you like to continue? (y/n): ");
/// let favorite_letter: char = input!("What's your favorite letter? ");
///
/// ## Colored Prompts
/// let score: u32 = input!("@(green, bold)Enter score (0-100): @()");
/// let username: String = input!("@(cyan)Username: @()");
/// let password: String = input!("@(yellow, dimmed)Password: @()");
///
/// ## Advanced Usage
/// let temperature: f32 = input!("@(blue)Temperature in °C: @()");
/// let confirm: bool = input!("@(red, bold)Are you sure? (y/n): @()");
///
/// # Error Handling
///
/// The macro automatically handles parsing errors and empty input:
/// - Empty input displays: "Error: Unauthorized empty input."
/// - Invalid format displays: "Error: {parsing_error}."
/// - Both errors are shown in red, bold, blinking text
/// - User is automatically prompted again until valid input is provided
///
/// # Technical Notes
///
/// - Uses stdin.read_line() for robust input capture
/// - Automatically trims whitespace from input
/// - Leverages Rust's FromStr trait for type conversion
/// - Integrates with the println! macro's color system via $("") syntax
/// - No heap allocations beyond the input string buffer
use TokenStream;
use quote;
use ;