3 unstable releases
0.3.1 | Nov 5, 2023 |
---|---|
0.3.0 | Feb 9, 2023 |
0.2.2 | Dec 8, 2022 |
0.1.0 |
|
#686 in Command-line interface
11KB
128 lines
menu_rs
This is library for Rust that allows the creation of simple and interactable command-line menus.
It's very simple to use, you just create a Menu, adds the option you want it to have with the correspondent action to be run when selected and that's it! You can use the arrow keys to move through the options, ENTER to select an option and ESC to exit the menu.
Example
use menu_rs::{Menu, MenuOption};
fn main() {
fn action_1() {
println!("Option 1 called!");
}
fn action_2() {}
fn action_3() {}
fn action_4() {}
let menu = Menu::new(vec![
MenuOption::new("Option 1", action_1).hint("Hint for option 1"),
MenuOption::new("Option 2", action_2),
MenuOption::new("Option 3", action_3),
MenuOption::new("Option 4", action_4),
]);
menu.show();
}
lib.rs
:
menu_rs is a library for Rust that allows the creation of simple and interactable command-line menus.
It's very simple to use, you just create a Menu, adds the option you want it to have with the correspondent action to be run when selected and that's it! You can use the arrow keys to move through the options, ENTER to select an option and ESC to exit the menu.
Example
use menu_rs::{Menu, MenuOption};
let my_variable: u32 = 157;
fn action_1() {
println!("action 1")
}
fn action_2(val: u32) {
println!("action 2 with number {}", val)
}
fn action_3(msg: &str, val: f32) {
println!("action 3 with string {} and float {}", msg, val)
}
fn action_4() {
println!("action 4")
}
let menu = Menu::new(vec![
MenuOption::new("Option 1", action_1).hint("Hint for option 1"),
MenuOption::new("Option 2", || action_2(42)),
MenuOption::new("Option 3", || action_3("example", 3.14)),
MenuOption::new("Option 4", action_4),
MenuOption::new("Option 5", move || action_2(my_variable)),
]);
menu.show();
Dependencies
~1.2–7.5MB
~57K SLoC