Skip to content

Commit 590681d

Browse files
committed
Renaming, fixing propagation
1 parent 97d418c commit 590681d

14 files changed

+58
-59
lines changed

README.md

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Here's the simplest possible way to add autocomplete to your Textual app:
2121
```python
2222
from textual.app import App, ComposeResult
2323
from textual.widgets import Input
24-
from textual_autocomplete import InputAutoComplete, DropdownItem
24+
from textual_autocomplete import AutoComplete, DropdownItem
2525

2626
class ColorFinder(App):
2727
def compose(self) -> ComposeResult:
@@ -30,7 +30,7 @@ class ColorFinder(App):
3030
yield text_input
3131

3232
# Add an autocomplete to the same screen, and pass in the input widget.
33-
yield InputAutoComplete(
33+
yield AutoComplete(
3434
text_input, # Target input widget
3535
candidates=["Red", "Green", "Blue", "Yellow", "Purple", "Orange"]
3636
)
@@ -59,7 +59,7 @@ These columns are display-only, and do not influence the search process.
5959
```python
6060
from textual.app import App, ComposeResult
6161
from textual.widgets import Input
62-
from textual_autocomplete import InputAutoComplete, DropdownItem
62+
from textual_autocomplete import AutoComplete, DropdownItem
6363

6464
# Create dropdown items with a left metadata column.
6565
ITEMS = [
@@ -73,7 +73,7 @@ class LanguageSearcher(App):
7373
def compose(self) -> ComposeResult:
7474
text_input = Input(placeholder="Programming language...")
7575
yield text_input
76-
yield InputAutoComplete(text_input, candidates=ITEMS)
76+
yield AutoComplete(text_input, candidates=ITEMS)
7777

7878
if __name__ == "__main__":
7979
app = LanguageSearcher()
@@ -88,7 +88,7 @@ Add rich styling to your metadata columns using [Textual markup](https://textual
8888
from textual.app import App, ComposeResult
8989
from textual.content import Content
9090
from textual.widgets import Input, Label
91-
from textual_autocomplete import InputAutoComplete, DropdownItem
91+
from textual_autocomplete import AutoComplete, DropdownItem
9292

9393
# Languages with their popularity rank
9494
LANGUAGES_WITH_RANK = [
@@ -118,7 +118,7 @@ class LanguageSearcher(App):
118118
yield Label("Start typing a programming language:")
119119
text_input = Input(placeholder="Type here...")
120120
yield text_input
121-
yield InputAutoComplete(target=text_input, candidates=CANDIDATES)
121+
yield AutoComplete(target=text_input, candidates=CANDIDATES)
122122

123123
if __name__ == "__main__":
124124
app = LanguageSearcher()
@@ -137,7 +137,7 @@ if __name__ == "__main__":
137137
The dropdown can be styled using Textual CSS:
138138

139139
```css
140-
InputAutoComplete {
140+
AutoComplete {
141141
/* Customize the dropdown */
142142
& AutoCompleteList {
143143
max-height: 6; /* The number of lines before scrollbars appear */
@@ -185,21 +185,21 @@ DropdownItem(
185185

186186
## Completing Paths
187187

188-
`textual-autocomplete` includes a `PathInputAutoComplete` widget that can be used to autocomplete filesystem paths.
188+
`textual-autocomplete` includes a `PathAutoComplete` widget that can be used to autocomplete filesystem paths.
189189

190190
```python
191191
from textual.app import App, ComposeResult
192192
from textual.containers import Container
193193
from textual.widgets import Button, Input, Label
194194

195-
from textual_autocomplete import PathInputAutoComplete
195+
from textual_autocomplete import PathAutoComplete
196196

197197
class FileSystemPathCompletions(App[None]):
198198
def compose(self) -> ComposeResult:
199199
yield Label("Choose a file!", id="label")
200200
input_widget = Input(placeholder="Enter a path...")
201201
yield input_widget
202-
yield PathInputAutoComplete(target=input_widget, path="../textual")
202+
yield PathAutoComplete(target=input_widget, path="../textual")
203203

204204

205205
if __name__ == "__main__":
@@ -211,7 +211,7 @@ Here's what that looks like in action:
211211

212212
https://github.com/user-attachments/assets/25b80e34-0a35-4962-9024-f2dab7666689
213213

214-
`PathInputAutoComplete` has a bunch of parameters that can be used to customize the behavior - check the docstring for more details. It'll also cache directory contents after reading them once - but you can clear the cache if you need to using the `clear_directory_cache` method.
214+
`PathAutoComplete` has a bunch of parameters that can be used to customize the behavior - check the docstring for more details. It'll also cache directory contents after reading them once - but you can clear the cache if you need to using the `clear_directory_cache` method.
215215

216216
## Dynamic Data with Callbacks
217217

@@ -225,15 +225,15 @@ The app below displays the length of the text in the input widget in the prefix
225225
from textual.app import App, ComposeResult
226226
from textual.widgets import Input
227227

228-
from textual_autocomplete import InputAutoComplete
228+
from textual_autocomplete import AutoComplete
229229
from textual_autocomplete._autocomplete import DropdownItem, TargetState
230230

231231

232232
class DynamicDataApp(App[None]):
233233
def compose(self) -> ComposeResult:
234234
input_widget = Input()
235235
yield input_widget
236-
yield InputAutoComplete(input_widget, candidates=self.candidates_callback)
236+
yield AutoComplete(input_widget, candidates=self.candidates_callback)
237237

238238
def candidates_callback(self, state: TargetState) -> list[DropdownItem]:
239239
left = len(state.text)
@@ -262,13 +262,13 @@ Notice the count displayed in the prefix increment and decrement based on the ch
262262

263263
## Customizing Behavior
264264

265-
If you need custom behavior, `InputAutoComplete` is can be subclassed.
265+
If you need custom behavior, `AutoComplete` is can be subclassed.
266266

267-
A good example of how to subclass and customize behavior is the `PathInputAutoComplete` widget, which is a subclass of `InputAutoComplete`.
267+
A good example of how to subclass and customize behavior is the `PathAutoComplete` widget, which is a subclass of `AutoComplete`.
268268

269269
Some methods you may want to be aware of which you can override:
270270

271-
- `get_candidates`: Return a list of `DropdownItem` objects - called each time the input changes or the cursor position changes. Note that if you're overriding this in a subclass, you'll need to make sure that the `get_candidates` parameter passed into the `InputAutoComplete` constructor is set to `None` - this tells `textual-autocomplete` to use the subclassed method instead of the default.
271+
- `get_candidates`: Return a list of `DropdownItem` objects - called each time the input changes or the cursor position changes. Note that if you're overriding this in a subclass, you'll need to make sure that the `get_candidates` parameter passed into the `AutoComplete` constructor is set to `None` - this tells `textual-autocomplete` to use the subclassed method instead of the default.
272272
- `get_search_string`: The string that will be used to filter the candidates. You may wish to only use a portion of the input text to filter the candidates rather than the entire text.
273273
- `apply_completion`: Apply the completion to the target input widget. Receives the value the user selected from the dropdown and updates the `Input` directly using it's API.
274274
- `post_completion`: Called when a completion is selected. Called immediately after `apply_completion`. The default behaviour is just to hide the completion dropdown (after performing a completion, we want to immediately hide the dropdown in the default case).

examples/basic_single_column.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from textual.app import App, ComposeResult
44
from textual.widgets import Input
55

6-
from textual_autocomplete import InputAutoComplete
6+
from textual_autocomplete import AutoComplete
77

88
LANGUAGES = [
99
"Python",
@@ -22,7 +22,7 @@ def compose(self) -> ComposeResult:
2222
text_input = Input(placeholder="Search for a programming language...")
2323
yield text_input
2424

25-
yield InputAutoComplete(
25+
yield AutoComplete(
2626
target=text_input, # The widget to attach autocomplete to
2727
candidates=LANGUAGES, # The list of completion candidates
2828
)

examples/basic_two_column.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from textual.content import Content
55
from textual.widgets import Input, Label
66

7-
from textual_autocomplete import InputAutoComplete, DropdownItem
7+
from textual_autocomplete import AutoComplete, DropdownItem
88

99
# Languages with their popularity rank
1010
LANGUAGES_WITH_RANK = [
@@ -36,7 +36,7 @@ def compose(self) -> ComposeResult:
3636
text_input = Input(placeholder="Type here...")
3737
yield text_input
3838

39-
yield InputAutoComplete(
39+
yield AutoComplete(
4040
target=text_input, # The widget to attach autocomplete to
4141
candidates=CANDIDATES, # The list of completion candidates
4242
)

examples/basic_two_column_heavy_styles.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from textual.content import Content
55
from textual.widgets import Input, Label
66

7-
from textual_autocomplete import InputAutoComplete, DropdownItem
7+
from textual_autocomplete import AutoComplete, DropdownItem
88
from examples._headers import headers
99

1010
# Define a mapping of sections to colors
@@ -44,7 +44,7 @@ def compose(self) -> ComposeResult:
4444
text_input = Input(placeholder="Type here...")
4545
yield text_input
4646

47-
yield InputAutoComplete(
47+
yield AutoComplete(
4848
target=text_input, # The widget to attach autocomplete to
4949
candidates=CANDIDATES, # The list of completion candidates
5050
)

examples/dynamic_data.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from textual.app import App, ComposeResult
22
from textual.widgets import Input
33

4-
from textual_autocomplete import InputAutoComplete
4+
from textual_autocomplete import AutoComplete
55
from textual_autocomplete._autocomplete import DropdownItem, TargetState
66

77

@@ -15,7 +15,7 @@ class DynamicDataApp(App[None]):
1515
def compose(self) -> ComposeResult:
1616
input_widget = Input()
1717
yield input_widget
18-
yield InputAutoComplete(input_widget, candidates=self.get_candidates)
18+
yield AutoComplete(input_widget, candidates=self.get_candidates)
1919

2020
def get_candidates(self, state: TargetState) -> list[DropdownItem]:
2121
left = len(state.text)

examples/left_column_styling.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from textual.content import Content
33
from textual.widgets import Input
44

5-
from textual_autocomplete import InputAutoComplete, DropdownItem
5+
from textual_autocomplete import AutoComplete, DropdownItem
66

77

88
LANGUAGES = [
@@ -14,9 +14,7 @@
1414
"Golang",
1515
prefix=Content.from_markup("[$text-primary on $primary-muted] 🔷 "),
1616
),
17-
DropdownItem(
18-
"Java", prefix=Content.from_markup("[#6a2db5 on magenta 20%] ☕ ")
19-
),
17+
DropdownItem("Java", prefix=Content.from_markup("[#6a2db5 on magenta 20%] ☕ ")),
2018
DropdownItem(
2119
"Rust", prefix=Content.from_markup("[$text-accent on $accent-muted] 🦀 ")
2220
),
@@ -33,7 +31,7 @@ class LanguagesSearchApp(App[None]):
3331
def compose(self) -> ComposeResult:
3432
input_widget = Input(placeholder="Search for a programming language...")
3533
yield input_widget
36-
yield InputAutoComplete(target=input_widget, candidates=LANGUAGES)
34+
yield AutoComplete(target=input_widget, candidates=LANGUAGES)
3735

3836

3937
if __name__ == "__main__":

examples/partial_completions.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from textual.containers import Container
1414
from textual.widgets import Button, Input, Label
1515

16-
from textual_autocomplete import PathInputAutoComplete
16+
from textual_autocomplete import PathAutoComplete
1717

1818

1919
class FileSystemPathCompletions(App[None]):
@@ -35,7 +35,7 @@ def compose(self) -> ComposeResult:
3535
yield Label("Choose a file!", id="label")
3636
input_widget = Input(placeholder="Enter a path...")
3737
yield input_widget
38-
yield PathInputAutoComplete(target=input_widget, path="../textual")
38+
yield PathAutoComplete(target=input_widget, path="../textual")
3939
yield Button("Go")
4040

4141

tests/snapshots/test_cursor_tracking.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from textual.containers import Center, VerticalScroll
33
from textual.pilot import Pilot
44
from textual.widgets import Input
5-
from textual_autocomplete import InputAutoComplete
5+
from textual_autocomplete import AutoComplete
66

77

88
class CursorTracking(App[None]):
@@ -27,7 +27,7 @@ def compose(self) -> ComposeResult:
2727
with Center():
2828
yield (input := Input(placeholder="Type here..."))
2929

30-
yield InputAutoComplete(
30+
yield AutoComplete(
3131
target=input,
3232
candidates=["foo", "bar", "baz", "qux", "boop"],
3333
)

tests/snapshots/test_input.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from textual.widgets import Input
66
from textual.widgets.input import Selection
77

8-
from textual_autocomplete import InputAutoComplete, AutoCompleteList, DropdownItem
8+
from textual_autocomplete import AutoComplete, AutoCompleteList, DropdownItem
99

1010
LANGUAGES = [
1111
"Python",
@@ -28,7 +28,7 @@ class BasicInputAutocomplete(App[None]):
2828
def compose(self) -> ComposeResult:
2929
input = Input(placeholder="Type here...")
3030
yield input
31-
yield InputAutoComplete(
31+
yield AutoComplete(
3232
target=input,
3333
candidates=CANDIDATES,
3434
)
@@ -208,8 +208,8 @@ def test_multiple_autocomplete_dropdowns_on_a_single_input(snap_compare):
208208
class MultipleAutocompleteDropdowns(App[None]):
209209
def compose(self) -> ComposeResult:
210210
yield (input1 := Input(placeholder="Type here..."))
211-
yield InputAutoComplete(target=input1, candidates=LANGUAGES)
212-
yield InputAutoComplete(
211+
yield AutoComplete(target=input1, candidates=LANGUAGES)
212+
yield AutoComplete(
213213
target=input1,
214214
candidates=["foo", "bar", "java", "javas", "javassss", "jajaja"],
215215
)
@@ -229,10 +229,10 @@ class MultipleAutocompleteDropdowns(App[None]):
229229
def compose(self) -> ComposeResult:
230230
yield (input1 := Input(placeholder="Type here..."))
231231
# Setup with strings...
232-
yield InputAutoComplete(target=input1, candidates=LANGUAGES)
232+
yield AutoComplete(target=input1, candidates=LANGUAGES)
233233
yield (input2 := Input(placeholder="Also type here..."))
234234
# ...and with DropdownItems...
235-
yield InputAutoComplete(target=input2, candidates=CANDIDATES)
235+
yield AutoComplete(target=input2, candidates=CANDIDATES)
236236

237237
async def run_before(pilot: Pilot[None]) -> None:
238238
await pilot.press("tab")

tests/snapshots/test_prevent_default.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from typing import Any
44
from textual.app import App, ComposeResult
55
from textual.widgets import Button, Input
6-
from textual_autocomplete import InputAutoComplete
6+
from textual_autocomplete import AutoComplete
77

88

99
class PreventDefaultTab(App[None]):
@@ -18,7 +18,7 @@ def __init__(
1818
def compose(self) -> ComposeResult:
1919
input = Input(placeholder="Type something...")
2020
yield input
21-
yield InputAutoComplete(
21+
yield AutoComplete(
2222
input,
2323
candidates=["foo", "bar"],
2424
prevent_default_tab=self.prevent_default_tab,

tests/snapshots/test_styling.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
from textual.app import App, ComposeResult
22
from textual.pilot import Pilot
33
from textual.widgets import Input
4-
from textual_autocomplete import InputAutoComplete
4+
from textual_autocomplete import AutoComplete
55

66

77
class StyledAutocomplete(App[None]):
88
def compose(self) -> ComposeResult:
99
input = Input(placeholder="Search...")
1010
yield input
11-
yield InputAutoComplete(target=input, candidates=["foo", "bar", "baz", "qux"])
11+
yield AutoComplete(target=input, candidates=["foo", "bar", "baz", "qux"])
1212

1313

1414
def test_foreground_color_and_text_style(snap_compare):
1515
"""Background color should not be impacted by the text foreground and style."""
1616
StyledAutocomplete.CSS = """
17-
InputAutoComplete {
17+
AutoComplete {
1818
& .autocomplete--highlight-match {
1919
color: $text-accent;
2020
text-style: bold italic underline;
@@ -30,7 +30,7 @@ async def run_before(pilot: Pilot) -> None:
3030

3131
def test_background_color_and_removed_style(snap_compare):
3232
StyledAutocomplete.CSS = """
33-
InputAutoComplete {
33+
AutoComplete {
3434
& .autocomplete--highlight-match {
3535
color: $text-accent;
3636
background: $success-muted;
@@ -48,7 +48,7 @@ async def run_before(pilot: Pilot) -> None:
4848
def test_max_height_and_scrolling(snap_compare):
4949
"""We should be scrolled to qux, and the red scrollbar should reflect that."""
5050
StyledAutocomplete.CSS = """
51-
InputAutoComplete {
51+
AutoComplete {
5252
& AutoCompleteList {
5353
scrollbar-color: red;
5454
max-height: 2;
@@ -65,7 +65,7 @@ async def run_before(pilot: Pilot) -> None:
6565
def test_dropdown_styles_match_textual_theme(snap_compare):
6666
"""Dropdown styles should match the textual theme. In this test, we've swapped the theme to nord."""
6767
StyledAutocomplete.CSS = """
68-
InputAutoComplete {
68+
AutoComplete {
6969
& .autocomplete--highlight-match {
7070
color: $text-accent;
7171
}
@@ -82,7 +82,7 @@ async def run_before(pilot: Pilot) -> None:
8282
def test_cursor_color_change_and_dropdown_background_change(snap_compare):
8383
"""Checking various interactions between styles. See the test's CSS for info."""
8484
StyledAutocomplete.CSS = """
85-
InputAutoComplete {
85+
AutoComplete {
8686
8787
& AutoCompleteList {
8888
color: red;

0 commit comments

Comments
 (0)