Renaming App.search to App.search_commands

This commit is contained in:
Darren Burns
2024-11-14 13:57:31 +00:00
parent 6978f80cc3
commit d6ef1c08ab
5 changed files with 166 additions and 8 deletions

View File

@@ -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__,

View File

@@ -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.

View File

@@ -0,0 +1,157 @@
<svg class="rich-terminal" viewBox="0 0 994 635.5999999999999" xmlns="http://www.w3.org/2000/svg">
<!-- Generated with Rich https://www.textualize.io -->
<style>
@font-face {
font-family: "Fira Code";
src: local("FiraCode-Regular"),
url("https://cdnjs.cloudflare.com/ajax/libs/firacode/6.2.0/woff2/FiraCode-Regular.woff2") format("woff2"),
url("https://cdnjs.cloudflare.com/ajax/libs/firacode/6.2.0/woff/FiraCode-Regular.woff") format("woff");
font-style: normal;
font-weight: 400;
}
@font-face {
font-family: "Fira Code";
src: local("FiraCode-Bold"),
url("https://cdnjs.cloudflare.com/ajax/libs/firacode/6.2.0/woff2/FiraCode-Bold.woff2") format("woff2"),
url("https://cdnjs.cloudflare.com/ajax/libs/firacode/6.2.0/woff/FiraCode-Bold.woff") format("woff");
font-style: bold;
font-weight: 700;
}
.terminal-4097857637-matrix {
font-family: Fira Code, monospace;
font-size: 20px;
line-height: 24.4px;
font-variant-east-asian: full-width;
}
.terminal-4097857637-title {
font-size: 18px;
font-weight: bold;
font-family: arial;
}
.terminal-4097857637-r1 { fill: #646464 }
.terminal-4097857637-r2 { fill: #c5c8c6 }
.terminal-4097857637-r3 { fill: #0178d4 }
.terminal-4097857637-r4 { fill: #e0e0e0 }
.terminal-4097857637-r5 { fill: #00ff00 }
.terminal-4097857637-r6 { fill: #000000 }
.terminal-4097857637-r7 { fill: #121212 }
.terminal-4097857637-r8 { fill: #e0e0e0;font-weight: bold }
.terminal-4097857637-r9 { fill: #e0e0e0;font-weight: bold;text-decoration: underline; }
</style>
<defs>
<clipPath id="terminal-4097857637-clip-terminal">
<rect x="0" y="0" width="975.0" height="584.5999999999999" />
</clipPath>
<clipPath id="terminal-4097857637-line-0">
<rect x="0" y="1.5" width="976" height="24.65"/>
</clipPath>
<clipPath id="terminal-4097857637-line-1">
<rect x="0" y="25.9" width="976" height="24.65"/>
</clipPath>
<clipPath id="terminal-4097857637-line-2">
<rect x="0" y="50.3" width="976" height="24.65"/>
</clipPath>
<clipPath id="terminal-4097857637-line-3">
<rect x="0" y="74.7" width="976" height="24.65"/>
</clipPath>
<clipPath id="terminal-4097857637-line-4">
<rect x="0" y="99.1" width="976" height="24.65"/>
</clipPath>
<clipPath id="terminal-4097857637-line-5">
<rect x="0" y="123.5" width="976" height="24.65"/>
</clipPath>
<clipPath id="terminal-4097857637-line-6">
<rect x="0" y="147.9" width="976" height="24.65"/>
</clipPath>
<clipPath id="terminal-4097857637-line-7">
<rect x="0" y="172.3" width="976" height="24.65"/>
</clipPath>
<clipPath id="terminal-4097857637-line-8">
<rect x="0" y="196.7" width="976" height="24.65"/>
</clipPath>
<clipPath id="terminal-4097857637-line-9">
<rect x="0" y="221.1" width="976" height="24.65"/>
</clipPath>
<clipPath id="terminal-4097857637-line-10">
<rect x="0" y="245.5" width="976" height="24.65"/>
</clipPath>
<clipPath id="terminal-4097857637-line-11">
<rect x="0" y="269.9" width="976" height="24.65"/>
</clipPath>
<clipPath id="terminal-4097857637-line-12">
<rect x="0" y="294.3" width="976" height="24.65"/>
</clipPath>
<clipPath id="terminal-4097857637-line-13">
<rect x="0" y="318.7" width="976" height="24.65"/>
</clipPath>
<clipPath id="terminal-4097857637-line-14">
<rect x="0" y="343.1" width="976" height="24.65"/>
</clipPath>
<clipPath id="terminal-4097857637-line-15">
<rect x="0" y="367.5" width="976" height="24.65"/>
</clipPath>
<clipPath id="terminal-4097857637-line-16">
<rect x="0" y="391.9" width="976" height="24.65"/>
</clipPath>
<clipPath id="terminal-4097857637-line-17">
<rect x="0" y="416.3" width="976" height="24.65"/>
</clipPath>
<clipPath id="terminal-4097857637-line-18">
<rect x="0" y="440.7" width="976" height="24.65"/>
</clipPath>
<clipPath id="terminal-4097857637-line-19">
<rect x="0" y="465.1" width="976" height="24.65"/>
</clipPath>
<clipPath id="terminal-4097857637-line-20">
<rect x="0" y="489.5" width="976" height="24.65"/>
</clipPath>
<clipPath id="terminal-4097857637-line-21">
<rect x="0" y="513.9" width="976" height="24.65"/>
</clipPath>
<clipPath id="terminal-4097857637-line-22">
<rect x="0" y="538.3" width="976" height="24.65"/>
</clipPath>
</defs>
<rect fill="#292929" stroke="rgba(255,255,255,0.35)" stroke-width="1" x="1" y="1" width="992" height="633.6" rx="8"/><text class="terminal-4097857637-title" fill="#c5c8c6" text-anchor="middle" x="496" y="27">SearchApp</text>
<g transform="translate(26,22)">
<circle cx="0" cy="0" r="7" fill="#ff5f57"/>
<circle cx="22" cy="0" r="7" fill="#febc2e"/>
<circle cx="44" cy="0" r="7" fill="#28c840"/>
</g>
<g transform="translate(9, 41)" clip-path="url(#terminal-4097857637-clip-terminal)">
<rect fill="#121212" x="0" y="1.5" width="976" height="24.65" shape-rendering="crispEdges"/><rect fill="#121212" x="0" y="25.9" width="976" height="24.65" shape-rendering="crispEdges"/><rect fill="#121212" x="0" y="50.3" width="976" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="74.7" width="976" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="99.1" width="12.2" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="12.2" y="99.1" width="36.6" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="48.8" y="99.1" width="915" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="963.8" y="99.1" width="12.2" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="123.5" width="12.2" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="12.2" y="123.5" width="12.2" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="24.4" y="123.5" width="24.4" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="48.8" y="123.5" width="12.2" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="61" y="123.5" width="12.2" height="24.65" shape-rendering="crispEdges"/><rect fill="#e0e0e0" x="73.2" y="123.5" width="12.2" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="85.4" y="123.5" width="866.2" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="951.6" y="123.5" width="12.2" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="963.8" y="123.5" width="12.2" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="147.9" width="12.2" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="12.2" y="147.9" width="12.2" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="24.4" y="147.9" width="24.4" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="48.8" y="147.9" width="915" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="963.8" y="147.9" width="12.2" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="172.3" width="976" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="196.7" width="24.4" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="24.4" y="196.7" width="12.2" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="36.6" y="196.7" width="939.4" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="221.1" width="24.4" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="24.4" y="221.1" width="12.2" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="36.6" y="221.1" width="939.4" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="245.5" width="976" height="24.65" shape-rendering="crispEdges"/><rect fill="#121212" x="0" y="269.9" width="976" height="24.65" shape-rendering="crispEdges"/><rect fill="#121212" x="0" y="294.3" width="976" height="24.65" shape-rendering="crispEdges"/><rect fill="#121212" x="0" y="318.7" width="976" height="24.65" shape-rendering="crispEdges"/><rect fill="#121212" x="0" y="343.1" width="976" height="24.65" shape-rendering="crispEdges"/><rect fill="#121212" x="0" y="367.5" width="976" height="24.65" shape-rendering="crispEdges"/><rect fill="#121212" x="0" y="391.9" width="976" height="24.65" shape-rendering="crispEdges"/><rect fill="#121212" x="0" y="416.3" width="976" height="24.65" shape-rendering="crispEdges"/><rect fill="#121212" x="0" y="440.7" width="976" height="24.65" shape-rendering="crispEdges"/><rect fill="#121212" x="0" y="465.1" width="976" height="24.65" shape-rendering="crispEdges"/><rect fill="#121212" x="0" y="489.5" width="976" height="24.65" shape-rendering="crispEdges"/><rect fill="#121212" x="0" y="513.9" width="976" height="24.65" shape-rendering="crispEdges"/><rect fill="#121212" x="0" y="538.3" width="976" height="24.65" shape-rendering="crispEdges"/><rect fill="#121212" x="0" y="562.7" width="976" height="24.65" shape-rendering="crispEdges"/>
<g class="terminal-4097857637-matrix">
<text class="terminal-4097857637-r1" x="0" y="20" textLength="976" clip-path="url(#terminal-4097857637-line-0)">Search&#160;Commands&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;</text><text class="terminal-4097857637-r2" x="976" y="20" textLength="12.2" clip-path="url(#terminal-4097857637-line-0)">
</text><text class="terminal-4097857637-r2" x="976" y="44.4" textLength="12.2" clip-path="url(#terminal-4097857637-line-1)">
</text><text class="terminal-4097857637-r2" x="976" y="68.8" textLength="12.2" clip-path="url(#terminal-4097857637-line-2)">
</text><text class="terminal-4097857637-r3" x="0" y="93.2" textLength="976" clip-path="url(#terminal-4097857637-line-3)">▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔</text><text class="terminal-4097857637-r2" x="976" y="93.2" textLength="12.2" clip-path="url(#terminal-4097857637-line-3)">
</text><text class="terminal-4097857637-r2" x="976" y="117.6" textLength="12.2" clip-path="url(#terminal-4097857637-line-4)">
</text><text class="terminal-4097857637-r6" x="24.4" y="142" textLength="12.2" clip-path="url(#terminal-4097857637-line-5)">🔎</text><text class="terminal-4097857637-r4" x="61" y="142" textLength="12.2" clip-path="url(#terminal-4097857637-line-5)">b</text><text class="terminal-4097857637-r2" x="976" y="142" textLength="12.2" clip-path="url(#terminal-4097857637-line-5)">
</text><text class="terminal-4097857637-r2" x="976" y="166.4" textLength="12.2" clip-path="url(#terminal-4097857637-line-6)">
</text><text class="terminal-4097857637-r2" x="976" y="190.8" textLength="12.2" clip-path="url(#terminal-4097857637-line-7)">
</text><text class="terminal-4097857637-r9" x="24.4" y="215.2" textLength="12.2" clip-path="url(#terminal-4097857637-line-8)">b</text><text class="terminal-4097857637-r8" x="36.6" y="215.2" textLength="939.4" clip-path="url(#terminal-4097857637-line-8)">ar&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;</text><text class="terminal-4097857637-r2" x="976" y="215.2" textLength="12.2" clip-path="url(#terminal-4097857637-line-8)">
</text><text class="terminal-4097857637-r9" x="24.4" y="239.6" textLength="12.2" clip-path="url(#terminal-4097857637-line-9)">b</text><text class="terminal-4097857637-r8" x="36.6" y="239.6" textLength="939.4" clip-path="url(#terminal-4097857637-line-9)">az&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;</text><text class="terminal-4097857637-r2" x="976" y="239.6" textLength="12.2" clip-path="url(#terminal-4097857637-line-9)">
</text><text class="terminal-4097857637-r3" x="0" y="264" textLength="976" clip-path="url(#terminal-4097857637-line-10)">▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁</text><text class="terminal-4097857637-r2" x="976" y="264" textLength="12.2" clip-path="url(#terminal-4097857637-line-10)">
</text><text class="terminal-4097857637-r2" x="976" y="288.4" textLength="12.2" clip-path="url(#terminal-4097857637-line-11)">
</text><text class="terminal-4097857637-r2" x="976" y="312.8" textLength="12.2" clip-path="url(#terminal-4097857637-line-12)">
</text><text class="terminal-4097857637-r2" x="976" y="337.2" textLength="12.2" clip-path="url(#terminal-4097857637-line-13)">
</text><text class="terminal-4097857637-r2" x="976" y="361.6" textLength="12.2" clip-path="url(#terminal-4097857637-line-14)">
</text><text class="terminal-4097857637-r2" x="976" y="386" textLength="12.2" clip-path="url(#terminal-4097857637-line-15)">
</text><text class="terminal-4097857637-r2" x="976" y="410.4" textLength="12.2" clip-path="url(#terminal-4097857637-line-16)">
</text><text class="terminal-4097857637-r2" x="976" y="434.8" textLength="12.2" clip-path="url(#terminal-4097857637-line-17)">
</text><text class="terminal-4097857637-r2" x="976" y="459.2" textLength="12.2" clip-path="url(#terminal-4097857637-line-18)">
</text><text class="terminal-4097857637-r2" x="976" y="483.6" textLength="12.2" clip-path="url(#terminal-4097857637-line-19)">
</text><text class="terminal-4097857637-r2" x="976" y="508" textLength="12.2" clip-path="url(#terminal-4097857637-line-20)">
</text><text class="terminal-4097857637-r2" x="976" y="532.4" textLength="12.2" clip-path="url(#terminal-4097857637-line-21)">
</text><text class="terminal-4097857637-r2" x="976" y="556.8" textLength="12.2" clip-path="url(#terminal-4097857637-line-22)">
</text>
</g>
</g>
</svg>

After

Width:  |  Height:  |  Size: 15 KiB

View File

@@ -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")

View File

@@ -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")