Function terminal_menu::scroll

source ·
pub fn scroll<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. All values are dispalyed all the time.

Example

use terminal_menu::{menu, scroll, run, mut_menu};
let menu = menu(vec![
    scroll("My Scrolls Name", vec![
        "First Option",
        "Second Option",
        "Third Option"
    ])
]);
run(&menu);
println!("My Scrolls Value: {}", mut_menu(&menu).selection_value("My Scrolls Name"));
Examples found in repository?
examples/readme.rs (line 8)
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
Hide additional examples
examples/selections.rs (line 23)
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"));
    }
}
examples/submenus.rs (line 13)
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"));
}