Crate menu_genie

Source
Expand description

MenuGenie is a library for making multi-level terminal menus. It provides a MenuBuilder with a simple API for createing menus and managing actions when user makes a choice.

§How to use MenuGenie

Recomended way to use MenuGenie is to create a MenuBuilder instance, add menus and menu items to it. After that call prompt in a loop, handle errors and user inputs.

§Example

Here is an example of how to create a simple menu.

let mut menu = menu_genie::MenuBuilder::new()
    .with_menu(1)
    .with_menu_item("Create Todo", MenuAction::Nothing)
    .with_menu_item("Delete Todo", MenuAction::Nothing)
    .with_menu_item("Edit Todo", MenuAction::Navigate(2))
    .with_quit_button()
    .with_menu(2)
    .with_menu_item("Change Name", MenuAction::Nothing)
    .with_menu_item("Change Description", MenuAction::Nothing)
    .with_back_button()
    .build();

loop {
    match menu.prompt() {
        Ok(tuple) => match tuple {
            (1, 1) => println!("ACTION: Create Todo"),
            (1, 2) => println!("ACTION: Delete Todo"),
            (2, 1) => println!("ACTION: Change Name"),
            (2, 1) => println!("ACTION: Change Description"),
            (0, 0) => break,
            _ => ()
        },
        Err(e) => {
            println("{e}");
        }
    }
}

As you can see prompt returns a Result containing a tuple (menu_id, menu_item_id) or an error. Special case is when user wants to quit the menu, in that case tuple returned is (0, 0).

More examples can be found here.

Structs§

MenuBuilder
MenuBuilder provides simple API for creating nested menus.
MenuGenie
MenuGenie is a core struct that keeps track of which menus are called and which menu should be displayed.
MgError
Custom Error type

Enums§

MenuAction
MenuAction describes what should be done with the callstack.
MgErrorKind
Error kinds for MgError