Skip to content

StatusBar

Base classes

Name Children Inherits
Horizontal
textual.containers
An expanding container with horizontal layout and no scrollbars.

⋔ Inheritance diagram

graph TD
  107846720950112["status.StatusBar"]
  107846717381104["containers.Horizontal"]
  107846718477920["widget.Widget"]
  107846718489888["dom.DOMNode"]
  107846718374032["message_pump.MessagePump"]
  137699722799616["builtins.object"]
  107846717381104 --> 107846720950112
  107846718477920 --> 107846717381104
  107846718489888 --> 107846718477920
  107846718374032 --> 107846718489888
  137699722799616 --> 107846718374032

🛈 DocStrings

Bases: Horizontal

One line above the footer.

Source code in src/acptui/ui/widgets/status.py
class StatusBar(Horizontal):
    """One line above the footer."""

    DEFAULT_CSS = """
    StatusBar {
        height: 1;
        background: $panel;
        padding: 0 1;
        #status-left { width: 1fr; text-wrap: nowrap; text-overflow: ellipsis; }
        #status-right { width: auto; text-wrap: nowrap; }
    }
    """

    def __init__(self) -> None:
        super().__init__()
        self.agent = ""
        self.connection_state = "starting"
        self.state: SessionState | None = None
        self.account = ""
        """The agent's active account (from ``auth/status``), if known."""
        self._frame = 0

    def compose(self) -> ComposeResult:
        yield Static(id="status-left")
        yield Static(id="status-right")

    def on_mount(self) -> None:
        self.set_interval(0.1, self._tick)
        self.refresh_status()

    def _tick(self) -> None:
        if self.state is not None and self.state.running:
            self._frame = (self._frame + 1) % len(SPINNER)
            self.refresh_status()

    def refresh_status(self) -> None:
        """Redraw from the current state."""
        left: list[Content | tuple[str, str] | str] = []
        state = self.state
        match self.connection_state:
            case "connected" if state is not None and state.running:
                label = "waiting for you" if state.activity == "requires_action" else "working"
                left.append((f"{SPINNER[self._frame]} {label}  ", "$text-accent"))
            case "connected":
                left.append(("● ", "$text-success"))
            case "starting":
                left.append(("◌ starting  ", "$text-warning"))
            case _:
                left.append(("✘ disconnected  ", "$text-error"))
        left.append((self.agent, "bold"))
        if state is not None and state.title:
            left.append(("  " + state.title, "$text-muted"))
        self.query_one("#status-left", Static).update(Content.assemble(*left))
        self.query_one("#status-right", Static).update(self._right())

    def _right(self) -> Content:
        state = self.state
        if state is None:
            return Content("")
        from acptui.ui.screens.dialogs import option_value_label

        parts: list[Content] = []
        if self.account:
            parts.append(Content(self.account).stylize("$text-muted"))
        if state.background:
            parts.append(Content(f"⚙ {len(state.background)} bg").stylize("$text-accent"))
        for option in state.config_options:
            category = option.category if is_set(option.category) else None
            if category in {"mode", "model"}:
                parts.append(
                    Content.assemble(
                        (f"{option.name}: ", "$text-muted"), option_value_label(option)
                    )
                )
        if (usage := state.usage) is not None and usage.size:
            used = f"{human_tokens(usage.used)}/{human_tokens(usage.size)}"
            style = (
                "$text-error"
                if usage.fraction > CONTEXT_CRITICAL
                else "$text-warning"
                if usage.fraction > CONTEXT_WARNING
                else ""
            )
            parts.append(Content.assemble(("ctx ", "$text-muted"), (used, style)))
            if usage.cost is not None:
                parts.append(Content(f"{usage.cost.amount:.2f} {usage.cost.currency}"))
        if (turn := state.last_turn_usage) is not None:
            parts.append(
                Content(f"turn {human_tokens(turn.total_tokens)} tok").stylize("$text-muted")
            )
        return Content("  ").join(parts)

account instance-attribute

account = ''

The agent's active account (from auth/status), if known.

refresh_status

refresh_status() -> None

Redraw from the current state.

Source code in src/acptui/ui/widgets/status.py
def refresh_status(self) -> None:
    """Redraw from the current state."""
    left: list[Content | tuple[str, str] | str] = []
    state = self.state
    match self.connection_state:
        case "connected" if state is not None and state.running:
            label = "waiting for you" if state.activity == "requires_action" else "working"
            left.append((f"{SPINNER[self._frame]} {label}  ", "$text-accent"))
        case "connected":
            left.append(("● ", "$text-success"))
        case "starting":
            left.append(("◌ starting  ", "$text-warning"))
        case _:
            left.append(("✘ disconnected  ", "$text-error"))
    left.append((self.agent, "bold"))
    if state is not None and state.title:
        left.append(("  " + state.title, "$text-muted"))
    self.query_one("#status-left", Static).update(Content.assemble(*left))
    self.query_one("#status-right", Static).update(self._right())

:fa-brands-github: Show source on GitHub