3 releases
0.2.10 | Mar 15, 2022 |
---|---|
0.2.9 | Mar 3, 2022 |
0.2.7 | Feb 25, 2022 |
#849 in Command-line interface
24 downloads per month
Used in ezmenu
77KB
1K
SLoC
EZMenuLib
Fast designing menus for your Rust CLI programs.
Caution: This library is not completely stable yet. Many changes may occur depending on versions. I am still looking for a sustainable design of the library.
This crate provides a library with structs and traits to easily build menus. It includes type-checking from the user input, and a formatting customization.
This crate is really useful if you use structopt or clap crates beside this, so you can get the matches safely, and build a menu on your own after.
It can also be used as a mode selection, for a game for example.
Note
If you want to use the derive(Menu)
macro,
you must use the ezmenu crate instead.
This crate may however contain features that are not available on the ezmenu crate.
Example
Here is an example of how to use the library:
use ezmenulib::prelude::*;
use std::error::Error;
fn main() -> Result<(), Box<dyn Error>> {
let mut my_menu = ValueMenu::from([
Field::Value(ValueField::from("Give your name")),
Field::Value(ValueField::from("Give a number")),
Field::Select(SelectMenu::from([
SelectField::from("0"),
SelectField::from("1"),
SelectField::from("2"),
])
.title(SelectTitle::from("Select a number"))),
]);
let name: String = my_menu.next_output()?;
let number: i32 = my_menu.next_output()?;
let amount: u8 = my_menu.next_output()?;
println!("hello {}, you entered {} and you selected {}.", name, number, amount);
}
This sample code prints the standard menu like above:
Hello there!
--> Give your name
>> Ahmad
--> Give a number
>> 1000
--> Select a number:
1 - 0
2 - 1
3 - 2
>> 2
hello Ahmad, you entered 1000 and you selected 2.
Documentation
You can find all the crate documentation on Docs.rs. You can also check the examples to learn with a practical way.
WIP
This project is still in development. You can check the EZMenu project to take a look at my todolist :D
Dependencies
~0–280KB