v0.3.0
Breaking Changes
Features #1 to #4 are all breaking changes and could break the compilation of your program.
Fix #2 representes a change in usability and might be an unexpected behavior.
Features
1. Completer
Completer
for Text
prompts, allowing users to auto-update their text input by pressing tab
and not having to navigate through a suggestion list.
It takes the current input and return an optional suggestion. If any, the prompter will replace the current input with the received suggestion. Completer
is an alias for &'a dyn Fn(&str) -> Result<Option<String>, CustomUserError>
.
The auto-completion API will be revamped for v0.4.0, watch #69.
2. Support for custom prompt prefix in finished prompts.
Added answered_prompt_prefix
configuration on RenderConfig
, allowing users to set custom prefixes (e.g. a check mark) to prompts that have already been answered.
Additionally, prompts that have been answered are now differed by a >
prefix instead of the usual ?
.
Cheers to @href for the suggestion! #44
3. User-provided operations can be fallible.
Input validation, suggestions and completions are now fallible operations.
The return type of validators has been changed to Result<Validation, CustomUserError>
. This means that validating the input can now be a fallible operation. The docs contain more thorough explanations and full-featured examples.
- Successful executions of the validator should return a variant of the
Validation
enum, which can be eitherValid
orInvalid(ErrorMessage)
. - Unsuccessful executions return a
CustomUserError
type, which is an alias forBox<dyn std::error::Error + Send + Sync + 'static>
.
The return type of suggesters has also been changed to allow fallible executions. The return type in successful executions continues to be Vec<String>
, while CustomUserError
is used with errors.
4. Validators are traits instead of closures.
All builtin validators have been turned into traits, with structs instead of macros as implementations.
This change makes it easier to share the validators throughout the code, especially if these carry their own owned data. For example, consider a validator that uses a compiled regular expression to verify the input. That validator can now be built as a new-type struct that encapsulates the regex.
Closures can still be used as before, but may not require to pass the argument type explicitly. The previous macros are now simply shorthands for the constructors of builtin validators.
Fixes
- Fix a broken link in the
struct.Text
documentation. - Suggestions are now always loaded at the start of a
Text
prompt.- Previously, suggestions were only loaded and displayed if the
Text
prompt was created with a pre-existing input value or after the user entered any input. - Now, even if the prompt is started without any input and the user hasn't done anything, suggestions are displayed.
- Previously, suggestions were only loaded and displayed if the
Changes
- Update
crossterm
andconsole
to their latest versions.