Function terminal_menu::list
source · pub fn list<T: Into<String>, T2: IntoIterator>(
name: T,
values: T2
) -> TerminalMenuItemwhere
T2::Item: Into<String>,
Expand description
Make a terminal-menu item from which you can select a value from a selection. Only the selected value is visible.
Example
use terminal_menu::{menu, list, run, mut_menu};
let menu = menu(vec![
list("My Lists Name", vec![
"First Option",
"Second Option",
"Third Option"
])
]);
run(&menu);
println!("My Lists Value: {}", mut_menu(&menu).selection_value("My Lists Name"));
Examples found in repository?
examples/readme.rs (line 9)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
fn main() {
use terminal_menu::{run, menu, label, scroll, list, string, numeric, submenu, back_button};
let menu = menu(vec![
label("--------------"),
label("MY lovely menu!"),
label("usage: tinker around"),
label("---------------"),
scroll("Selection", vec!["First Option", "Second Option", "Third Option"]),
list("Do Something", vec!["Yes", "No"]),
string("Your Name", "Samuel", false),
numeric("Numeric", 5.25, None, None, None),
submenu("Submenu", vec![back_button("Back")]),
back_button("Exit"),
]);
run(&menu);
}
More examples
examples/selections.rs (line 19)
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
fn main() {
use terminal_menu::{menu, label, button, list, scroll, run, mut_menu};
let menu = menu(vec![
label("lists and scrolls"),
// with list and scroll you can select a value from a group of values
// you can change the selected value with arrow keys, wasd, or enter
// use arrow keys or wasd
// enter to select
// list:
// show all values
// surround the selected value with brackets
list("li", vec!["Alice", "Bob", "Charlie"]),
// scroll:
// show only the selected item
scroll("sc", vec!["Alice", "Bob", "Charlie"]),
button("exit")
]);
run(&menu);
{
let mm = mut_menu(&menu);
println!("{}", mm.selection_value("li"));
println!("{}", mm.selection_value("sc"));
}
}