Replies: 1 comment 1 reply
-
I suspect you may need to implement your own Here's a quick example: from textual import on
from textual.app import App, ComposeResult
from textual.suggester import Suggester
from textual.widgets import Input
class CustomSuggester(Suggester):
def __init__(self, case_sensitive: bool = True) -> None:
super().__init__(use_cache=False, case_sensitive=case_sensitive)
self._suggestions: list[str] = []
self._for_comparison: list[str] = []
async def get_suggestion(self, value: str) -> str | None:
for idx, suggestion in enumerate(self._for_comparison):
if suggestion.startswith(value):
return self._suggestions[idx]
return None
def add_suggestion(self, suggestion: str) -> None:
if suggestion not in self._suggestions:
self._suggestions.append(suggestion)
self._for_comparison.append(
suggestion if self.case_sensitive else suggestion.casefold()
)
class ExampleApp(App):
def compose(self) -> ComposeResult:
yield Input(suggester=CustomSuggester())
@on(Input.Submitted)
def on_input_submitted(self, event: Input.Submitted) -> None:
input = event.input
assert isinstance(input.suggester, CustomSuggester)
input.suggester.add_suggestion(event.value)
input.clear()
if __name__ == "__main__":
app = ExampleApp()
app.run() |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
A few weeks ago I stumbled on textual while looking for a user interface framework for a dynamic control practical based on micropython. Textual turned out to be very suitable, fast and fun as well. Many thanks for developing! In my app there are two REPLs, one for python and one for micropython. I would love to add some history-search and autocompletion in the REPLs. I tried to append past input values to the list of suggestions, see this commented line and the following, but this did not work. The suggester._suggestions list was appended (verified in textual console), but past inputs were not recognised by the suggester. However, when I run a mini example by hand:
the suggestion was correctly given:
'a=1'
. In my app I also played a bit with the LRUcache, but that did not help as well.Please, can someone shed some light on this? And am I willing something (in)feasable?
Beta Was this translation helpful? Give feedback.
All reactions