pub struct TerminalMenuStruct {
    pub items: Vec<TerminalMenuItem>,
    /* private fields */
}

Fields§

§items: Vec<TerminalMenuItem>

Implementations§

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"
Examples found in repository?
examples/long.rs (line 14)
5
6
7
8
9
10
11
12
13
14
15
fn main() {
    use terminal_menu::{menu, button, run, mut_menu};
    let menu = menu(

        // create buttons representing numbers from 1 to 100
        (1..100).map(|n| button(format!("{}", n))).collect()

    );
    run(&menu);
    println!("{}", mut_menu(&menu).selected_item_name());
}
More examples
Hide additional examples
examples/simple.rs (line 28)
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
fn main() {
    use terminal_menu::{menu, label, button, run, mut_menu};
    let menu = menu(vec![

        // label:
        //  not selectable, useful as a title, separator, etc...
        label("----------------------"),
        label("terminal-menu"),
        label("use wasd or arrow keys"),
        label("enter to select"),
        label("'q' or esc to exit"),
        label("-----------------------"),

        // button:
        //  exit the menu
        button("Alice"),
        button("Bob"),
        button("Charlie")

    ]);
    run(&menu);

    // you can get the selected buttons name like so:
    println!("Selected: {}", mut_menu(&menu).selected_item_name());
}

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 1

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");

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 item

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"));
Examples found in repository?
examples/selections.rs (line 30)
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"));
    }
}
More examples
Hide additional examples
examples/submenus.rs (line 38)
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"));
}
examples/string_and_numeric.rs (line 41)
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
40
41
42
43
44
45
fn main() {
    use terminal_menu::{menu, label, button, string, numeric, run, mut_menu};
    let menu = menu(vec![
        label("strings and numerics"),

        // string:
        //  a string of characters
        //  the last arguments specifies if empty strings are allowed

        // empty strings allowed:
        string("ste", "default", true),

        // empty strings not allowed:
        string("stn", "default", false),

        // numeric:
        //  a floating point number
        numeric("num",
            // default
            4.5,

            // step
            Some(1.5),

            // minimum
            None,

            // maximum
            Some(150.0)
        ),

        button("exit")
    ]);
    run(&menu);
    {
        let mm = mut_menu(&menu);
        println!("{}", mm.selection_value("ste"));
        println!("{}", mm.selection_value("stn"));
        println!("{}", mm.numeric_value("num"));
    }
}

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"));
Examples found in repository?
examples/string_and_numeric.rs (line 43)
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
40
41
42
43
44
45
fn main() {
    use terminal_menu::{menu, label, button, string, numeric, run, mut_menu};
    let menu = menu(vec![
        label("strings and numerics"),

        // string:
        //  a string of characters
        //  the last arguments specifies if empty strings are allowed

        // empty strings allowed:
        string("ste", "default", true),

        // empty strings not allowed:
        string("stn", "default", false),

        // numeric:
        //  a floating point number
        numeric("num",
            // default
            4.5,

            // step
            Some(1.5),

            // minimum
            None,

            // maximum
            Some(150.0)
        ),

        button("exit")
    ]);
    run(&menu);
    {
        let mm = mut_menu(&menu);
        println!("{}", mm.selection_value("ste"));
        println!("{}", mm.selection_value("stn"));
        println!("{}", mm.numeric_value("num"));
    }
}

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"));
Examples found in repository?
examples/submenus.rs (line 38)
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"));
}

Returns the menu (or submenu) which was active on deactivation.

Examples found in repository?
examples/submenus.rs (line 35)
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"));
}

Returns true if menu was exited with ‘q’ or esc

Example
use terminal_menu::{menu, button, run, mut_menu};
let menu = menu(vec![
    button("button")
]);
run(&menu);

// true if esc, false if button
println!("{}", mut_menu(&menu).canceled());
Examples found in repository?
examples/cancel.rs (line 14)
5
6
7
8
9
10
11
12
13
14
15
fn main() {
    use terminal_menu::{menu, label, button, run, mut_menu};
    let menu = menu(vec![
        label("press the button or hit 'q' or esc!"),
        button("button")
    ]);
    run(&menu);

    // true if exited with 'q' or esc, false if button was pressed
    println!("{}", mut_menu(&menu).canceled());
}

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.