Interactive terminal menu lib for rust.
make interactive menus in rust. In case of any issues feel free to create an issue here or create a pull request.
cargo install xmenu
This will also install a bin named xmenu
which can be called for simulating demos of xmenu working as well as fix an ISSUE in Windows terminal where ANSI colours are not displaying as it is supposed to. Instead, the colour codes are getting printed.
Just choose the option for fixing it after running xmenu
in the terminal
xmenu
For in script usage,
use xmenu::{Xmenu, Colour};
fn main() {
// define the menu
let mut xm = Xmenu::new();
// add options
xm.add("Option1");
xm.add("Option2");
// run and collect result
let result = xm.run(Colour::Blue); // this will make the selected option blue
// create conditions
if result == "Option1".to_string() {
// do something
} else if result == "Option2".to_string() {
// do something else
} else result == "Abort" {
std::process::exit(0);
}
}
For a demo, after installing xmenu
using cargo install xmenu
, run:
xmenu
in terminal.
After running xmenu
in terminal, choose the third option.