pub fn numeric<T: Into<String>>(
name: T,
default: f64,
step: Option<f64>,
min: Option<f64>,
max: Option<f64>,
) -> TerminalMenuItem
Expand description
Make a terminal-menu item from which you can select a number between specified bounds.
ยงExample
use terminal_menu::{menu, numeric, run, mut_menu};
let menu = menu(vec![
numeric("My Numerics Name",
0.0, //default
Some(0.5), //step (optional)
Some(-5.0), //minimum (optional)
Some(10.0) //maximum (optional)
)
]);
run(&menu);
println!("My Numerics Value: {}", mut_menu(&menu).numeric_value("My Numerics Name"))
Examples found in repository?
examples/readme.rs (line 11)
1fn main() {
2 use terminal_menu::{run, menu, label, scroll, list, string, 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 numeric("Numeric", 5.25, None, None, None),
12 submenu("Submenu", vec![back_button("Back")]),
13 back_button("Exit"),
14 ]);
15 run(&menu);
16}
More examples
examples/string_and_numeric.rs (lines 22-34)
5fn main() {
6 use terminal_menu::{menu, label, button, string, 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 // numeric:
21 // a floating point number
22 numeric("num",
23 // default
24 4.5,
25
26 // step
27 Some(1.5),
28
29 // minimum
30 None,
31
32 // maximum
33 Some(150.0)
34 ),
35
36 button("exit")
37 ]);
38 run(&menu);
39 {
40 let mm = mut_menu(&menu);
41 println!("{}", mm.selection_value("ste"));
42 println!("{}", mm.selection_value("stn"));
43 println!("{}", mm.numeric_value("num"));
44 }
45}