rushterm

Crates.iorushterm
lib.rsrushterm
version1.1.2
sourcesrc
created_at2022-01-13 04:49:14.936157
updated_at2022-03-24 20:47:45.408511
descriptionMake your CLI app easy by adding menu. Create nested menus, navigate with hotkeys. Data-driven. No function/macro complexity.
homepagehttps://github.com/seanandyrush/rushterm
repositoryhttps://github.com/seanandyrush/rushterm
max_upload_size
id513183
size46,626
Andy Allison (aalowlevel)

documentation

https://docs.rs/rushterm/1.1.2/rushterm/

README

Donation

If you like this crate, you could become a backer or sponsor or donator via PayPal. Any amount is welcome.

link: https://www.paypal.com/donate/?hosted_button_id=AN536BKRLP8MG

Thank you!

Sean Andy Rush.

Rushterm

Make your CLI app easy by adding menu. Create nested menus, navigate with hotkeys. Data-driven. No function/macro complexity.

Example

Firstly, we'll need to construct a Menu instance with its Items. Bring them into scope. Menu instance doesn't need to be mutable. Next, we'll invoke .run() method on the instance to execute our menu:

use rushterm::{Item, Menu};

fn main() {
    let menu = Menu {
        name: "My Main Menu".to_string(),
        items: vec![
            Item::Action {
                name: "Action0".to_string(),
                hotkey: Some('a'),
                exp: Some("Action0 Explanation. This Has Been Assigned To A Hotkey.".to_string()),
            },
            Item::Action {
                name: "Action1".to_string(),
                hotkey: None,
                exp: Some("Action1 Explanation. This Has No Hotkey.".to_string()),
            },
            Item::SubMenu {
                name: "Submenu0".to_string(),
                hotkey: Some('s'),
                exp: Some("Submenu0 explanation.".to_string()),
                items: vec![
                    Item::Action {
                        name: "Sub Action0".to_string(),
                        hotkey: Some('a'),
                        exp: Some(
                            "Sub Action0 Explanation. This Has Been Assigned To A Hotkey."
                                .to_string(),
                        ),
                    },
                    Item::Action {
                        name: "Sub Action1".to_string(),
                        hotkey: Some('c'),
                        exp: Some(
                            "Sub Action1 Explanation. This Has Been Assigned To A Hotkey."
                                .to_string(),
                        ),
                    },
                    Item::SubMenu {
                        name: "Deepermenu0".to_string(),
                        hotkey: Some('d'),
                        exp: Some("Deepermenu0 Explanation.".to_string()),
                        items: vec![
                            Item::Action {
                                name: "Deeper Action0".to_string(),
                                hotkey: Some('f'),
                                exp: None,
                            },
                            Item::Action {
                                name: "Deeper Action1".to_string(),
                                hotkey: Some('g'),
                                exp: Some("Deeper Action1 Explanation.".to_string()),
                            },
                        ],
                    },
                ],
            },
            Item::Bool {
                name: "Bool0".to_string(),
                hotkey: Some('b'),
                exp: Some("Bool0 Explanation.".to_string()),
            },
            Item::Char {
                name: "Char0".to_string(),
                hotkey: Some('c'),
                exp: Some("Char0 Explanation.".to_string()),
            },
            Item::String {
                name: "String0".to_string(),
                hotkey: Some('t'),
                exp: Some("String0 Explanation.".to_string()),
            },
            Item::F32 {
                name: "F32".to_string(),
                hotkey: Some('f'),
                exp: Some("F32 Explanation.".to_string()),
            },
            Item::I32 {
                name: "I32".to_string(),
                hotkey: Some('i'),
                exp: Some("I32 Explanation.".to_string()),
            },
            Item::U32 {
                name: "U32".to_string(),
                hotkey: Some('u'),
                exp: Some("U32 Explanation.".to_string()),
            },
        ],
        exp: Some("My Main Menu Explanation.".to_string()),
        esc: true,
    };
    let selection = menu.run();
    dbg!(&selection);
}

If selection is successful, run() method will return us Selection type in Ok() variant to get information we may need in ongoing execution. You may also bring Selection and Value into scope in this case. But, if not, exits the execution with an Err() variant.

Commit count: 0

cargo fmt