mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
Mention the discover method in the docs
This commit is contained in:
@@ -68,7 +68,7 @@ The following example will display a blank screen initially, but if you bring up
|
||||
5. Highlights matching letters in the search.
|
||||
6. Adds our custom command provider and the default command provider.
|
||||
|
||||
There are three methods you can override in a command provider: [`startup`][textual.command.Provider.startup], [`search`][textual.command.Provider.search], and [`shutdown`][textual.command.Provider.shutdown].
|
||||
There are four methods you can override in a command provider: [`startup`][textual.command.Provider.startup], [`search`][textual.command.Provider.search], [`discover`][textual.command.Provider.discover] and [`shutdown`][textual.command.Provider.shutdown].
|
||||
All of these methods should be coroutines (`async def`). Only `search` is required, the other methods are optional.
|
||||
Let's explore those methods in detail.
|
||||
|
||||
@@ -99,6 +99,17 @@ In the example above, the callback is a lambda which calls the `open_file` metho
|
||||
This is a deliberate design decision taken to prevent a single broken `Provider` class from making the command palette unusable.
|
||||
Errors in command providers will be logged to the [console](./devtools.md).
|
||||
|
||||
### discover method
|
||||
|
||||
The [`discover`][textual.command.Provider.discover] method is responsible for providing results (or *hits*) that should be shown to the user when the command palette input is empty;
|
||||
this is to aid in command discoverability.
|
||||
|
||||
`discover` is similar to `search` but with the difference that no search value is passed to it, and it should *yield* instances of [`DiscoveryHit`][textual.command.DiscoveryHit].
|
||||
There is no matching and no match score is needed.
|
||||
The [`DiscoveryHit`][textual.command.DiscoveryHit] contains information about how the hit should be displayed, and an optional help string;
|
||||
discovery hits are sorted in ascending alphabetical order.
|
||||
It also contains a callback, which will be run if the user selects that command.
|
||||
|
||||
### shutdown method
|
||||
|
||||
The [`shutdown`][textual.command.Provider.shutdown] method is called when the command palette is closed.
|
||||
|
||||
Reference in New Issue
Block a user