Skip to content

trading_agent.terminal.page_commands

The pages and the terminal's actions in Textual's command palette (Ctrl+P).

Typical usage example:

class TerminalApplication(App): COMMANDS = App.COMMANDS | {PageCommands}

PageCommands

Bases: Provider

Offers every page, and switching desk, model and theme, in the command palette.

search async

search(query)

Finds the pages and actions that match the typed text.

Parameters:

Name Type Description Default
query str

What was typed into the palette.

required

Yields:

Type Description
Hit

One hit per matching page or action.

Source code in src/trading_agent/terminal/page_commands.py
async def search(self, query: str) -> command.Hits:
    """Finds the pages and actions that match the typed text.

    Args:
        query (str): What was typed into the palette.

    Yields:
        command.Hit: One hit per matching page or action.
    """
    matcher = self.matcher(query)
    for page in page_catalogue.PageCatalogue().pages():
        text = f'{page.title} page'
        score = matcher.match(text)
        if score > 0:
            yield command.Hit(
                score,
                matcher.highlight(text),
                partial(self.app.open_page, page.command),
                help=page.description,
            )
    for text, action, description in self._actions():
        score = matcher.match(text)
        if score > 0:
            yield command.Hit(
                score,
                matcher.highlight(text),
                action,
                help=description,
            )

discover async

discover()

Lists every page and action before anything is typed.

Yields:

Type Description
DiscoveryHit

One hit per page or action.

Source code in src/trading_agent/terminal/page_commands.py
async def discover(self) -> command.Hits:
    """Lists every page and action before anything is typed.

    Yields:
        command.DiscoveryHit: One hit per page or action.
    """
    for page in page_catalogue.PageCatalogue().pages():
        yield command.DiscoveryHit(
            f'{page.title} page',
            partial(self.app.open_page, page.command),
            help=page.description,
        )
    for text, action, description in self._actions():
        yield command.DiscoveryHit(text, action, help=description)