Function terminal_menu::back_button
source · pub fn back_button<T: Into<String>>(name: T) -> TerminalMenuItem
Expand description
Make a back button terminal-menu item. Returns to the previous menu (or exits when there is none) when pressed.
Example
use terminal_menu::{menu, back_button, submenu};
let menu = menu(vec![
submenu("Submenus Name", vec![
back_button("Back")
]),
back_button("Exit"),
]);
Examples found in repository?
examples/readme.rs (line 12)
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/submenus.rs (line 17)
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 34 35 36 37 38 39
fn main() {
use terminal_menu::{menu, label, button, scroll, back_button, submenu, run, mut_menu};
let menu = menu(vec![
label("submenus"),
// submenu:
// submenus are basically menus inside menus
submenu("sub", vec![
scroll("scr", vec!["Alice", "Bob", "Charlie"]),
// back button:
// back buttons return to the parent menu.
back_button("back")
]),
submenu("ret", vec![
// button:
// buttons exit all the menus
button("Alice"),
button("Bob"),
button("Charlie"),
]),
button("exit")
]);
run(&menu);
// name of the menu active before exiting
println!("{:?}", mut_menu(&menu).get_latest_menu_name());
// pull values
println!("{}", mut_menu(&menu).get_submenu("sub").selection_value("scr"));
}