Struct ZenConsoleInput

Source
pub struct ZenConsoleInput;
Expand description

The main struct for ZenConsoleInput.

Use this struct to create new input, password, or selection prompts.

Implementations§

Source§

impl ZenConsoleInput

Source

pub fn new() -> Self

Creates a new ZenConsoleInput instance.

Examples found in repository?
examples/demo.rs (line 4)
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}
Source

pub fn input(&self) -> Input

Creates a new Input instance for text 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}
Source

pub fn selection(&self) -> Selection

Creates a new Selection instance for choosing from a list of options.

Examples found in repository?
examples/demo.rs (line 28)
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}
Source

pub fn password(&self) -> Password

Creates a new Password instance for password input.

Examples found in repository?
examples/demo.rs (line 40)
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§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.