textual-autocomplete
textual-autocomplete copied to clipboard
Is it possible to have Grouped Autocomplete?
I'm not sure if "Grouped Autocomplete" is an actual term, it might be something I'm making up.
The end goal would be to have different sets of autocomplete based on the placement in the input box. In my mind I'm thinking of 3 groups: object, verb and query. Each separated by a space character.
For this example, I imagine a Textual input box expecting input in the order: [object] [verb] [query]
Where as you type in the input box you start typing the first few letters of the 'object' and the only AutoComplete options shown are those in the list of 'objects'. You can continue typing or accept one of the autocomplete suggestions.
You add a space character and start typing again to begin the 'verb' and again as you begin the first few characters the only AutoComplete options shown are those from the 'verb' list.
After accepting an AutoComplete suggestion for the 'verb' you input a space character and begin typing the final item a 'query'. Again, as you get a few characters in the only AutoComplete items shown are those in the 'query' list.
I'm not quiet sure how to pull this off or if textual-autocomplete is the right module for the job. What are your thoughts?
Yes, the contents of the dropdown can be dynamic and based on the current value and cursor position inside the Input. You'll basically have to write your own function which returns the items that should appear inside the dropdown.
There's an example of this here: https://github.com/darrenburns/textual-autocomplete/blob/main/examples/custom_meta.py#L95
textual-autocomplete will pass the value and cursor position into the function for you.
However, a Textual bug meant that the function wasn't always firing when the cursor position changed. I'm not sure whether this has been fixed or not.
Do you mean grouped like this? I use this for docker repo selection. (and tag validation)
https://github.com/darrenburns/textual-autocomplete/assets/22514713/d97c671c-c026-4f59-86a4-7de0cebc23d9