Skip to content

ShellView

Base classes

Name Children Inherits
TerminalView
acptui.ui.widgets.terminal
Command, live output and exit status of a terminal.

⋔ Inheritance diagram

graph TD
  2285288840["terminal.ShellView"]
  1493154384["terminal.TerminalView"]
  723859837["containers.Vertical"]
  4188532303["widget.Widget"]
  3946681048["dom.DOMNode"]
  53685856["message_pump.MessagePump"]
  2751680898["builtins.object"]
  1493154384 --> 2285288840
  723859837 --> 1493154384
  4188532303 --> 723859837
  3946681048 --> 4188532303
  53685856 --> 3946681048
  2751680898 --> 53685856

🛈 DocStrings

Bases: TerminalView

A command the user ran in shell mode: like an agent terminal, plus where it ran.

Source code in src/acptui/ui/widgets/terminal.py
class ShellView(TerminalView):
    """A command the user ran in shell mode: like an agent terminal, plus where it ran."""

    DEFAULT_CSS = """
    ShellView { border-left: outer $warning; }
    """

    class InterruptRequested(Message):
        """The user asked to interrupt the command."""

        def __init__(self, entry: ShellEntry) -> None:
            super().__init__()
            self.entry = entry

    def __init__(self, entry: ShellEntry, session_cwd: str) -> None:
        self.entry = entry
        self.session_cwd = session_cwd
        Vertical.__init__(self, classes="shell-command")
        self._dirty = False

    @property
    def command(self) -> ShellCommand:
        """The command shown."""
        return self.entry.command

    def _output(self) -> bytes:
        return self.command.display_output

    def _header(self) -> Content:
        command = self.command
        prompt = Content.assemble(("! ", "bold $warning"), (command.command, "bold"))
        if command.cwd != self.session_cwd:
            prompt = Content.assemble(
                prompt, ("  in ", "$text-muted"), (command.cwd, "$text-muted")
            )
        code = command.exit_code
        if code is None:
            badge = pill("running", "$accent-muted", "$text-accent")
        elif code == 0:
            badge = pill("exit 0", "$success-muted", "$text-success")
        else:
            badge = pill(f"exit {code}", "$error-muted", "$text-error")
        return Content.assemble(prompt, "  ", badge)

    def _sync_cancel(self) -> None:
        button = self.query_one("#terminal-cancel", Button)
        button.label = "interrupt"
        button.display = not self.command.done

    def refresh_entry(self) -> None:
        """Redraw after new output (at most every :data:`REFRESH_INTERVAL`)."""
        self.refresh_terminal()

    def on_button_pressed(self, event: Button.Pressed) -> None:
        event.stop()
        self.post_message(self.InterruptRequested(self.entry))

command property

command: ShellCommand

The command shown.

InterruptRequested

Bases: Message

The user asked to interrupt the command.

Source code in src/acptui/ui/widgets/terminal.py
class InterruptRequested(Message):
    """The user asked to interrupt the command."""

    def __init__(self, entry: ShellEntry) -> None:
        super().__init__()
        self.entry = entry

refresh_entry

refresh_entry() -> None

Redraw after new output (at most every :data:REFRESH_INTERVAL).

Source code in src/acptui/ui/widgets/terminal.py
def refresh_entry(self) -> None:
    """Redraw after new output (at most every :data:`REFRESH_INTERVAL`)."""
    self.refresh_terminal()

:fa-brands-github: Show source on GitHub