pub struct Input { /* private fields */ }Expand description
Struct for handling text input from the user.
Implementations§
Source§impl Input
impl Input
Sourcepub fn message(self, msg: &str) -> Self
pub fn message(self, msg: &str) -> Self
Sets the prompt message for the input.
Examples found in repository?
examples/demo.rs (line 7)
3fn main() {
4 let zci = ZenConsoleInput::new();
5
6 // Simple input
7 let name = zci.input().message("Enter your name: ").get_input();
8 println!("Hello, {}!", name);
9
10 // Input with default value
11 let age: u32 = zci
12 .input()
13 .message("Enter your age [19]: ")
14 .default("19")
15 .get_parsed_input();
16 println!("You are {} years old.", age);
17
18 // Multiline input (with optional editor support)
19 let bio = zci
20 .input()
21 .message("Enter your bio")
22 .multiline()
23 .get_input();
24 println!("Your bio:\n{}", bio);
25
26 // Selection
27 let favorite_color = zci
28 .selection()
29 .message("Choose your favorite color")
30 .options(vec![
31 "Red".to_string(),
32 "Green".to_string(),
33 "Blue".to_string(),
34 ])
35 .get_selection();
36 println!("Your favorite color is {}", favorite_color);
37
38 // Password
39 let password = zci
40 .password()
41 .message("Enter your password: ")
42 .get_password();
43 println!("Your password is {} characters long", password.len());
44}Sourcepub fn default(self, value: &str) -> Self
pub fn default(self, value: &str) -> Self
Sets a default value for the input.
Examples found in repository?
examples/demo.rs (line 14)
3fn main() {
4 let zci = ZenConsoleInput::new();
5
6 // Simple input
7 let name = zci.input().message("Enter your name: ").get_input();
8 println!("Hello, {}!", name);
9
10 // Input with default value
11 let age: u32 = zci
12 .input()
13 .message("Enter your age [19]: ")
14 .default("19")
15 .get_parsed_input();
16 println!("You are {} years old.", age);
17
18 // Multiline input (with optional editor support)
19 let bio = zci
20 .input()
21 .message("Enter your bio")
22 .multiline()
23 .get_input();
24 println!("Your bio:\n{}", bio);
25
26 // Selection
27 let favorite_color = zci
28 .selection()
29 .message("Choose your favorite color")
30 .options(vec![
31 "Red".to_string(),
32 "Green".to_string(),
33 "Blue".to_string(),
34 ])
35 .get_selection();
36 println!("Your favorite color is {}", favorite_color);
37
38 // Password
39 let password = zci
40 .password()
41 .message("Enter your password: ")
42 .get_password();
43 println!("Your password is {} characters long", password.len());
44}Sourcepub fn disable_tips(self) -> Self
pub fn disable_tips(self) -> Self
Disables tips for the input.
Sourcepub fn multiline(self) -> Self
pub fn multiline(self) -> Self
Enables multiline input mode.
Examples found in repository?
examples/demo.rs (line 22)
3fn main() {
4 let zci = ZenConsoleInput::new();
5
6 // Simple input
7 let name = zci.input().message("Enter your name: ").get_input();
8 println!("Hello, {}!", name);
9
10 // Input with default value
11 let age: u32 = zci
12 .input()
13 .message("Enter your age [19]: ")
14 .default("19")
15 .get_parsed_input();
16 println!("You are {} years old.", age);
17
18 // Multiline input (with optional editor support)
19 let bio = zci
20 .input()
21 .message("Enter your bio")
22 .multiline()
23 .get_input();
24 println!("Your bio:\n{}", bio);
25
26 // Selection
27 let favorite_color = zci
28 .selection()
29 .message("Choose your favorite color")
30 .options(vec![
31 "Red".to_string(),
32 "Green".to_string(),
33 "Blue".to_string(),
34 ])
35 .get_selection();
36 println!("Your favorite color is {}", favorite_color);
37
38 // Password
39 let password = zci
40 .password()
41 .message("Enter your password: ")
42 .get_password();
43 println!("Your password is {} characters long", password.len());
44}Sourcepub fn get_input(&self) -> String
pub fn get_input(&self) -> String
Gets the input from the user as a String.
Examples found in repository?
examples/demo.rs (line 7)
3fn main() {
4 let zci = ZenConsoleInput::new();
5
6 // Simple input
7 let name = zci.input().message("Enter your name: ").get_input();
8 println!("Hello, {}!", name);
9
10 // Input with default value
11 let age: u32 = zci
12 .input()
13 .message("Enter your age [19]: ")
14 .default("19")
15 .get_parsed_input();
16 println!("You are {} years old.", age);
17
18 // Multiline input (with optional editor support)
19 let bio = zci
20 .input()
21 .message("Enter your bio")
22 .multiline()
23 .get_input();
24 println!("Your bio:\n{}", bio);
25
26 // Selection
27 let favorite_color = zci
28 .selection()
29 .message("Choose your favorite color")
30 .options(vec![
31 "Red".to_string(),
32 "Green".to_string(),
33 "Blue".to_string(),
34 ])
35 .get_selection();
36 println!("Your favorite color is {}", favorite_color);
37
38 // Password
39 let password = zci
40 .password()
41 .message("Enter your password: ")
42 .get_password();
43 println!("Your password is {} characters long", password.len());
44}Sourcepub fn get_parsed_input<T: FromStr>(&self) -> T
pub fn get_parsed_input<T: FromStr>(&self) -> T
Gets the input from the user and parses it to the specified type.
Examples found in repository?
examples/demo.rs (line 15)
3fn main() {
4 let zci = ZenConsoleInput::new();
5
6 // Simple input
7 let name = zci.input().message("Enter your name: ").get_input();
8 println!("Hello, {}!", name);
9
10 // Input with default value
11 let age: u32 = zci
12 .input()
13 .message("Enter your age [19]: ")
14 .default("19")
15 .get_parsed_input();
16 println!("You are {} years old.", age);
17
18 // Multiline input (with optional editor support)
19 let bio = zci
20 .input()
21 .message("Enter your bio")
22 .multiline()
23 .get_input();
24 println!("Your bio:\n{}", bio);
25
26 // Selection
27 let favorite_color = zci
28 .selection()
29 .message("Choose your favorite color")
30 .options(vec![
31 "Red".to_string(),
32 "Green".to_string(),
33 "Blue".to_string(),
34 ])
35 .get_selection();
36 println!("Your favorite color is {}", favorite_color);
37
38 // Password
39 let password = zci
40 .password()
41 .message("Enter your password: ")
42 .get_password();
43 println!("Your password is {} characters long", password.len());
44}Auto Trait Implementations§
impl Freeze for Input
impl RefUnwindSafe for Input
impl Send for Input
impl Sync for Input
impl Unpin for Input
impl UnwindSafe for Input
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more