| Crates.io | dm_x |
| lib.rs | dm_x |
| version | 0.2.3 |
| created_at | 2022-06-13 09:40:18.260502+00 |
| updated_at | 2022-06-21 09:55:53.203532+00 |
| description | A library for using dmenu as an option picker |
| homepage | https://github.com/d2718/dmx-rs |
| repository | https://github.com/d2718/dmx-rs |
| max_upload_size | |
| id | 604985 |
| size | 34,758 |
dm_xA Rust crate for using dmenu, a
keyboard-driven menu originally written for use with tiling window managers.
Using this crate involves implementing the Item trait for your type,
and then passing a slice of those to the Dmx::select() method.
Item is already implemented for &str, so the following should work:
let choices: &[&str] = &[
"Choice A",
"Choice B",
"Choice C",
"Both A and B",
"Both B and C",
"All Three",
"None of the Above",
];
let dmx = Dmx::default();
match dmx.select("Pick One:", choices).unwrap() {
None => {
println!("You declined to select an option.");
},
Some(n) => match choices.get(n) {
None => {
println!("You somehow chose an invalid choice.");
},
Some(choice) => {
println!("You chose \"{}\".", choice);
}
}
}
See the examples/ for non-trivial implementation of Item.