Suggester
The Suggester
class is used by the Input widget.
SuggestFromList
class
¶
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
Parameter | Default | Description |
---|---|---|
suggestions
Iterable[str]
|
required | Valid suggestions sorted by decreasing priority. |
case_sensitive
bool
|
True
|
Whether suggestions are computed in a case sensitive manner
or not. The values provided in the argument |
Suggester
class
¶
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
Parameter | Default | Description |
---|---|---|
use_cache
bool
|
True
|
Whether to cache suggestion results. |
case_sensitive
bool
|
False
|
Whether suggestions are case sensitive or not. If they are not, incoming values are casefolded before generating the suggestion. |
cache
instance-attribute
¶
Suggestion cache, if used.
get_suggestion
abstractmethod
async
¶
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
Parameter | Default | Description |
---|---|---|
value
str
|
required | The current value of the requester widget. |
Returns
Type | Description |
---|---|
str | None
|
A valid suggestion or |