mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
Rename hunt_for to search_for
Sounds a lot less dramatic but... okay, fair enough.
This commit is contained in:
@@ -20,7 +20,7 @@ To add your own command source to the Textual command palette you start by
|
|||||||
creating a class that inherits from
|
creating a class that inherits from
|
||||||
[`CommandSource`][textual.command_palette.CommandSource]. Your new command
|
[`CommandSource`][textual.command_palette.CommandSource]. Your new command
|
||||||
source class should implement the
|
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
|
should be an `async` method which `yield`s instances of
|
||||||
[`CommandSourceHit`][textual.command_palette.CommandSourceHit].
|
[`CommandSourceHit`][textual.command_palette.CommandSourceHit].
|
||||||
|
|
||||||
@@ -36,7 +36,7 @@ The command source might look something like this:
|
|||||||
class PythonGlobalSource(CommandSource):
|
class PythonGlobalSource(CommandSource):
|
||||||
"""A command palette source for globals in an app."""
|
"""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.
|
# Create a fuzzy matching object for the user input.
|
||||||
matcher = self.matcher(user_input)
|
matcher = self.matcher(user_input)
|
||||||
# Looping throught the available globals...
|
# Looping throught the available globals...
|
||||||
@@ -69,11 +69,11 @@ class PythonGlobalSource(CommandSource):
|
|||||||
!!! important
|
!!! important
|
||||||
|
|
||||||
The command palette populates itself asynchronously, pulling matches from
|
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
|
`async`, and must not block in any way; doing so will affect the
|
||||||
performance of the user's experience while using the command palette.
|
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
|
given the user input, and yield up a
|
||||||
[`CommandSourceHit`][textual.command_palette.CommandSourceHit], which will
|
[`CommandSourceHit`][textual.command_palette.CommandSourceHit], which will
|
||||||
contain the match score (which should be between 0 and 1), a Rich renderable
|
contain the match score (which should be between 0 and 1), a Rich renderable
|
||||||
|
|||||||
@@ -35,8 +35,8 @@ class SystemCommandSource(CommandSource):
|
|||||||
Used by default in [`App.COMMAND_SOURCES`][textual.app.App.COMMAND_SOURCES].
|
Used by default in [`App.COMMAND_SOURCES`][textual.app.App.COMMAND_SOURCES].
|
||||||
"""
|
"""
|
||||||
|
|
||||||
async def hunt_for(self, user_input: str) -> CommandMatches:
|
async def search_for(self, user_input: str) -> CommandMatches:
|
||||||
"""Handle a request to hunt for system commands that match the user input.
|
"""Handle a request to search for system commands that match the user input.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
user_input: The user input to be matched.
|
user_input: The user input to be matched.
|
||||||
|
|||||||
@@ -81,14 +81,14 @@ class CommandSourceHit(NamedTuple):
|
|||||||
|
|
||||||
|
|
||||||
CommandMatches: TypeAlias = AsyncIterator[CommandSourceHit]
|
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):
|
class CommandSource(ABC):
|
||||||
"""Base class for command palette command sources.
|
"""Base class for command palette command sources.
|
||||||
|
|
||||||
To create a source of commands inherit from this class and implement
|
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:
|
def __init__(self, screen: Screen, match_style: Style | None = None) -> None:
|
||||||
@@ -138,8 +138,8 @@ class CommandSource(ABC):
|
|||||||
)
|
)
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
async def hunt_for(self, user_input: str) -> CommandMatches:
|
async def search_for(self, user_input: str) -> CommandMatches:
|
||||||
"""A request to hunt for commands relevant to the given user input.
|
"""A request to search for commands relevant to the given user input.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
user_input: The user input to be matched.
|
user_input: The user input to be matched.
|
||||||
@@ -443,8 +443,8 @@ class CommandPalette(ModalScreen[CommandPaletteCallable], inherit_css=False):
|
|||||||
async for hit in source:
|
async for hit in source:
|
||||||
await commands.put(hit)
|
await commands.put(hit)
|
||||||
|
|
||||||
async def _hunt_for(self, search_value: str) -> CommandMatches:
|
async def _search_for(self, search_value: str) -> CommandMatches:
|
||||||
"""Hunt for a given search value amongst all of the command sources.
|
"""Search for a given search value amongst all of the command sources.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
search_value: The value to search for.
|
search_value: The value to search for.
|
||||||
@@ -466,7 +466,7 @@ class CommandPalette(ModalScreen[CommandPaletteCallable], inherit_css=False):
|
|||||||
searches = [
|
searches = [
|
||||||
create_task(
|
create_task(
|
||||||
self._consume(
|
self._consume(
|
||||||
source(self._calling_screen, match_style).hunt_for(search_value),
|
source(self._calling_screen, match_style).search_for(search_value),
|
||||||
commands,
|
commands,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
@@ -592,7 +592,7 @@ class CommandPalette(ModalScreen[CommandPaletteCallable], inherit_css=False):
|
|||||||
command_id = 0
|
command_id = 0
|
||||||
worker = get_current_worker()
|
worker = get_current_worker()
|
||||||
self._show_busy = True
|
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
|
prompt = hit.match_display
|
||||||
if hit.command_help:
|
if hit.command_help:
|
||||||
prompt = Group(
|
prompt = Group(
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ from textual.command_palette import (
|
|||||||
|
|
||||||
|
|
||||||
class SimpleSource(CommandSource):
|
class SimpleSource(CommandSource):
|
||||||
async def hunt_for(self, user_input: str) -> CommandMatches:
|
async def search_for(self, user_input: str) -> CommandMatches:
|
||||||
def gndn() -> None:
|
def gndn() -> None:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ from textual.widgets import Input
|
|||||||
class SimpleSource(CommandSource):
|
class SimpleSource(CommandSource):
|
||||||
environment: set[tuple[App, Screen, Widget | None]] = set()
|
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:
|
def gndn() -> None:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ async def test_sources_with_no_known_screen() -> None:
|
|||||||
|
|
||||||
|
|
||||||
class ExampleCommandSource(CommandSource):
|
class ExampleCommandSource(CommandSource):
|
||||||
async def hunt_for(self, _: str) -> CommandMatches:
|
async def search_for(self, _: str) -> CommandMatches:
|
||||||
def gndn() -> None:
|
def gndn() -> None:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ from textual.command_palette import (
|
|||||||
|
|
||||||
|
|
||||||
class SimpleSource(CommandSource):
|
class SimpleSource(CommandSource):
|
||||||
async def hunt_for(self, user_input: str) -> CommandMatches:
|
async def search_for(self, user_input: str) -> CommandMatches:
|
||||||
def gndn() -> None:
|
def gndn() -> None:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ from textual.command_palette import (
|
|||||||
|
|
||||||
|
|
||||||
class SimpleSource(CommandSource):
|
class SimpleSource(CommandSource):
|
||||||
async def hunt_for(self, user_input: str) -> CommandMatches:
|
async def search_for(self, user_input: str) -> CommandMatches:
|
||||||
def gndn() -> None:
|
def gndn() -> None:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ class CommandPaletteApp(App[None]):
|
|||||||
|
|
||||||
|
|
||||||
async def test_no_results() -> 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:
|
async with CommandPaletteApp().run_test() as pilot:
|
||||||
assert len(pilot.app.query(CommandPalette)) == 1
|
assert len(pilot.app.query(CommandPalette)) == 1
|
||||||
results = pilot.app.screen.query_one(OptionList)
|
results = pilot.app.screen.query_one(OptionList)
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ from textual.widgets import Input
|
|||||||
|
|
||||||
|
|
||||||
class SimpleSource(CommandSource):
|
class SimpleSource(CommandSource):
|
||||||
async def hunt_for(self, _: str) -> CommandMatches:
|
async def search_for(self, _: str) -> CommandMatches:
|
||||||
def gndn(selection: int) -> None:
|
def gndn(selection: int) -> None:
|
||||||
assert isinstance(self.app, CommandPaletteRunOnSelectApp)
|
assert isinstance(self.app, CommandPaletteRunOnSelectApp)
|
||||||
self.app.selection = selection
|
self.app.selection = selection
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ class TestSource(CommandSource):
|
|||||||
def gndn(self) -> None:
|
def gndn(self) -> None:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
async def hunt_for(self, user_input: str) -> CommandMatches:
|
async def search_for(self, user_input: str) -> CommandMatches:
|
||||||
matcher = self.matcher(user_input)
|
matcher = self.matcher(user_input)
|
||||||
for n in range(10):
|
for n in range(10):
|
||||||
command = f"This is a test of this code {n}"
|
command = f"This is a test of this code {n}"
|
||||||
|
|||||||
Reference in New Issue
Block a user