wait_for_enter

Function wait_for_enter 

Source
pub fn wait_for_enter()
Expand description

Waits for the user to press enter, prints “Press enter to continue “

This is basically a wrapper for prompt!("Press enter to continue ")

Examples found in repository?
examples/read_lines.rs (line 87)
3fn main() {
4	
5	println!("\n==== custom fuzzy-search testing ====");
6	let input = read!(["Lanercoast", "Windrip", "Redwick Bush", "Brickelwhyte", "Sirencester", "Conriston", "Inverness", "Norwich", "Elinmylly", "Murlayfield"]).1;
7	println!("You entered: \"{input}\"");
8	
9	
10	println!("\n==== `read!()` ====");
11	let input = read!(); // read a line of text
12	println!("You entered: \"{input}\"");
13	
14	println!("\n==== `prompt!(\"Enter a string: \")` ====");
15	let input = prompt!("Enter a string: "); // prompt a line of text
16	println!("You entered: \"{input}\"");
17	
18	println!("\n==== `read!(UsizeInput)` ====");
19	let input = read!(UsizeInput); // read specific types
20	println!("You entered: \"{input}\"");
21	println!("\n==== `read!(BoolInput)` ====");
22	let input = read!(BoolInput);
23	println!("You entered: \"{input}\"");
24	println!("\n==== `read!(NonWhitespaceInput)` ====");
25	let input = read!(NonWhitespaceInput);
26	println!("You entered: \"{input}\"");
27	println!("\n==== `read!(I32Input)` ====");
28	let input = read!(I32Input);
29	println!("You entered: \"{input}\"");
30	
31	println!("\n==== `read!(0. ..= 100.)` ====");
32	let input = read!(0. ..= 100.); // read a number within a range
33	println!("You entered: \"{input}\"");
34	
35	
36	println!("\n==== `prompt!(\"Confirm input: \"; YesNoInput)` ====");
37	let input = prompt!("Confirm input: "; YesNoInput); // read a bool
38	println!("You entered: \"{input}\"");
39	
40	println!("\n==== `prompt!(\"Confirm input: \"; [true] YesNoInput)` ====");
41	let input = prompt!("Confirm input: "; [true] YesNoInput); // set a default value
42	println!("You entered: \"{input}\"");
43	
44	
45	println!("\n==== `read!([\"red\", \"green\", \"blue\"])` ====");
46	let (index, input) = read!(["red", "green", "blue"]); // choose from a list of options
47	println!("You entered: index {index}, \"{input}\"");
48	println!("\n==== `read!(= \"red\", \"green\", \"blue\")` ====");
49	let (index, input) = read!(= "red", "green", "blue"); // some inputs types have special syntax
50	println!("You entered: index {index}, \"{input}\"");
51	
52	println!("\n==== `read!([InputOption::new(...), ...])` ====");
53	let (index, input) = read!([
54		InputOption::new("1", &["red"  , "r", "choose first" ], ()), // displayed as "1: red", can be chosen with "1", "red", "r", or "choose first"
55		InputOption::new("2", &["green", "g", "choose second"], ()),
56		InputOption::new("3", &["blue" , "b", "choose third" ], ()),
57	]);
58	println!("You entered: index {index}, \"{}\"", input.names[0]);
59	
60	println!("\n==== `read!(= ...)` ====");
61	let (index, input) = read!(=
62		"1"; "red"  ; ["r", "choose first" ]; (), // displayed as "1: red", can be chosen with "1", "red", "r", or "choose first"
63		"2"; "green"; ["g", "choose second"]; (),
64		"3"; "blue" ; ["b", "choose third" ]; (),
65	);
66	println!("You entered: index {index}, \"{}\"", input.names[0]);
67	
68	println!("\n==== `prompt!(\"Enter an even int: \"; TransformValidate(...));` ====");
69	// one-time custom logic
70	let input = prompt!("Enter an even int: "; TransformValidate (|x| {
71		// validate input as an integer
72		let Ok(x) = x.parse::<isize>() else {return Err(String::from("Could not parse input"));};
73		// validate input as even
74		if x % 2 != 0 {return Err(String::from("Input is not even."));}
75		Ok(x)
76	}));
77	println!("You entered: \"{input}\"");
78	
79	
80	println!("\n==== `prompt!(\"Enter an int: \"; [2usize] = \"a\", \"b\", \"c\")` ====");
81	let (index, input) = prompt!("Enter an int: "; [2usize] = "a", "b", "c"); // combine any features
82	println!("You entered: index {index}, \"{input}\"");
83	
84	
85	println!();
86	println!("read_lines example finished");
87	wait_for_enter();
88	
89}