manifoldco / promptui

Interactive prompt for command-line applications
https://www.manifold.co
BSD 3-Clause "New" or "Revised" License
6.03k stars 333 forks source link

Dynamic search based select #213

Open jroper opened 1 year ago

jroper commented 1 year ago

This would probably be an entirely new feature. But, imagine you have a system with a million users stored in a database. And you want to select one based on a simple text search. Obviously, fetching a million users and rendering them in the select, and then using the searcher function to match them, is infeasible. Instead, you want the items that appear to be selected to be dynamic, using API calls to the backend to fetch the items based on what the user has typed so far. So, to implement it, instead of a static list of items, you'll have a callback:

func(input string) interface{}

This would have to use goroutines/channels to invoke the search in the background, while allowing the user to continue to enter text, so that after a user types a certain number of characters, it can immediately issue the search callback, and then continue to allow the user to type and refine the search, waiting till the previous callback has returned till it invokes the callback again with the currently input text (if different from the previous callback invocation).

Since Items in Select is currently interface{}, perhaps it could be possible to add this support to the existing select, I'm not sure if that would make sense or not.

SimFG commented 1 year ago

I have the same idea, and I am going to implement it.