Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Title and Box options for Menu #12

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

dantebarbieri
Copy link

Closes #8. @nathom I'd love it if you integrated this and deployed a new version to Cargo. Happy to make any changes to the PR that you see fit. I did a possibly unnecessary step of converting a lot of String to life-time annotated &str because I believe that &str is generally more flexible, but I am new to Rust, so that may be a misconception.

New titled example:

use youchoose;

fn main() {
    let mut menu =
        youchoose::Menu::new(0..100).title(" Numbers from 0 to 99 ");
    let choice = menu.show();
    // `choice` is a Vec<usize> containing the chosen indices
    println!("Index of the chosen item: {:?}", choice);
}

titled preview

Old (modified) customization example:

use youchoose;

fn main() {
    let mut menu = youchoose::Menu::new(0..100)
        .preview(multiples) // Sets the preview function
        .preview_pos(youchoose::ScreenSide::Bottom, 0.3) // Sets the position of the preview pane
        .preview_label(" multiples ") // Sets the text at the top of the preview pane
        .multiselect() // Allows multiple items to be selected
        .icon(":(") // Sets the default (not selected) icon for an item
        .selected_icon(":)") // The icon for selected items
        .add_multiselect_key('s' as i32) // Bind the 's' key to multiselect
        .add_up_key('u' as i32) // Bind the 'u' key to up
        .add_down_key('d' as i32) // Bind the 'd' key to down
        .add_select_key('.' as i32) // Bind the '.' key to select
        .title(" A custom title ") // Sets the text at the top of the main pane
        .boxed(); // Draws a box around the menu

    let _choice = menu.show();
}

fn multiples(num: i32) -> String {
    // --- Snip ---
    format!("very custom: {}", num)
}

fullly customized

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature - title/prompt
1 participant