Skip to main content

Prompt

Struct Prompt 

Source
pub struct Prompt { /* private fields */ }
Expand description

Asks the user of the application a question and waits for the answer

Prompt holds the Output that sends a question to the presenter, the Cancellation that stops the wait, and the Interactivity of the application. Context::prompt builds one from the context of a command.

A question arrives at the presenter after the output that the command sent before it.

Without a user, a prompt returns PromptUserError::AbsentUser immediately and sends nothing. It never applies a default. interactivity reports whether a user is present.

Cancellation stops the wait, and the prompt returns PromptUserError::CancelledPrompt.

Prompt is cheaply clonable. Cloning produces another handle to the same event channel and the same cancellation token.

§Examples

use clawless_core::prompt::{Confirmation, Prompt};

let answer = prompt.confirm("Delete the branch?").await?;

let delete = match answer {
    Confirmation::Yes => true,
    Confirmation::No => false,
};

Implementations§

Source§

impl Prompt

Source

pub fn builder() -> PromptBuilder

Create an instance of Prompt using the builder syntax

Source§

impl Prompt

Source

pub fn interactivity(&self) -> Interactivity

Whether a user is present who can answer

Source§

impl Prompt

Source

pub async fn confirm( &self, question: impl Into<Confirm>, ) -> Result<Confirmation, PromptUserError>

Asks the user to confirm with yes or no

The question is a Confirm, or a text that converts into one without a default.

§Errors

Returns PromptUserError::AbsentUser if no user is present, and PromptUserError::CancelledPrompt if cancellation stopped the wait. Returns PromptUserError::UndeliverablePrompt if the presenter stopped listening, and PromptUserError::UnansweredPrompt if the prompt came back without an answer.

§Examples
use clawless_core::prompt::{Confirm, Confirmation, Prompt};

let question = Confirm::new("Publish the release?").with_default(Confirmation::No);

let answer = prompt.confirm(question).await?;
Source

pub async fn select<T: Display>( &self, question: impl Into<String>, options: impl IntoIterator<Item = T>, ) -> Result<T, PromptUserError>

Asks the user to select one of several options

The user sees the Display text of each option, in the order given. The call returns the option that the user selected.

§Errors

Returns PromptUserError::MissingOptions if there is no option to select from, whether or not a user is present. Returns PromptUserError::AbsentUser if no user is present, and PromptUserError::CancelledPrompt if cancellation stopped the wait. Returns PromptUserError::UndeliverablePrompt if the presenter stopped listening, and PromptUserError::UnansweredPrompt if the prompt came back without an answer. Returns PromptUserError::UnknownOption if the answer names an option that does not exist.

§Examples
use clawless_core::prompt::Prompt;

let port = prompt.select("Port to listen on", [80, 443, 8080]).await?;
Source

pub async fn text( &self, question: impl Into<Text>, ) -> Result<String, PromptUserError>

Asks the user for one line of text

The question is a Text, or a text that converts into one. The answer is the line as the user typed it, without the characters that end the line. The answer can be empty.

§Errors

Returns PromptUserError::AbsentUser if no user is present, and PromptUserError::CancelledPrompt if cancellation stopped the wait. Returns PromptUserError::UndeliverablePrompt if the presenter stopped listening, and PromptUserError::UnansweredPrompt if the prompt came back without an answer.

§Examples
use clawless_core::prompt::Prompt;

let title = prompt.text("Title of the change").await?;

Trait Implementations§

Source§

impl Clone for Prompt

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Prompt

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.