pub fn string<T: Into<String>, T2: Into<String>>(
name: T,
default: T2,
allow_empty: bool,
) -> TerminalMenuItemExpand description
Make a terminal-menu item which you can enter a string of characters to. Empty strings may be enabled with a flag.
ยงExample
use terminal_menu::{menu, string, run, mut_menu};
let menu = menu(vec![
string("My Strings Name", "Default Value", /* allow empty string */ false)
]);
run(&menu);
println!("My Strings Value: {}", mut_menu(&menu).selection_value("My Strings Name"));Examples found in repository?
examples/readme.rs (line 10)
1fn main() {
2 use terminal_menu::{run, menu, label, scroll, list, string, password, numeric, submenu, back_button};
3 let menu = menu(vec![
4 label("--------------"),
5 label("MY lovely menu!"),
6 label("usage: tinker around"),
7 label("---------------"),
8 scroll("Selection", vec!["First Option", "Second Option", "Third Option"]),
9 list("Do Something", vec!["Yes", "No"]),
10 string("Your Name", "Samuel", false),
11 password("Your Password", "pass", false),
12 numeric("Numeric", 5.25, None, None, None),
13 submenu("Submenu", vec![back_button("Back")]),
14 back_button("Exit"),
15 ]);
16 run(&menu);
17}More examples
examples/string_and_numeric.rs (line 15)
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}