Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement raw_prompt_skippable for Select #279

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- Fix autocomplete suggestions not being updated after a suggestion is accepted. Thanks @moritz-hoelting and @istudyatuni for reporting and fixing it!
- Fix incorrect cursor placement when inputting CJK characters. Thanks @phostann (#270) for reporting it!
- Removed unused dependency (newline-converter). Thanks @jonassmedegaard (#267) for catching it!
- Implement `raw_prompt_skippable` for `Select`

## [0.7.5] - 2024-04-23

Expand Down
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
Loading