Struct terminal_menu::TerminalMenuStruct
source · [−]pub struct TerminalMenuStruct {
pub items: Vec<TerminalMenuItem>,
/* private fields */
}Fields
items: Vec<TerminalMenuItem>Implementations
sourceimpl TerminalMenuStruct
impl TerminalMenuStruct
sourcepub fn selected_item_name(&self) -> &str
pub fn selected_item_name(&self) -> &str
Returns the name of the selected menu item.
Example
use terminal_menu::{menu, button, run, mut_menu};
let my_menu = menu(vec![
button("a"),
button("b"),
]);
run(&my_menu);
println!("selected item name: {}", mut_menu(&my_menu).selected_item_name()); //"a" or "b"sourcepub fn selected_item_index(&self) -> usize
pub fn selected_item_index(&self) -> usize
Returns the selected item as an index of the items vec.
Example
use terminal_menu::{menu, button, run, mut_menu};
let my_menu = menu(vec![
button("a"),
button("b"),
]);
run(&my_menu);
println!("selected item index: {}", mut_menu(&my_menu).selected_item_index()); // 0 or 1sourcepub fn set_selected_item_with_name(&mut self, item: &str)
pub fn set_selected_item_with_name(&mut self, item: &str)
Set the selected item with a name.
Example
use terminal_menu::{TerminalMenu, menu, button, mut_menu};
let my_menu: TerminalMenu = menu(vec![
button("item"),
button("other item")
]);
mut_menu(&my_menu).set_selected_item_with_name("item");sourcepub fn set_selected_item_with_index(&mut self, item: usize)
pub fn set_selected_item_with_index(&mut self, item: usize)
Set the selected item with an index of the items vec.
Example
use terminal_menu::{TerminalMenu, menu, button, mut_menu};
let my_menu: TerminalMenu = menu(vec![
button("item"),
button("other item")
]);
mut_menu(&my_menu).set_selected_item_with_index(1); //index 1 = other itemsourcepub fn selection_value(&self, name: &str) -> &str
pub fn selection_value(&self, name: &str) -> &str
Returns the value of the specified scroll, list, or string item.
Example
use terminal_menu::{TerminalMenu, menu, scroll, run, mut_menu};
let my_menu: TerminalMenu = menu(vec![
scroll("item", vec!["val1", "val2"])
]);
run(&my_menu);
println!("item value: {}", mut_menu(&my_menu).selection_value("item"));sourcepub fn numeric_value(&self, name: &str) -> f64
pub fn numeric_value(&self, name: &str) -> f64
Returns the value of the specified numeric item.
Example
use terminal_menu::{TerminalMenu, menu, scroll, run, numeric, mut_menu};
let my_menu: TerminalMenu = menu(vec![
numeric("item", 0.0, None, None, None)
]);
run(&my_menu);
println!("item value: {}", mut_menu(&my_menu).numeric_value("item"));Returns the specified submenu.
Example
use terminal_menu::{TerminalMenu, menu, run, submenu, scroll, mut_menu};
let my_menu: TerminalMenu = menu(vec![
submenu("sub",vec![
scroll("item", vec!["winnie", "the", "pooh"])
])
]);
run(&my_menu);
println!("{}", mut_menu(&my_menu).get_submenu("sub").selection_value("item"));Returns the menu (or submenu) which was active on deactivation.
Auto Trait Implementations
impl RefUnwindSafe for TerminalMenuStruct
impl Send for TerminalMenuStruct
impl Sync for TerminalMenuStruct
impl Unpin for TerminalMenuStruct
impl UnwindSafe for TerminalMenuStruct
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more