Skip to main content

ContextPrompter

Trait ContextPrompter 

Source
pub trait ContextPrompter {
    // Required methods
    fn select(
        &self,
        prompt: &str,
        items: &[String],
        default: usize,
    ) -> Result<usize>;
    fn multi_select(
        &self,
        prompt: &str,
        items: &[String],
        defaults: &[bool],
    ) -> Result<Vec<usize>>;
    fn confirm(&self, prompt: &str, default: bool) -> Result<bool>;
    fn input(
        &self,
        prompt: &str,
        default: Option<&str>,
        allow_empty: bool,
    ) -> Result<String>;
    fn edit(&self, prompt: &str, initial: &str) -> Result<String>;
}
Expand description

Trait for prompting user input, allowing testable implementations.

Required Methods§

Source

fn select( &self, prompt: &str, items: &[String], default: usize, ) -> Result<usize>

Select a single item from a list. Returns the index of the selected item.

Source

fn multi_select( &self, prompt: &str, items: &[String], defaults: &[bool], ) -> Result<Vec<usize>>

Select multiple items from a list. Returns indices of selected items.

Source

fn confirm(&self, prompt: &str, default: bool) -> Result<bool>

Confirm a yes/no question.

Source

fn input( &self, prompt: &str, default: Option<&str>, allow_empty: bool, ) -> Result<String>

Get text input from user.

Source

fn edit(&self, prompt: &str, initial: &str) -> Result<String>

Edit multi-line text in an editor.

Implementors§