Skip to content

trading_agent.terminal.widgets.diff_view

A unified diff with added lines in green, removed lines in red and hunk headers dimmed, as the web page's DiffView.tsx shows it.

Typical usage example:

view = DiffView() view.show(proposal['difference'])

DiffView

DiffView(**options)

Bases: Static

A coloured unified diff.

Creates an empty view.

Parameters:

Name Type Description Default
**options str

Textual's id and classes.

{}
Source code in src/trading_agent/terminal/widgets/diff_view.py
def __init__(self, **options: str):
    """Creates an empty view.

    Args:
        **options (str): Textual's id and classes.
    """
    super().__init__('', **options)

show

show(difference)

Draws a diff.

Parameters:

Name Type Description Default
difference str

The unified diff text.

required
Source code in src/trading_agent/terminal/widgets/diff_view.py
def show(self, difference: str) -> None:
    """Draws a diff.

    Args:
        difference (str): The unified diff text.
    """
    lines = []
    for line in difference.splitlines():
        if line.startswith(_FILE_MARKERS):
            lines.append(Content.from_markup('[b]$line[/b]', line=line))
        elif line.startswith('@@'):
            lines.append(
                Content.from_markup('[$secondary]$line[/]', line=line)
            )
        elif line.startswith('+'):
            lines.append(
                Content.from_markup('[$success]$line[/]', line=line)
            )
        elif line.startswith('-'):
            lines.append(Content.from_markup('[$error]$line[/]', line=line))
        else:
            lines.append(Content(line))
    self.update(Content('\n').join(lines))