Skip to content

PlanView

Base classes

Name Children Inherits
Static
textual.widgets._static
A widget to display simple static content, or use as a base class for more complex widgets.

⋔ Inheritance diagram

graph TD
  107846720491312["blocks.PlanView"]
  107846719030608["_static.Static"]
  107846718477920["widget.Widget"]
  107846718489888["dom.DOMNode"]
  107846718374032["message_pump.MessagePump"]
  137699722799616["builtins.object"]
  107846719030608 --> 107846720491312
  107846718477920 --> 107846719030608
  107846718489888 --> 107846718477920
  107846718374032 --> 107846718489888
  137699722799616 --> 107846718374032

🛈 DocStrings

Bases: Static

The agent's plan (adapted from toad's plan widget: status icons, priority pills).

Source code in src/acptui/ui/widgets/blocks.py
class PlanView(Static):
    """The agent's plan (adapted from toad's plan widget: status icons, priority pills)."""

    DEFAULT_CSS = """
    PlanView {
        height: auto;
        border: round $secondary 60%;
        border-title-color: $secondary;
        padding: 0 1;
        margin: 0 0 1 0;
    }
    PlanView.-removed { display: none; }
    """

    PRIORITIES: ClassVar[dict[str, tuple[str, str, str]]] = {
        "high": ("H", "$error-muted", "$text-error"),
        "medium": ("M", "$warning-muted", "$text-warning"),
        "low": ("L", "$primary-muted", "$text-primary"),
    }

    def __init__(self, entry: PlanEntry) -> None:
        super().__init__()
        self.entry = entry
        self.border_title = "Plan"
        self.refresh_entry()

    def refresh_entry(self) -> None:
        """Re-render the plan."""
        from aclientp.schema.v2 import PlanItems

        self.set_class(self.entry.removed, "-removed")
        content = self.entry.content
        if not isinstance(content, PlanItems):
            path = content.path if is_set(content.path) and content.path else None
            if path:
                self.border_subtitle = path
            self.update(Content(content.content))
            return
        lines: list[Content] = []
        for item in content.entries:
            label, bg, fg = self.PRIORITIES.get(
                item.priority, (item.priority[:1].upper(), "$panel", "$text")
            )
            text_style = "$text-muted strike" if item.status in {"completed", "cancelled"} else ""
            lines.append(
                Content.assemble(
                    status_icon(item.status),
                    " ",
                    pill(label, bg, fg),
                    " ",
                    (item.content, text_style),
                )
            )
        done = sum(1 for item in content.entries if item.status == "completed")
        self.border_subtitle = f"{done}/{len(content.entries)}"
        self.update(Content("\n").join(lines) if lines else Content("(empty plan)"))

refresh_entry

refresh_entry() -> None

Re-render the plan.

Source code in src/acptui/ui/widgets/blocks.py
def refresh_entry(self) -> None:
    """Re-render the plan."""
    from aclientp.schema.v2 import PlanItems

    self.set_class(self.entry.removed, "-removed")
    content = self.entry.content
    if not isinstance(content, PlanItems):
        path = content.path if is_set(content.path) and content.path else None
        if path:
            self.border_subtitle = path
        self.update(Content(content.content))
        return
    lines: list[Content] = []
    for item in content.entries:
        label, bg, fg = self.PRIORITIES.get(
            item.priority, (item.priority[:1].upper(), "$panel", "$text")
        )
        text_style = "$text-muted strike" if item.status in {"completed", "cancelled"} else ""
        lines.append(
            Content.assemble(
                status_icon(item.status),
                " ",
                pill(label, bg, fg),
                " ",
                (item.content, text_style),
            )
        )
    done = sum(1 for item in content.entries if item.status == "completed")
    self.border_subtitle = f"{done}/{len(content.entries)}"
    self.update(Content("\n").join(lines) if lines else Content("(empty plan)"))

:fa-brands-github: Show source on GitHub