Skip to main content

PickerTui

Struct PickerTui 

Source
pub struct PickerTui {
    pub default_query: String,
    pub header: Option<String>,
    pub auto_accept: bool,
}

Fields§

§default_query: String

The default value of the query text area

§header: Option<String>

The header text to indicate to the user what is being chosen

§auto_accept: bool

If there is zero or one options, automatically accept the choice

Implementations§

Source§

impl PickerTui

Source

pub fn new() -> Self

Examples found in repository?
examples/pick_a_noun.rs (line 5)
3pub fn main() -> eyre::Result<()> {
4    let nouns = vec!["dog", "cat", "house", "pickle", "mouse"];
5    let chosen = PickerTui::new().set_header("Pick a noun").pick_one(nouns)?;
6    println!("You chose {}", chosen);
7
8    Ok(())
9}
More examples
Hide additional examples
examples/pick_many_nouns.rs (line 5)
3pub fn main() -> eyre::Result<()> {
4    let nouns = vec!["dog", "cat", "house", "pickle", "mouse"];
5    let chosen = PickerTui::new()
6        .set_header("Press tab to select entries")
7        .pick_many(nouns)?;
8
9    println!("You chose {:?}", chosen);
10
11    Ok(())
12}
examples/starting_search.rs (line 5)
3pub fn main() -> eyre::Result<()> {
4    let nouns = vec!["dog", "cat", "house", "pickle", "mouse"];
5    let chosen = PickerTui::new()
6        .set_header("Pick a noun")
7        .set_query("ouse")
8        .pick_one(nouns)?;
9    println!("You chose {}", chosen);
10
11    Ok(())
12}
examples/multiline.rs (line 11)
3pub fn main() -> eyre::Result<()> {
4    let choices = vec![
5        "First\nSecond\nThird",
6        "A\nB\nC",
7        "IMPORT BRUH\nDO THING\nWOOHOO!",
8        "single item",
9        "another single item",
10    ];
11    let chosen = PickerTui::new().pick_many(choices)?;
12    println!("You chose: {chosen:#?}");
13    Ok(())
14}
examples/pick_a_path.rs (line 12)
4pub fn main() -> eyre::Result<()> {
5    let mut choices = Vec::new();
6    let dir = std::fs::read_dir(".")?;
7    for entry in dir {
8        let entry = entry?;
9        choices.push(entry);
10    }
11
12    let chosen = PickerTui::new()
13        .set_header("Pick a path")
14        .pick_one(choices.into_iter().map(|entry| Choice {
15            key: entry.path().display().to_string(), // the value shown to the user
16            value: entry, // the inner value we want to have after the user picks
17        }))?;
18
19    println!("You chose {}", chosen.file_name().to_string_lossy());
20
21    Ok(())
22}
Source

pub fn set_header(self, header: impl Into<String>) -> Self

Examples found in repository?
examples/pick_a_noun.rs (line 5)
3pub fn main() -> eyre::Result<()> {
4    let nouns = vec!["dog", "cat", "house", "pickle", "mouse"];
5    let chosen = PickerTui::new().set_header("Pick a noun").pick_one(nouns)?;
6    println!("You chose {}", chosen);
7
8    Ok(())
9}
More examples
Hide additional examples
examples/pick_many_nouns.rs (line 6)
3pub fn main() -> eyre::Result<()> {
4    let nouns = vec!["dog", "cat", "house", "pickle", "mouse"];
5    let chosen = PickerTui::new()
6        .set_header("Press tab to select entries")
7        .pick_many(nouns)?;
8
9    println!("You chose {:?}", chosen);
10
11    Ok(())
12}
examples/starting_search.rs (line 6)
3pub fn main() -> eyre::Result<()> {
4    let nouns = vec!["dog", "cat", "house", "pickle", "mouse"];
5    let chosen = PickerTui::new()
6        .set_header("Pick a noun")
7        .set_query("ouse")
8        .pick_one(nouns)?;
9    println!("You chose {}", chosen);
10
11    Ok(())
12}
examples/pick_a_path.rs (line 13)
4pub fn main() -> eyre::Result<()> {
5    let mut choices = Vec::new();
6    let dir = std::fs::read_dir(".")?;
7    for entry in dir {
8        let entry = entry?;
9        choices.push(entry);
10    }
11
12    let chosen = PickerTui::new()
13        .set_header("Pick a path")
14        .pick_one(choices.into_iter().map(|entry| Choice {
15            key: entry.path().display().to_string(), // the value shown to the user
16            value: entry, // the inner value we want to have after the user picks
17        }))?;
18
19    println!("You chose {}", chosen.file_name().to_string_lossy());
20
21    Ok(())
22}
Source

pub fn set_auto_accept(self, auto_accept: bool) -> Self

Source

pub fn set_query(self, query: impl Into<String>) -> Self

Examples found in repository?
examples/starting_search.rs (line 7)
3pub fn main() -> eyre::Result<()> {
4    let nouns = vec!["dog", "cat", "house", "pickle", "mouse"];
5    let chosen = PickerTui::new()
6        .set_header("Pick a noun")
7        .set_query("ouse")
8        .pick_one(nouns)?;
9    println!("You chose {}", chosen);
10
11    Ok(())
12}
Source

pub fn pick_one<T>(&self, choices: impl IntoChoices<T>) -> PickResult<T>

Examples found in repository?
examples/pick_a_noun.rs (line 5)
3pub fn main() -> eyre::Result<()> {
4    let nouns = vec!["dog", "cat", "house", "pickle", "mouse"];
5    let chosen = PickerTui::new().set_header("Pick a noun").pick_one(nouns)?;
6    println!("You chose {}", chosen);
7
8    Ok(())
9}
More examples
Hide additional examples
examples/starting_search.rs (line 8)
3pub fn main() -> eyre::Result<()> {
4    let nouns = vec!["dog", "cat", "house", "pickle", "mouse"];
5    let chosen = PickerTui::new()
6        .set_header("Pick a noun")
7        .set_query("ouse")
8        .pick_one(nouns)?;
9    println!("You chose {}", chosen);
10
11    Ok(())
12}
examples/pick_a_path.rs (lines 14-17)
4pub fn main() -> eyre::Result<()> {
5    let mut choices = Vec::new();
6    let dir = std::fs::read_dir(".")?;
7    for entry in dir {
8        let entry = entry?;
9        choices.push(entry);
10    }
11
12    let chosen = PickerTui::new()
13        .set_header("Pick a path")
14        .pick_one(choices.into_iter().map(|entry| Choice {
15            key: entry.path().display().to_string(), // the value shown to the user
16            value: entry, // the inner value we want to have after the user picks
17        }))?;
18
19    println!("You chose {}", chosen.file_name().to_string_lossy());
20
21    Ok(())
22}
Source

pub fn pick_many<T>(&self, choices: impl IntoChoices<T>) -> PickResult<Vec<T>>

Examples found in repository?
examples/pick_many_nouns.rs (line 7)
3pub fn main() -> eyre::Result<()> {
4    let nouns = vec!["dog", "cat", "house", "pickle", "mouse"];
5    let chosen = PickerTui::new()
6        .set_header("Press tab to select entries")
7        .pick_many(nouns)?;
8
9    println!("You chose {:?}", chosen);
10
11    Ok(())
12}
More examples
Hide additional examples
examples/multiline.rs (line 11)
3pub fn main() -> eyre::Result<()> {
4    let choices = vec![
5        "First\nSecond\nThird",
6        "A\nB\nC",
7        "IMPORT BRUH\nDO THING\nWOOHOO!",
8        "single item",
9        "another single item",
10    ];
11    let chosen = PickerTui::new().pick_many(choices)?;
12    println!("You chose: {chosen:#?}");
13    Ok(())
14}
Source

pub async fn pick_one_reloadable<T, F, C>( &self, choice_supplier: F, ) -> PickResult<T>
where F: AsyncFn(bool) -> Result<C>, C: IntoChoices<T>,

Source

pub async fn pick_many_reloadable<T, F, C>( &self, choice_supplier: F, ) -> PickResult<Vec<T>>
where F: AsyncFn(bool) -> Result<C>, C: IntoChoices<T>,

Source

pub async fn pick_inner_reloadable<T, F, C>( &self, many: bool, choice_supplier: F, ) -> PickResult<Vec<T>>
where F: AsyncFn(bool) -> Result<C>, C: IntoChoices<T>,

Source

pub fn pick_inner<T>( &self, many: bool, choices: impl IntoChoices<T>, ) -> PickResult<Vec<T>>

Trait Implementations§

Source§

impl Default for PickerTui

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more