Skip to content

AcpTui

Base classes

Name Children Inherits
App
textual.app
The base class for Textual Applications.

⋔ Inheritance diagram

graph TD
  107846720869808["app.AcpTui"]
  107846719951456["app.App"]
  107846685555472["typing.Generic"]
  137699722799616["builtins.object"]
  107846718489888["dom.DOMNode"]
  107846718374032["message_pump.MessagePump"]
  107846719951456 --> 107846720869808
  107846685555472 --> 107846719951456
  137699722799616 --> 107846685555472
  107846718489888 --> 107846719951456
  107846718374032 --> 107846718489888
  137699722799616 --> 107846718374032

🛈 DocStrings

Bases: App[None]

acptui: a terminal UI for ACP v2 agents.

Source code in src/acptui/ui/app.py
class AcpTui(App[None]):
    """acptui: a terminal UI for ACP v2 agents."""

    TITLE = "acptui"
    COMMANDS: ClassVar = App.COMMANDS | {SessionCommands}
    BINDINGS: ClassVar = [
        Binding("ctrl+q", "quit", "Quit", priority=True),
        Binding("f12", "screenshot", "Screenshot", show=False),
    ]
    CSS = """
    Screen { background: $background; }
    """

    def __init__(
        self,
        settings: Settings,
        cwd: Path,
        spec: AgentSpec | None = None,
        *,
        resume_id: str | None = None,
        setup: SessionSetup | None = None,
    ) -> None:
        super().__init__()
        self.setup_override = setup
        self.settings = settings
        self.cwd = cwd
        self.spec = spec
        self.resume_id = resume_id
        self.agent_log = AgentLog()

    def screen_text(self) -> str:
        """The current screen as plain text (what an SVG screenshot shows, without styling)."""
        width, height = self.size
        console = Console(
            width=width,
            height=height,
            file=io.StringIO(),
            record=True,
            legacy_windows=False,
            color_system=None,
            force_terminal=True,
        )
        console.print(self.screen._compositor.render_update(full=True))
        return console.export_text(styles=False).rstrip() + "\n"

    def action_screenshot(self, filename: str | None = None, path: str | None = None) -> None:
        """Save the screen as SVG and as text (Downloads by default); copy the text.

        Extends Textual's screenshot (palette: "Screenshot", key: F12): the text version
        can go straight into an issue or to an agent.
        """
        folder = Path(path) if path else platformdirs.user_downloads_path()
        stem = Path(filename).stem if filename else f"acptui_{dt.datetime.now():%Y-%m-%d_%H-%M-%S}"
        text = self.screen_text()
        try:
            folder.mkdir(parents=True, exist_ok=True)
            (folder / f"{stem}.svg").write_text(self.export_screenshot(), encoding="utf-8")
            (folder / f"{stem}.txt").write_text(text, encoding="utf-8")
        except OSError as exc:
            self.notify(
                f"Couldn't save the screenshot: {exc}", title="Screenshot", severity="error"
            )
            return
        self.copy_to_clipboard(text)
        self.notify(f"{folder / stem}.txt / .svg (text copied)", title="Screenshot")

    def on_mount(self) -> None:
        if self.settings.theme in self.available_themes:
            self.theme = self.settings.theme
        if self.spec is not None:
            self.push_screen(self._session_screen(self.spec))
        else:
            self.push_screen(AgentPicker(self.settings.all_agents(), str(self.cwd)))

    def _session_screen(self, spec: AgentSpec) -> SessionScreen:
        return SessionScreen(
            spec,
            self.cwd,
            self.agent_log,
            diff_mode=self.settings.diff_view,
            expand_thoughts=self.settings.expand_thoughts,
            resume_id=self.resume_id,
            setup=self.setup_override or build_setup(self.settings, spec),
        )

    def on_agent_picker_picked(self, message: AgentPicker.Picked) -> None:
        self.spec = message.spec
        self.switch_screen(self._session_screen(message.spec))

    async def action_quit(self) -> None:
        for screen in self.screen_stack:
            if isinstance(screen, SessionScreen):
                await screen.shutdown()
        self.exit()

action_screenshot

action_screenshot(filename: str | None = None, path: str | None = None) -> None

Save the screen as SVG and as text (Downloads by default); copy the text.

Extends Textual's screenshot (palette: "Screenshot", key: F12): the text version can go straight into an issue or to an agent.

Source code in src/acptui/ui/app.py
def action_screenshot(self, filename: str | None = None, path: str | None = None) -> None:
    """Save the screen as SVG and as text (Downloads by default); copy the text.

    Extends Textual's screenshot (palette: "Screenshot", key: F12): the text version
    can go straight into an issue or to an agent.
    """
    folder = Path(path) if path else platformdirs.user_downloads_path()
    stem = Path(filename).stem if filename else f"acptui_{dt.datetime.now():%Y-%m-%d_%H-%M-%S}"
    text = self.screen_text()
    try:
        folder.mkdir(parents=True, exist_ok=True)
        (folder / f"{stem}.svg").write_text(self.export_screenshot(), encoding="utf-8")
        (folder / f"{stem}.txt").write_text(text, encoding="utf-8")
    except OSError as exc:
        self.notify(
            f"Couldn't save the screenshot: {exc}", title="Screenshot", severity="error"
        )
        return
    self.copy_to_clipboard(text)
    self.notify(f"{folder / stem}.txt / .svg (text copied)", title="Screenshot")

screen_text

screen_text() -> str

The current screen as plain text (what an SVG screenshot shows, without styling).

Source code in src/acptui/ui/app.py
def screen_text(self) -> str:
    """The current screen as plain text (what an SVG screenshot shows, without styling)."""
    width, height = self.size
    console = Console(
        width=width,
        height=height,
        file=io.StringIO(),
        record=True,
        legacy_windows=False,
        color_system=None,
        force_terminal=True,
    )
    console.print(self.screen._compositor.render_update(full=True))
    return console.export_text(styles=False).rstrip() + "\n"

:fa-brands-github: Show source on GitHub