Struct youchoose::Menu[][src]

pub struct Menu<'a, I, D> where
    D: Display,
    I: Iterator<Item = D>, 
{ /* fields omitted */ }
Expand description

A Menu that lazily displays an iterable and (optionally) its preview.

Implementations

impl<'a, I, D> Menu<'a, I, D> where
    D: Display,
    I: Iterator<Item = D>, 
[src]

pub fn new(iter: I) -> Menu<'a, I, D>[src]

Create a new menu object. The iterable passed in must contain displayable items.

pub fn show(&mut self) -> Vec<usize>[src]

Initialize curses and display the menu on the screen.

pub fn preview<F>(self, func: F) -> Menu<'a, I, D> where
    F: Fn(D) -> String + 'static, 
[src]

Add a preview pane that displays the result of applying the function passed in to each item in the iterable. The function must return a String.

pub fn preview_pos(self, side: ScreenSide, width: f64) -> Menu<'a, I, D>[src]

Sets the position of the preview pane. The side parameter determines the side on which the pane sits. The width parameter is a float between 0.0 and 1.0, inclusive. It determines the proportion of the screen that the preview pane should use.

The menu’s side is automatically switched to opposite the preview pane’s side, and the menu’s width is set to 1 - width.

pub fn icon(self, icon: &'a str) -> Menu<'a, I, D>[src]

Sets the default icon of the menu. This is displayed before each entry.

pub fn selected_icon(self, icon: &'a str) -> Menu<'a, I, D>[src]

Sets the icon displayed when an item is selected in multiselect mode.

pub fn preview_label(self, label: String) -> Menu<'a, I, D>[src]

Sets the text displayed on top of the preview box. It is recommended to surround the label with spaces for aesthetic reasons. If it is not set, " preview " will be used.

pub fn add_multiselect_key(self, key: i32) -> Menu<'a, I, D>[src]

Adds a keybinding that triggers a multiselection. This inputs an ncurses keycode. All ascii keys can be set by passing the character as an i32. The keycodes for special keys can be found by importing ncurses and using the provided constants or by testing with the getch function. For example, running the following will display the keycodes on the screen.

// Make sure to add ncurses as a dependency!
use ncurses::*;
fn main() {
    initscr();
    loop {
        let c: i32 = getch();
        clear();
        if c == 'q' as i32 {break}
        addstr(&format!("Pressed key with keycode {}!", c.to_string()));
    }
    endwin();
}

pub fn add_up_key(self, key: i32) -> Menu<'a, I, D>[src]

Adds a keybinding that triggers an up movement. See add_multiselect_key for more information.

pub fn add_down_key(self, key: i32) -> Menu<'a, I, D>[src]

Adds a keybinding that triggers a down movement. See add_multiselect_key for more information.

pub fn add_select_key(self, key: i32) -> Menu<'a, I, D>[src]

Adds a keybinding that triggers a selection. See add_multiselect_key for more information.

pub fn multiselect(self) -> Menu<'a, I, D>[src]

Allow multiple items to be selected from the menu.

Auto Trait Implementations

impl<'a, I, D> !RefUnwindSafe for Menu<'a, I, D>

impl<'a, I, D> !Send for Menu<'a, I, D>

impl<'a, I, D> !Sync for Menu<'a, I, D>

impl<'a, I, D> Unpin for Menu<'a, I, D> where
    D: Unpin,
    I: Unpin

impl<'a, I, D> !UnwindSafe for Menu<'a, I, D>

Blanket Implementations

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

pub fn type_id(&self) -> TypeId[src]

Gets the TypeId of self. Read more

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

pub fn borrow(&self) -> &T[src]

Immutably borrows from an owned value. Read more

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

pub fn borrow_mut(&mut self) -> &mut T[src]

Mutably borrows from an owned value. Read more

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

pub fn from(t: T) -> T[src]

Performs the conversion.

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

pub fn into(self) -> U[src]

Performs the conversion.

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.

pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]

Performs the conversion.

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.

pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>[src]

Performs the conversion.