Skip to content

Commit

Permalink
Merge branch 'main' into rchriste/small_documention_improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
mikaelmello authored Nov 1, 2023
2 parents 1328b92 + 1949b47 commit 45c6116
Show file tree
Hide file tree
Showing 17 changed files with 345 additions and 162 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@
- Add strict clippy lints to improve code consistency and readability.
- Expand workflow clippy task to lint all-features in workspace.
- Add docs badge to readme.
- **Breaking** The Select and Multiselect Filter now scores input and is now expected to return an `Option<i64>`, making it possible to order/rank the list of options. [#176](https://github.com/mikaelmello/inquire/pull/176)
`None`: Will not be displayed in the list of options.
`Some(score)`: score determines the order of options, higher score, higher on the list of options.
- Implement fuzzy search as default on Select and MultiSelect prompts. [#176](https://github.com/mikaelmello/inquire/pull/176)
- Add new option on Select/MultiSelect prompts allowing to reset selection to the first item on filter-input changes. [#176](https://github.com/mikaelmello/inquire/pull/176)
- Keybindings Ctrl-p and Ctrl-n added for Up and Down actions
- Added 'with_starting_filter_input' to both Select and MultiSelect, which allows for setting an initial value to the filter section of the prompt.
- Keybindings Ctrl-j and Ctrl-g added for Enter and Cancel actions

### Fixes

Expand All @@ -26,6 +34,7 @@
- Raised MSRV to 1.63 due to requirements in downstream dependencies.
- MSRV is now explicitly set in the package definition.
- Replaced `lazy_static` with `once_cell` as `once_cell::sync::Lazy` is being standardized and `lazy_static` is not actively maintained anymore.
- Added `fuzzy-matcher` as an optional dependency for fuzzy filtering in Select and MultiSelect prompts [#176](https://github.com/mikaelmello/inquire/pull/176)

## [0.6.2] - 2023-05-07

Expand Down
4 changes: 2 additions & 2 deletions KEY_BINDINGS.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,5 +124,5 @@ These key bindings may be used in [`Editor`] prompts.
[`MultiSelect`]: https://docs.rs/inquire/*/inquire/prompts/multiselect/struct.MultiSelect.html
[`Confirm`]: https://docs.rs/inquire/*/inquire/prompts/confirm/struct.Confirm.html
[`Editor`]: https://docs.rs/inquire/*/inquire/prompts/editor/struct.Editor.html
[`CustomType`]: https://docs.rs/inquire/*/inquire/prompts/customtype/struct.CustomType.html
[`Password`]: https://docs.rs/inquire/*/inquire/prompts/password/struct.Password.html
[`customtype`]: https://docs.rs/inquire/*/inquire/struct.CustomType.html
[`Password`]: https://docs.rs/inquire/*/inquire/prompts/password/struct.Password.html
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ It provides several different prompts in order to interactively ask the user for
- Help messages;
- Autocompletion for [`Text`] prompts;
- Confirmation messages for [`Password`] prompts;
- Custom list filters for Select and [`MultiSelect`] prompts;
- Custom list filters for [`Select`] and [`MultiSelect`] prompts;
- Custom parsers for [`Confirm`] and [`CustomType`] prompts;
- Custom extensions for files created by [`Editor`] prompts;
- and many others!
Expand Down Expand Up @@ -154,13 +154,13 @@ The default parser for [`CustomType`] prompts calls the `parse::<T>()` method on

In the [demo](#demo) you can see this behavior in action with the _amount_ (CustomType) prompt.

## Filtering
## Scoring

Filtering is applicable to two prompts: [`Select`] and [`MultiSelect`]. They provide the user the ability to filter the options based on their text input. This is specially useful when there are a lot of options for the user to choose from, allowing them to quickly find their expected options.
Scoring is applicable to two prompts: [`Select`] and [`MultiSelect`]. They provide the user the ability to sort and filter the list of options based on their text input. This is specially useful when there are a lot of options for the user to choose from, allowing them to quickly find their expected options.

Filter functions receive three arguments: the current user input, the option string value and the option index. They must return a `bool` value indicating whether the option should be part of the results or not.
Scoring functions receive four arguments: the current user input, the option, the option string value and the option index. They must return a `Option<i64>` value indicating whether the option should be part of the results or not.

The default filter function does a naive case-insensitive comparison between the option string value and the current user input, returning `true` if the option string value contains the user input as a substring.
The default scoring function calculates a match value with the current user input and each option using SkimV2 from [fuzzy_matcher](https://crates.io/crates/fuzzy-matcher), resulting in fuzzy searching and filtering, returning `Some(<score>_i64)` if SkimV2 detects a match.

In the [demo](#demo) you can see this behavior in action with the _account_ (Select) and _tags_ (MultiSelect) prompts.

Expand Down Expand Up @@ -313,7 +313,7 @@ Like all others, this prompt also allows you to customize several aspects of it:
- Prints the selected option string value by default.
- **Page size**: Number of options displayed at once, 7 by default.
- **Display option indexes**: On long lists, it might be helpful to display the indexes of the options to the user. Via the `RenderConfig`, you can set the display mode of the indexes as a prefix of an option. The default configuration is `None`, to not render any index when displaying the options.
- **Filter function**: Function that defines if an option is displayed or not based on the current filter input.
- **Scoring function**: Function that defines the order of options and if an option is displayed or not based on the current user input.

## MultiSelect

Expand Down Expand Up @@ -344,7 +344,7 @@ Customizable options:
- No validators are on by default.
- **Page size**: Number of options displayed at once, 7 by default.
- **Display option indexes**: On long lists, it might be helpful to display the indexes of the options to the user. Via the `RenderConfig`, you can set the display mode of the indexes as a prefix of an option. The default configuration is `None`, to not render any index when displaying the options.
- **Filter function**: Function that defines if an option is displayed or not based on the current filter input.
- **Scoring function**: Function that defines the order of options and if an option is displayed or not based on the current user input.
- **Keep filter flag**: Whether the current filter input should be cleared or not after a selection is made. Defaults to true.

## Editor
Expand Down
2 changes: 1 addition & 1 deletion inquire-derive/CRATE_README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[crates.io]: https://crates.io/crates/inquire-derive
[latest version]: https://img.shields.io/crates/v/inquire-derive.svg
[build status]: https://github.com/mikaelmello/inquire/actions/workflows/test.yml/badge.svg
[build status]: https://github.com/mikaelmello/inquire/actions/workflows/build.yml/badge.svg
[supported platforms]: https://img.shields.io/badge/platform-linux%20%7C%20macos%20%7C%20windows-success
[license]: https://img.shields.io/crates/l/inquire-derive.svg

Expand Down
8 changes: 4 additions & 4 deletions inquire/CRATE_README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

[crates.io]: https://crates.io/crates/inquire
[latest version]: https://img.shields.io/crates/v/inquire.svg
[build status]: https://github.com/mikaelmello/inquire/actions/workflows/test.yml/badge.svg
[build status]: https://github.com/mikaelmello/inquire/actions/workflows/build.yml/badge.svg
[supported platforms]: https://img.shields.io/badge/platform-linux%20%7C%20macos%20%7C%20windows-success
[license]: https://img.shields.io/crates/l/inquire.svg

---

<p align="center">
<img width="460" src="./assets/inquire.png">
<img width="460" src="../assets/inquire.png">
<br>
<code>inquire</code> is a library for building interactive prompts on terminals.
</p>
Expand All @@ -29,7 +29,7 @@ It provides several different prompts in order to interactively ask the user for

## Demo

![Animated GIF making a demonstration of a questionnaire created with this library. You can replay this recording in your terminal with asciinema play command - asciinema play ./assets/expense_tracker.cast](./assets/expense_tracker.gif)
![Animated GIF making a demonstration of a questionnaire created with this library. You can replay this recording in your terminal with asciinema play command - asciinema play ../assets/expense_tracker.cast](../assets/expense_tracker.gif)
[Source](./examples/expense_tracker.rs)

## Features
Expand Down Expand Up @@ -66,5 +66,5 @@ inquire = { version = "0.6.2", features = ["date", "editor"] }
[`multiselect`]: https://docs.rs/inquire/*/inquire/prompts/multiselect/struct.MultiSelect.html
[`confirm`]: https://docs.rs/inquire/*/inquire/prompts/confirm/struct.Confirm.html
[`editor`]: https://docs.rs/inquire/*/inquire/prompts/editor/struct.Editor.html
[`customtype`]: https://docs.rs/inquire/*/inquire/prompts/customtype/struct.CustomType.html
[`customtype`]: https://docs.rs/inquire/*/inquire/struct.CustomType.html
[`password`]: https://docs.rs/inquire/*/inquire/prompts/password/struct.Password.html
5 changes: 4 additions & 1 deletion inquire/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@ path = "src/lib.rs"
doctest = true

[features]
default = ["macros", "crossterm", "one-liners"]
default = ["macros", "crossterm", "one-liners", "fuzzy"]
macros = []
one-liners = []
date = ["chrono"]
editor = ["tempfile"]
fuzzy = ["fuzzy-matcher"]

[package.metadata.docs.rs]
all-features = true
Expand All @@ -41,6 +42,8 @@ chrono = { version = "0.4", optional = true }

tempfile = { version = "3", optional = true }

fuzzy-matcher = { version = "0.3.7", default-features = false, optional = true }

bitflags = "2"
dyn-clone = "1"
newline-converter = "0.3"
Expand Down
4 changes: 2 additions & 2 deletions inquire/src/prompts/action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ where
I: InnerAction<Config = C>,
{
match key {
Key::Enter => Some(Action::Submit),
Key::Escape => Some(Action::Cancel),
Key::Enter | Key::Char('j', KeyModifiers::CONTROL) => Some(Action::Submit),
Key::Escape | Key::Char('g', KeyModifiers::CONTROL) => Some(Action::Cancel),
Key::Char('c', KeyModifiers::CONTROL) => Some(Action::Interrupt),
key => I::from_key(key, config).map(Action::Inner),
}
Expand Down
4 changes: 2 additions & 2 deletions inquire/src/prompts/multiselect/action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ impl InnerAction for MultiSelectPromptAction {
}

let action = match key {
Key::Up(KeyModifiers::NONE) => Self::MoveUp,
Key::Up(KeyModifiers::NONE) | Key::Char('p', KeyModifiers::CONTROL) => Self::MoveUp,
Key::PageUp => Self::PageUp,
Key::Home => Self::MoveToStart,

Key::Down(KeyModifiers::NONE) => Self::MoveDown,
Key::Down(KeyModifiers::NONE) | Key::Char('n', KeyModifiers::CONTROL) => Self::MoveDown,
Key::PageDown => Self::PageDown,
Key::End => Self::MoveToEnd,

Expand Down
3 changes: 3 additions & 0 deletions inquire/src/prompts/multiselect/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ pub struct MultiSelectConfig {
pub page_size: usize,
/// Whether to keep the filter text when an option is selected.
pub keep_filter: bool,
/// Whether to reset the cursor to the first option on filter input change.
pub reset_cursor: bool,
}

impl<T> From<&MultiSelect<'_, T>> for MultiSelectConfig {
Expand All @@ -17,6 +19,7 @@ impl<T> From<&MultiSelect<'_, T>> for MultiSelectConfig {
vim_mode: value.vim_mode,
page_size: value.page_size,
keep_filter: value.keep_filter,
reset_cursor: value.reset_cursor,
}
}
}
Loading

0 comments on commit 45c6116

Please sign in to comment.