ezmenu 0.2.5

Builds a CLI menu with a derive.
Documentation

EZMenu

Fast designing menus for your Rust CLI programs.

This crate provides a derive(Menu) procedural macro to easily build menus. It includes type-checking from the user input, and a formatting customization.

Documentation

You can find all the crate documentation on Docs.rs. You can also check the examples to learn with a practical way.

Example

Here is an example of how to use it:

use std::io::Write;
use ezmenu::{Menu, MenuResult};

fn map(val: u32, w: &mut impl Write) -> MenuResult<u32> {
    if val == 1000 {
        w.write(b"ok!\n")?;
    }
    Ok(val)
}

#[derive(Menu)]
#[menu(title = "Hello there!")]
struct MyMenu {
    author: String,
    #[field(msg = "Give a number", then(map))]
    number: u32,
}

To display the menu, you instantiate the struct by calling its from_menu method:

let MyMenu { author, number } = MyMenu::from_menu();
println!("values provided: author={}, number={}", author, number);

This sample code prints the standard menu like above:

Hello there!
* author: Ahmad
* Give a number: 1000
ok!
values provided: author=Ahmad, number=1000

WIP

This project is still in development. You can check the EZMenu project to see all the next features.