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
impl Prompt
Sourcepub fn builder() -> PromptBuilder
pub fn builder() -> PromptBuilder
Create an instance of Prompt using the builder syntax
Source§impl Prompt
impl Prompt
Sourcepub fn interactivity(&self) -> Interactivity
pub fn interactivity(&self) -> Interactivity
Whether a user is present who can answer
Source§impl Prompt
impl Prompt
Sourcepub async fn confirm(
&self,
question: impl Into<Confirm>,
) -> Result<Confirmation, PromptUserError>
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?;Sourcepub async fn select<T: Display>(
&self,
question: impl Into<String>,
options: impl IntoIterator<Item = T>,
) -> Result<T, PromptUserError>
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?;Sourcepub async fn text(
&self,
question: impl Into<Text>,
) -> Result<String, PromptUserError>
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?;