Skip to main content

Crate valinta

Crate valinta 

Source
Expand description

This crate provide an easy and zero config multiple selector in terminal.

ยงUsage

ยงFirst: add this crate to your project

cargo add valinta

ยงNext:

use valinta::select;

fn main() -> std::io::Result<()> {

    let animals = vec![
        "๐Ÿฆ gorilla",
        "๐Ÿชผ jellyfish",
        "๐Ÿฆ lion",
        "๐Ÿ honeybee",
        "๐Ÿ— boar",
        "๐Ÿฆ‡ bat",
        "๐ŸŒ snail",
        "๐Ÿจ koala",
        "๐Ÿฆ‰ owl",
        "๐Ÿข turtle",
        "๐Ÿฌ dolphin",
    ];

    let selected_animals = select(&animals).expect("Error message");

    Ok(())
}

ยงOr by using ValintaError

use valinta::{select, ValintaError};
fn main() -> Result<(), ValintaError> {

    let animals = vec![
        "๐Ÿฆ gorilla",
        "๐Ÿชผ jellyfish",
        "๐Ÿฆ lion",
        "๐Ÿ honeybee",
        "๐Ÿ— boar",
        "๐Ÿฆ‡ bat",
        "๐ŸŒ snail",
        "๐Ÿจ koala",
        "๐Ÿฆ‰ owl",
        "๐Ÿข turtle",
        "๐Ÿฌ dolphin",
    ];

    let selected_animals = select(&animals)?;

    Ok(())
}

ยงUser interactions

key pressedAction
โ†“Next item
โ†‘Previous item
a or ASelect all
n or NDeselect all
i or IInvert selection
spaceToggle current
enterConfirm selection
escBreak

ยงReturned type

A tupple which include the selected data and the indexes of selected data

pub type Returned<T> = (Vec<T>, Vec<usize>);

Enumsยง

ValintaError
Errors for this crate

Functionsยง

select
select is the main function of this crate