diff options
author | Valentin Popov <valentin@popov.link> | 2024-01-08 00:21:28 +0300 |
---|---|---|
committer | Valentin Popov <valentin@popov.link> | 2024-01-08 00:21:28 +0300 |
commit | 1b6a04ca5504955c571d1c97504fb45ea0befee4 (patch) | |
tree | 7579f518b23313e8a9748a88ab6173d5e030b227 /vendor/dialoguer/examples/input.rs | |
parent | 5ecd8cf2cba827454317368b68571df0d13d7842 (diff) | |
download | fparkan-1b6a04ca5504955c571d1c97504fb45ea0befee4.tar.xz fparkan-1b6a04ca5504955c571d1c97504fb45ea0befee4.zip |
Initial vendor packages
Signed-off-by: Valentin Popov <valentin@popov.link>
Diffstat (limited to 'vendor/dialoguer/examples/input.rs')
-rw-r--r-- | vendor/dialoguer/examples/input.rs | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/vendor/dialoguer/examples/input.rs b/vendor/dialoguer/examples/input.rs new file mode 100644 index 0000000..8691c2e --- /dev/null +++ b/vendor/dialoguer/examples/input.rs @@ -0,0 +1,44 @@ +use dialoguer::{theme::ColorfulTheme, Input}; + +fn main() { + let input: String = Input::with_theme(&ColorfulTheme::default()) + .with_prompt("Your name") + .interact_text() + .unwrap(); + + println!("Hello {}!", input); + + let mail: String = Input::with_theme(&ColorfulTheme::default()) + .with_prompt("Your email") + .validate_with({ + let mut force = None; + move |input: &String| -> Result<(), &str> { + if input.contains('@') || force.as_ref().map_or(false, |old| old == input) { + Ok(()) + } else { + force = Some(input.clone()); + Err("This is not a mail address; type the same value again to force use") + } + } + }) + .interact_text() + .unwrap(); + + println!("Email: {}", mail); + + let mail: String = Input::with_theme(&ColorfulTheme::default()) + .with_prompt("Your planet") + .default("Earth".to_string()) + .interact_text() + .unwrap(); + + println!("Planet: {}", mail); + + let mail: String = Input::with_theme(&ColorfulTheme::default()) + .with_prompt("Your galaxy") + .with_initial_text("Milky Way".to_string()) + .interact_text() + .unwrap(); + + println!("Galaxy: {}", mail); +} |