Function terminal_menu::run

source ·
pub fn run(menu: &TerminalMenu)
Expand description

Activate the menu and wait for it to exit.

Example

use terminal_menu::{TerminalMenu, menu, run};
let my_menu = menu(vec![
    list("galadriel", vec!["frodo", "bilbo"])
    numeric("boo", 4.67, Some(3.0), None, None)
]);
run(&my_menu);
Examples found in repository?
examples/long.rs (line 13)
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/cancel.rs (line 11)
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());
}
examples/colors.rs (line 21)
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
fn main() {
    use terminal_menu::*;

    // see the crossterm crate for all the color options
    use crossterm::style::Color;

    let menu = menu(vec![

        label("COLOR!"),
        label("Red").colorize(Color::Red),
        label("Green").colorize(Color::Green),
        label("Blue").colorize(Color::Blue),

        // selected item is always cyan
        button("Cyan")
    ]);
    run(&menu);
}
examples/readme.rs (line 15)
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);
}
examples/simple.rs (line 25)
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());
}
examples/selections.rs (line 27)
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"));
    }
}