Skip to content

SessionTabs

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
  1084802052["tabs.SessionTabs"]
  644067388["_static.Static"]
  4188532303["widget.Widget"]
  3946681048["dom.DOMNode"]
  53685856["message_pump.MessagePump"]
  2751680898["builtins.object"]
  644067388 --> 1084802052
  4188532303 --> 644067388
  3946681048 --> 4188532303
  53685856 --> 3946681048
  2751680898 --> 53685856

🛈 DocStrings

Bases: Static

The tab bar; a click on a tab switches to it.

Source code in src/acptui/ui/widgets/tabs.py
class SessionTabs(Static):
    """The tab bar; a click on a tab switches to it."""

    DEFAULT_CSS = """
    SessionTabs {
        height: 1;
        background: $panel;
        text-wrap: nowrap;
        text-overflow: ellipsis;
        display: none;
        &.-visible { display: block; }
    }
    """

    class Switch(Message):
        """The user clicked a tab."""

        def __init__(self, tab_id: str) -> None:
            super().__init__()
            self.tab_id = tab_id

    def __init__(self) -> None:
        super().__init__(id="session-tabs")
        self.tabs: list[TabInfo] = []
        self._spans: list[tuple[int, int, str]] = []
        """``(start, end, tab_id)`` cell ranges of the tabs, for clicks."""

    def show_tabs(self, tabs: list[TabInfo], *, visible: bool) -> None:
        """Show these tabs (or hide the bar)."""
        self.set_class(visible, "-visible")
        if tabs == self.tabs:
            return
        self.tabs = tabs
        parts: list[Content] = []
        self._spans = []
        offset = 0
        for index, tab in enumerate(tabs, start=1):
            part = tab_content(index, tab)
            self._spans.append((offset, offset + part.cell_length, tab.tab_id))
            offset += part.cell_length + 1
            parts.append(part)
        self.update(Content(" ").join(parts))

    def on_click(self, event: Click) -> None:
        for start, end, tab_id in self._spans:
            if start <= event.x < end:
                event.stop()
                self.post_message(self.Switch(tab_id))
                return

Switch

Bases: Message

The user clicked a tab.

Source code in src/acptui/ui/widgets/tabs.py
class Switch(Message):
    """The user clicked a tab."""

    def __init__(self, tab_id: str) -> None:
        super().__init__()
        self.tab_id = tab_id

show_tabs

show_tabs(tabs: list[TabInfo], *, visible: bool) -> None

Show these tabs (or hide the bar).

Source code in src/acptui/ui/widgets/tabs.py
def show_tabs(self, tabs: list[TabInfo], *, visible: bool) -> None:
    """Show these tabs (or hide the bar)."""
    self.set_class(visible, "-visible")
    if tabs == self.tabs:
        return
    self.tabs = tabs
    parts: list[Content] = []
    self._spans = []
    offset = 0
    for index, tab in enumerate(tabs, start=1):
        part = tab_content(index, tab)
        self._spans.append((offset, offset + part.cell_length, tab.tab_id))
        offset += part.cell_length + 1
        parts.append(part)
    self.update(Content(" ").join(parts))

:fa-brands-github: Show source on GitHub