Crates.io | ezmenulib |
lib.rs | ezmenulib |
version | 0.2.10 |
source | src |
created_at | 2022-02-25 18:10:35.683005 |
updated_at | 2022-03-15 21:56:18.955115 |
description | Build easily a CLI menu. |
homepage | |
repository | https://github.com/ahbalbk/ezmenulib |
max_upload_size | |
id | 539568 |
size | 81,676 |
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.
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.
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.
You can find all the crate documentation on Docs.rs. You can also check the examples to learn with a practical way.
This project is still in development. You can check the EZMenu project to take a look at my todolist :D