From d6ef1c08abc31116f96fa8f6bb7d293ba305e56b Mon Sep 17 00:00:00 2001 From: Darren Burns Date: Thu, 14 Nov 2024 13:57:31 +0000 Subject: [PATCH] Renaming App.search to App.search_commands --- examples/theme_sandbox.py | 2 +- src/textual/app.py | 3 +- ...ommands_opens_and_displays_search_list.svg | 157 ++++++++++++++++++ tests/snapshot_tests/test_snapshots.py | 6 +- tests/test_app.py | 6 +- 5 files changed, 166 insertions(+), 8 deletions(-) create mode 100644 tests/snapshot_tests/__snapshots__/test_snapshots/test_app_search_commands_opens_and_displays_search_list.svg diff --git a/examples/theme_sandbox.py b/examples/theme_sandbox.py index 8dcc5012a..78d94d974 100644 --- a/examples/theme_sandbox.py +++ b/examples/theme_sandbox.py @@ -302,7 +302,7 @@ class ChangingThemeApp(App[None]): self.theme = "not-a-theme" def action_widget_search(self) -> None: - self.search( + self.search_commands( [ ( widget.__class__.__name__, diff --git a/src/textual/app.py b/src/textual/app.py index d4207d440..8050dc1b3 100644 --- a/src/textual/app.py +++ b/src/textual/app.py @@ -1662,7 +1662,7 @@ class App(Generic[ReturnType], DOMNode): name="screenshot", ) - def search( + def search_commands( self, commands: Sequence[CommandListItem], placeholder: str = "Search for commands…", @@ -1671,6 +1671,7 @@ class App(Generic[ReturnType], DOMNode): Args: commands: A list of SimpleCommand instances. + placeholder: Placeholder text for the search field. Returns: AwaitMount: An awaitable that resolves when the commands are shown. diff --git a/tests/snapshot_tests/__snapshots__/test_snapshots/test_app_search_commands_opens_and_displays_search_list.svg b/tests/snapshot_tests/__snapshots__/test_snapshots/test_app_search_commands_opens_and_displays_search_list.svg new file mode 100644 index 000000000..eb8622653 --- /dev/null +++ b/tests/snapshot_tests/__snapshots__/test_snapshots/test_app_search_commands_opens_and_displays_search_list.svg @@ -0,0 +1,157 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + SearchApp + + + + + + + + + + Search Commands                                                                  + + +▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔ + +🔎b + + +bar                                                                            +baz                                                                            +▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁ + + + + + + + + + + + + + + + + diff --git a/tests/snapshot_tests/test_snapshots.py b/tests/snapshot_tests/test_snapshots.py index 41f477874..81803b4f0 100644 --- a/tests/snapshot_tests/test_snapshots.py +++ b/tests/snapshot_tests/test_snapshots.py @@ -2511,8 +2511,8 @@ def test_custom_theme_with_variables(snap_compare): assert snap_compare(ThemeApp()) -def test_app_search_opens_and_displays_search_list(snap_compare): - """Test the App.search method for displaying a list of commands.""" +def test_app_search_commands_opens_and_displays_search_list(snap_compare): + """Test the App.search_commands method for displaying a list of commands.""" class SearchApp(App[None]): def compose(self) -> ComposeResult: @@ -2523,7 +2523,7 @@ def test_app_search_opens_and_displays_search_list(snap_compare): """Dummy no-op callback.""" commands = [("foo", callback), ("bar", callback), ("baz", callback)] - await self.search(commands) + await self.search_commands(commands) async def run_before(pilot: Pilot) -> None: await pilot.press("b") diff --git a/tests/test_app.py b/tests/test_app.py index c6afc60f8..f61042899 100644 --- a/tests/test_app.py +++ b/tests/test_app.py @@ -195,7 +195,7 @@ async def test_search_with_simple_commands(): SimpleCommand("Another Command", callback, "Another test command"), ] async with app.run_test() as pilot: - await app.search(commands) + await app.search_commands(commands) await pilot.press("enter", "enter") assert called @@ -216,7 +216,7 @@ async def test_search_with_tuples(): ("Another Command", callback), ] async with app.run_test() as pilot: - await app.search(commands) + await app.search_commands(commands) await pilot.press("enter", "enter") assert called @@ -225,5 +225,5 @@ async def test_search_with_empty_list(): """Test search with an empty command list doesn't crash.""" app = App[None]() async with app.run_test() as pilot: - await app.search([]) + await app.search_commands([]) await pilot.press("escape")