[][src]Struct dmenu_facade::DMenu

pub struct DMenu<'a> { /* fields omitted */ }

DISCLAIMER! This crate uses the shell to pipe strings into dmenu.

The dmenu wrapper. This struct is built using a builder pattern and finally executed. The items must implement Display to be displayed by dmenu.

The item's Display output must be unique, otherwise the latest in the list will be returned if the key is selected.

Example

use dmenu_facade::*;
let items = vec!["Hello", "World", "!"];
let chosen = DMenu::default()
                   .vertical_with_lines(2)
                   .execute(&items);
//Prints selected item to stdout
if let Ok(item) = chosen {
    println!("{}", chosen);
}

Implementations

impl<'a> DMenu<'a>[src]

pub fn display_bottom(self) -> Self[src]

Display dmenu on the bottom of the screen instead of the top

Example

use dmenu_facade::*;
let dmenu = DMenu::default()
                .display_bottom();

pub fn case_insensitive(self) -> Self[src]

Dmenu will search the list case insensetively

Example

use dmenu_facade::*;
let dmenu = DMenu::default()
                .case_insensitive();

pub fn vertical_with_lines(self, amount: i32) -> Self[src]

Display items vertically, with an amount of lines

Example

//Display dmenu with 5 linex vertically
use dmenu_facade::*;
let dmenu = DMenu::default()
                .vertical_with_lines(5);

pub fn display_on_monitor(self, monitor_id: i32) -> Self[src]

Display on a specific monitor. Index starts with 0

Example

// To display on the second monitor
use dmenu_facade::*;
let dmenu = DMenu::default()
                .display_on_monitor(1);

pub fn with_prompt(self, prompt: &'a str) -> Self[src]

Displays a prompt/title to the left of the selections.

Example

use dmenu_facade::*;
let dmenu = DMenu::default()
                .with_prompt("Select an item:");

pub fn with_font(self, font: &'a str) -> Self[src]

Specifies which font should be used

Example

use dmenu_facade::*;
let dmenu = DMenu::default()
                .with_font("FiraCodeNerdFont:size=13");

pub fn with_colors(
    self,
    normal_background_color: Option<Color<'a>>,
    normal_foreground_color: Option<Color<'a>>,
    selected_background_color: Option<Color<'a>>,
    selected_foreground_color: Option<Color<'a>>
) -> Self
[src]

Sets the colors for dmenu.

If only specific colors are wanted, the rest can be set to None to use defaults

Examples

use dmenu_facade::*;
//To set normal background to white, normal foreground to black, selected background to red and selected foreground to blue.
let dmenu = DMenu::default()
                .with_colors(Some(Color("#ffffff")), Some(Color("#000000")),
                Some(Color("#ff0000")), Some(Color("#0000ff")));
use dmenu_facade::*;
//To set normal background to white, normal foreground to black, selected background and selected foreground to default.
let dmenu = DMenu::default()
                .with_colors(Some(Color("#ffffff")), Some(Color("#000000")),
                None, None);

pub fn execute<T: Display>(self, list: &Vec<T>) -> Result<&T, Box<dyn Error>>[src]

Execute the dmenu struct as a command. Blocks the program till the user completes

Takes a reference to a list of items with the Display trait, and returns a Result containing a reference to the chosen item.

Example

use dmenu_facade::*;
let items = vec!["Hello", "There", "Hope you", "Like my", "Docs :)"];
let chosen = DMenu::default()
                .vertical_with_lines(4)
                .case_insensitive()
                .with_font("FiraCodeNerdFont:size=13")
                .with_prompt("Select an item!")
                .execute(&items);
if let Ok(item) = chosen {
    println!("{}", item);
}

pub fn execute_consume<T: Display>(
    self,
    list: Vec<T>
) -> Result<T, Box<dyn Error>>
[src]

Like execute, but consumes the list to return an owned item after the user chooses.

pub fn execute_as_input(self) -> Result<String, Box<dyn Error>>[src]

Will launch the configured DMenu without any items and return the string typed by the user

Trait Implementations

impl<'a> Clone for DMenu<'a>[src]

impl<'a> Debug for DMenu<'a>[src]

impl<'_> Default for DMenu<'_>[src]

impl<'a> Eq for DMenu<'a>[src]

impl<'a> Ord for DMenu<'a>[src]

impl<'a> PartialEq<DMenu<'a>> for DMenu<'a>[src]

impl<'a> PartialOrd<DMenu<'a>> for DMenu<'a>[src]

impl<'a> StructuralEq for DMenu<'a>[src]

impl<'a> StructuralPartialEq for DMenu<'a>[src]

Auto Trait Implementations

impl<'a> RefUnwindSafe for DMenu<'a>

impl<'a> Send for DMenu<'a>

impl<'a> Sync for DMenu<'a>

impl<'a> Unpin for DMenu<'a>

impl<'a> UnwindSafe for DMenu<'a>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.