Skip to content

trading_agent.terminal.widgets.composer

The box where the user writes messages, with Claude Code's keys.

Enter sends. A ? typed into the empty box asks for the list of keys. File paths pasted by dragging files onto the terminal become attachments, Ctrl+V attaches a picture on the clipboard, and Backspace in the empty box removes the newest attachment. Shift+Enter, Alt+Enter, Ctrl+J, or a backslash typed just before Enter, starts a new line. Up on the first line and Down on the last line move through earlier prompts. While the command menu is open, Up, Down and Tab move through the menu and Enter picks from it.

Typical usage example:

composer = Composer(PromptHistory(None)) # The screen handles Composer.Submitted, MenuMoved and MenuPicked.

Composer

Composer(history, placeholder='')

Bases: TextArea

The message box.

Attributes:

Name Type Description
menu_open

Whether the command menu above the box is showing, set by the screen.

Creates the box.

Parameters:

Name Type Description Default
history PromptHistory

The earlier prompts, for Up and Down.

required
placeholder str

The hint shown while the box is empty.

''
Source code in src/trading_agent/terminal/widgets/composer.py
def __init__(
    self,
    history: prompt_history_module.PromptHistory,
    placeholder: str = '',
):
    """Creates the box.

    Args:
        history (prompt_history_module.PromptHistory): The earlier prompts, for Up and Down.
        placeholder (str): The hint shown while the box is empty.
    """
    super().__init__(
        '',
        soft_wrap=True,
        show_line_numbers=False,
        highlight_cursor_line=False,
        compact=True,
        placeholder=placeholder,
        id='composer',
    )
    self.menu_open = False
    self._history = history

Submitted

Submitted(text)

Bases: Message

The user pressed Enter to send what is in the box.

Creates the message.

Parameters:

Name Type Description Default
text str

What the box held.

required
Source code in src/trading_agent/terminal/widgets/composer.py
def __init__(self, text: str):
    """Creates the message.

    Args:
        text (str): What the box held.
    """
    super().__init__()
    self.text = text

MenuMoved

MenuMoved(step)

Bases: Message

The user moved the command menu's highlight.

Creates the message.

Parameters:

Name Type Description Default
step int

-1 for up, 1 for down.

required
Source code in src/trading_agent/terminal/widgets/composer.py
def __init__(self, step: int):
    """Creates the message.

    Args:
        step (int): -1 for up, 1 for down.
    """
    super().__init__()
    self.step = step

MenuPicked

Bases: Message

The user picked the highlighted command with Tab.

KeysWanted

Bases: Message

The user typed ? into the empty box, asking for the list of keys.

FilesDropped

FilesDropped(paths)

Bases: Message

Files were dragged onto the terminal, which pasted their paths.

Creates the message.

Parameters:

Name Type Description Default
paths list[Path]

The files.

required
Source code in src/trading_agent/terminal/widgets/composer.py
def __init__(self, paths: list[Path]):
    """Creates the message.

    Args:
        paths (list[Path]): The files.
    """
    super().__init__()
    self.paths = paths

PictureWanted

Bases: Message

The user pressed Ctrl+V, which attaches a picture on the clipboard.

EmptyBackspace

Bases: Message

The user pressed Backspace in the empty box, which removes the newest attached file.

set_text

set_text(text)

Replaces the box's text and puts the cursor at its end.

Parameters:

Name Type Description Default
text str

The new text.

required
Source code in src/trading_agent/terminal/widgets/composer.py
def set_text(self, text: str) -> None:
    """Replaces the box's text and puts the cursor at its end.

    Args:
        text (str): The new text.
    """
    self.text = text
    self.move_cursor(self.document.end)

paste_text

paste_text()

Pastes Textual's own clipboard, when Ctrl+V found no picture.

Source code in src/trading_agent/terminal/widgets/composer.py
def paste_text(self) -> None:
    """Pastes Textual's own clipboard, when Ctrl+V found no picture."""
    self.action_paste()