string_and_numeric/
string_and_numeric.rs

1///
2/// String and numeric terminal-menu items explained.
3///
4
5fn main() {
6    use terminal_menu::{menu, label, button, string, password, numeric, run, mut_menu};
7    let menu = menu(vec![
8        label("strings and numerics"),
9
10        // string:
11        //  a string of characters
12        //  the last arguments specifies if empty strings are allowed
13
14        // empty strings allowed:
15        string("ste", "default", true),
16
17        // empty strings not allowed:
18        string("stn", "default", false),
19
20        // password:
21        password("pass", "default", true),
22
23        // numeric:
24        //  a floating point number
25        numeric("num",
26            // default
27            4.5,
28
29            // step
30            Some(1.5),
31
32            // minimum
33            None,
34
35            // maximum
36            Some(150.0)
37        ),
38
39        button("exit")
40    ]);
41    run(&menu);
42    {
43        let mm = mut_menu(&menu);
44        if mm.canceled() {
45            println!("Canceled!");
46            return;
47        }
48        println!("{}", mm.selection_value("ste"));
49        println!("{}", mm.selection_value("stn"));
50        println!("{}", mm.selection_value("pass"));
51        println!("{}", mm.numeric_value("num"));
52    }
53}