File: basic_single_column.py

package info (click to toggle)
textual-autocomplete 4.0.5-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 788 kB
  • sloc: python: 1,835; makefile: 4
file content (35 lines) | stat: -rw-r--r-- 852 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
"""Basic dropdown autocomplete from a list of options."""

from textual.app import App, ComposeResult
from textual.containers import Container
from textual.widgets import Input

from textual_autocomplete import AutoComplete

LANGUAGES = [
    "Python",
    "JavaScript",
    "TypeScript",
    "Java",
    "C++",
    "Ruby",
    "Go",
    "Rust",
]


class AutoCompleteExample(App[None]):
    def compose(self) -> ComposeResult:
        with Container(id="container"):
            text_input = Input(placeholder="Search for a programming language...")
            yield text_input

            yield AutoComplete(
                target=text_input,  # The widget to attach autocomplete to
                candidates=LANGUAGES,  # The list of completion candidates
            )


if __name__ == "__main__":
    app = AutoCompleteExample()
    app.run()