ynqa / promkit

A toolkit for building interactive prompt in Rust
https://crates.io/crates/promkit
MIT License
267 stars 7 forks source link

Checkbox::new_with_checked #13

Closed dvdsk closed 7 months ago

dvdsk commented 7 months ago

Nice project! I would love to use it (it looks stunning!). However for my use case I want to run the checkbox prompt with some items pre-selected. I think this is common enough to fit the checkbox preset.

existing work: dialoguer has MultiSelect::items_checked.

ynqa commented 7 months ago

@dvdsk Thank you for your proposal! I'm considering incorporating it into the changes for v0.3.1, as it's not a difficult modification.

dvdsk commented 7 months ago

@dvdsk Thank you for your proposal! I'm considering incorporating it into the changes for v0.3.1, as it's not a difficult modification.

Thats great! I'll work off that branch (and master) no need to rush 0.3.1

Feel free to close the issue :)

ynqa commented 7 months ago

@dvdsk I added Checkbox::new_with_checked at https://github.com/ynqa/promkit/tree/dev-0.3.1/main.

It can be executed as follows:

use promkit::{preset::checkbox::Checkbox, Result};

fn main() -> Result {
    let mut p = Checkbox::new_with_checked(vec![
        ("Apple", true),
        ("Banana", false),
        ("Orange", true),
        ("Mango", false),
        ("Strawberry", false),
        ("Pineapple", false),
        ("Grape", false),
        ("Watermelon", false),
        ("Kiwi", false),
        ("Pear", true),
    ])
    .title("What are your favorite fruits?")
    .checkbox_lines(5)
    .prompt()?;
    println!("result: {:?}", p.run()?);
    Ok(())
}
dvdsk commented 7 months ago

Great! thanks a lot!