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

Allow for a custom search filtering function for the SelectionPrompt #1545

Open
jord-nijhuis opened this issue May 14, 2024 · 0 comments
Open

Comments

@jord-nijhuis
Copy link

jord-nijhuis commented May 14, 2024

Is your feature request related to a problem? Please describe.
Right now, when using SelectionPrompt<T>.EnableSearch(), the search function will always be a String.Contains() see (ListPromptState.cs#L129).

It would be nice to allow for alternate searching strategies.

Describe the solution you'd like
A possible solution is to add an optional parameter to SelectionPrompt<T>.EnableSearch that is a Func<string, ListPromptItem<T>>, bool> that allows the user to provide a custom function that filters the items based on the search input.

If you want to search based on the start of the string, for example, you could do:

// ...
prompt.EnableSearch((search, item) => item.ToString()?.StartsWith(search, true, StringComparison.OrdinalIgnoreCase) == true)

Describe alternatives you've considered
An alternative option would be to add a separate method for setting the search function, instead of using SelectionPrompt<T>.EnableSearch.


Please upvote 👍 this issue if you are interested in it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Todo 🕑
Development

No branches or pull requests

1 participant