textual.suggester
Contains the Suggester
class, used by the Input widget.
SuggestFromList
¶
SuggestFromList(suggestions, *, case_sensitive=True)
Bases: Suggester
Give completion suggestions based on a fixed list of options.
Example
countries = ["England", "Scotland", "Portugal", "Spain", "France"]
class MyApp(App[None]):
def compose(self) -> ComposeResult:
yield Input(suggester=SuggestFromList(countries, case_sensitive=False))
If the user types P inside the input widget, a completion suggestion
for "Portugal"
appears.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
Iterable[str]
|
Valid suggestions sorted by decreasing priority. |
required |
|
bool
|
Whether suggestions are computed in a case sensitive manner
or not. The values provided in the argument |
True
|
Suggester
¶
Suggester(*, use_cache=True, case_sensitive=False)
Bases: ABC
Defines how widgets generate completion suggestions.
To define a custom suggester, subclass Suggester
and implement the async method
get_suggestion
.
See SuggestFromList
for an example.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
bool
|
Whether to cache suggestion results. |
True
|
|
bool
|
Whether suggestions are case sensitive or not. If they are not, incoming values are casefolded before generating the suggestion. |
False
|
get_suggestion
abstractmethod
async
¶
get_suggestion(value)
Try to get a completion suggestion for the given input value.
Custom suggesters should implement this method.
Note
The value argument will be casefolded if self.case_sensitive
is False
.
Note
If your implementation is not deterministic, you may need to disable caching.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
str
|
The current value of the requester widget. |
required |
Returns:
Type | Description |
---|---|
str | None
|
A valid suggestion or |