dm_x

Crates.iodm_x
lib.rsdm_x
version0.2.3
created_at2022-06-13 09:40:18.260502+00
updated_at2022-06-21 09:55:53.203532+00
descriptionA library for using dmenu as an option picker
homepagehttps://github.com/d2718/dmx-rs
repositoryhttps://github.com/d2718/dmx-rs
max_upload_size
id604985
size34,758
Dan (d2718)

documentation

https://docs.rs/dm_x

README

dm_x

A 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.

Commit count: 7

cargo fmt