Rename hunt_for to search_for

Sounds a lot less dramatic but... okay, fair enough.
This commit is contained in:
Dave Pearson
2023-08-21 19:37:24 +01:00
parent 9c35c924ba
commit af4423166b
11 changed files with 22 additions and 22 deletions

View File

@@ -20,7 +20,7 @@ To add your own command source to the Textual command palette you start by
creating a class that inherits from
[`CommandSource`][textual.command_palette.CommandSource]. Your new command
source class should implement the
[`hunt_for`][textual.command_palette.CommandSource.hunt_for] method. This
[`search_for`][textual.command_palette.CommandSource.search_for] method. This
should be an `async` method which `yield`s instances of
[`CommandSourceHit`][textual.command_palette.CommandSourceHit].
@@ -36,7 +36,7 @@ The command source might look something like this:
class PythonGlobalSource(CommandSource):
"""A command palette source for globals in an app."""
async def hunt_for(self, user_input: str) -> CommandMatches:
async def search_for(self, user_input: str) -> CommandMatches:
# Create a fuzzy matching object for the user input.
matcher = self.matcher(user_input)
# Looping throught the available globals...
@@ -69,11 +69,11 @@ class PythonGlobalSource(CommandSource):
!!! important
The command palette populates itself asynchronously, pulling matches from
all of the active sources. Your command source `hunt_for` method must be
all of the active sources. Your command source `search_for` method must be
`async`, and must not block in any way; doing so will affect the
performance of the user's experience while using the command palette.
The key point here is that the `hunt_for` method should look for matches,
The key point here is that the `search_for` method should look for matches,
given the user input, and yield up a
[`CommandSourceHit`][textual.command_palette.CommandSourceHit], which will
contain the match score (which should be between 0 and 1), a Rich renderable

View File

@@ -35,8 +35,8 @@ class SystemCommandSource(CommandSource):
Used by default in [`App.COMMAND_SOURCES`][textual.app.App.COMMAND_SOURCES].
"""
async def hunt_for(self, user_input: str) -> CommandMatches:
"""Handle a request to hunt for system commands that match the user input.
async def search_for(self, user_input: str) -> CommandMatches:
"""Handle a request to search for system commands that match the user input.
Args:
user_input: The user input to be matched.

View File

@@ -81,14 +81,14 @@ class CommandSourceHit(NamedTuple):
CommandMatches: TypeAlias = AsyncIterator[CommandSourceHit]
"""Return type for the command source match hunting method."""
"""Return type for the command source match searching method."""
class CommandSource(ABC):
"""Base class for command palette command sources.
To create a source of commands inherit from this class and implement
[`hunt_for`][textual.command_palette.CommandSource.hunt_for].
[`search_for`][textual.command_palette.CommandSource.search_for].
"""
def __init__(self, screen: Screen, match_style: Style | None = None) -> None:
@@ -138,8 +138,8 @@ class CommandSource(ABC):
)
@abstractmethod
async def hunt_for(self, user_input: str) -> CommandMatches:
"""A request to hunt for commands relevant to the given user input.
async def search_for(self, user_input: str) -> CommandMatches:
"""A request to search for commands relevant to the given user input.
Args:
user_input: The user input to be matched.
@@ -443,8 +443,8 @@ class CommandPalette(ModalScreen[CommandPaletteCallable], inherit_css=False):
async for hit in source:
await commands.put(hit)
async def _hunt_for(self, search_value: str) -> CommandMatches:
"""Hunt for a given search value amongst all of the command sources.
async def _search_for(self, search_value: str) -> CommandMatches:
"""Search for a given search value amongst all of the command sources.
Args:
search_value: The value to search for.
@@ -466,7 +466,7 @@ class CommandPalette(ModalScreen[CommandPaletteCallable], inherit_css=False):
searches = [
create_task(
self._consume(
source(self._calling_screen, match_style).hunt_for(search_value),
source(self._calling_screen, match_style).search_for(search_value),
commands,
)
)
@@ -592,7 +592,7 @@ class CommandPalette(ModalScreen[CommandPaletteCallable], inherit_css=False):
command_id = 0
worker = get_current_worker()
self._show_busy = True
async for hit in self._hunt_for(search_value):
async for hit in self._search_for(search_value):
prompt = hit.match_display
if hit.command_help:
prompt = Group(

View File

@@ -8,7 +8,7 @@ from textual.command_palette import (
class SimpleSource(CommandSource):
async def hunt_for(self, user_input: str) -> CommandMatches:
async def search_for(self, user_input: str) -> CommandMatches:
def gndn() -> None:
pass

View File

@@ -15,7 +15,7 @@ from textual.widgets import Input
class SimpleSource(CommandSource):
environment: set[tuple[App, Screen, Widget | None]] = set()
async def hunt_for(self, _: str) -> CommandMatches:
async def search_for(self, _: str) -> CommandMatches:
def gndn() -> None:
pass

View File

@@ -14,7 +14,7 @@ async def test_sources_with_no_known_screen() -> None:
class ExampleCommandSource(CommandSource):
async def hunt_for(self, _: str) -> CommandMatches:
async def search_for(self, _: str) -> CommandMatches:
def gndn() -> None:
pass

View File

@@ -8,7 +8,7 @@ from textual.command_palette import (
class SimpleSource(CommandSource):
async def hunt_for(self, user_input: str) -> CommandMatches:
async def search_for(self, user_input: str) -> CommandMatches:
def gndn() -> None:
pass

View File

@@ -9,7 +9,7 @@ from textual.command_palette import (
class SimpleSource(CommandSource):
async def hunt_for(self, user_input: str) -> CommandMatches:
async def search_for(self, user_input: str) -> CommandMatches:
def gndn() -> None:
pass

View File

@@ -11,7 +11,7 @@ class CommandPaletteApp(App[None]):
async def test_no_results() -> None:
"""Receiving no results from a hunt for a command should not be a problem."""
"""Receiving no results from a search for a command should not be a problem."""
async with CommandPaletteApp().run_test() as pilot:
assert len(pilot.app.query(CommandPalette)) == 1
results = pilot.app.screen.query_one(OptionList)

View File

@@ -11,7 +11,7 @@ from textual.widgets import Input
class SimpleSource(CommandSource):
async def hunt_for(self, _: str) -> CommandMatches:
async def search_for(self, _: str) -> CommandMatches:
def gndn(selection: int) -> None:
assert isinstance(self.app, CommandPaletteRunOnSelectApp)
self.app.selection = selection

View File

@@ -6,7 +6,7 @@ class TestSource(CommandSource):
def gndn(self) -> None:
pass
async def hunt_for(self, user_input: str) -> CommandMatches:
async def search_for(self, user_input: str) -> CommandMatches:
matcher = self.matcher(user_input)
for n in range(10):
command = f"This is a test of this code {n}"