shibayan / Sharprompt

Interactive command-line based application framework for C#
MIT License
761 stars 50 forks source link

refactor(Paginator): extract filtering of text input into Func #275

Open brianebeling opened 6 months ago

brianebeling commented 6 months ago

Adds a new constructor parameter that accepts a function for filtering text input (i.e. how text is filtered when typing into a Select or MultiSelect Prompt). This allows developers to override the default behavior (in this case .Contains(keyword)) with custom behavior such as fuzzy matching. This helps with long inputs, where you may have multiple keywords or matches in your string but are unsure about the order or exact input.

Motivation

I wanted to use Sharprompt to develop an internal tool, where I wanted to prompt the user to select one or multiple work items from a DevOps board. Sometimes it helps to filter with a text input such as "deliv closed" to match the row "Title: Delivery Menu, Type: User Story, State: Closed" or similar. For my own use case I would like a fuzzy match akin to fzf but was unable to implement that because the behavior is hardcoded into the paginator.

The PR may not be perfect, so I created it as a draft. What are your thoughts on this?