Skip to content

Commit

Permalink
Fix #278, implement raw_prompt_skippable for Select
Browse files Browse the repository at this point in the history
  • Loading branch information
theRookieCoder committed Nov 16, 2024
1 parent 446ce3d commit 70e255a
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions inquire/src/prompts/select/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,26 @@ where
}
}

/// Parses the provided behavioral and rendering options and prompts
/// the CLI user for input according to the defined rules.
///
/// Returns a [`ListOption`](crate::list_option::ListOption) containing
/// the index of the selection and the owned object selected by the user.
///
/// This method is intended for flows where the user skipping/cancelling
/// the prompt - by pressing ESC - is considered normal behavior. In this case,
/// it does not return `Err(InquireError::OperationCanceled)`, but `Ok(None)`.
///
/// Meanwhile, if the user does submit an answer, the method wraps the return
/// type with `Some`.
pub fn raw_prompt_skippable(self) -> InquireResult<Option<ListOption<T>>> {
match self.raw_prompt() {
Ok(answer) => Ok(Some(answer)),
Err(InquireError::OperationCanceled) => Ok(None),
Err(err) => Err(err),
}
}

/// Parses the provided behavioral and rendering options and prompts
/// the CLI user for input according to the defined rules.
///
Expand Down

0 comments on commit 70e255a

Please sign in to comment.