Skip to content

TabsScreen

Base classes

Name Children Inherits
ModalScreen
textual.screen
A screen with bindings that take precedence over the App's key bindings.

โ‹” Inheritance diagram

graph TD
  723357276["dialogs.TabsScreen"]
  1923423225["screen.ModalScreen"]
  642899982["screen.Screen"]
  3481597255["typing.Generic"]
  2751680898["builtins.object"]
  4188532303["widget.Widget"]
  3946681048["dom.DOMNode"]
  53685856["message_pump.MessagePump"]
  1923423225 --> 723357276
  642899982 --> 1923423225
  3481597255 --> 642899982
  2751680898 --> 3481597255
  4188532303 --> 642899982
  3946681048 --> 4188532303
  53685856 --> 3946681048
  2751680898 --> 53685856

๐Ÿ›ˆ DocStrings

Bases: ModalScreen[str | None]

All tabs with their state and directory; returns the tab to show.

Source code in src/acptui/ui/screens/dialogs.py
class TabsScreen(ModalScreen[str | None]):
    """All tabs with their state and directory; returns the tab to show."""

    DEFAULT_CSS = "TabsScreen {" + DIALOG_CSS + "}"
    BINDINGS: ClassVar = [Binding("escape", "dismiss_none", "Close")]

    def __init__(self, tabs: Sequence[TabInfo], directories: dict[str, str]) -> None:
        super().__init__()
        self.tabs = list(tabs)
        self.directories = directories

    def compose(self) -> ComposeResult:
        from acptui.ui.widgets.tabs import ICONS

        with Vertical(id="dialog"):
            yield Static("Sessions", id="dialog-title")
            options: list[Option] = []
            for index, tab in enumerate(self.tabs, start=1):
                icon, style = ICONS[tab.state]
                label = Content.assemble(
                    f"{index} ",
                    (icon, style),
                    " ",
                    (tab.label, "bold"),
                    (f"  {tab.state}", "$text-muted"),
                    ("  (shown)" if tab.active else "", "$text-accent"),
                    "\n    ",
                    (self.directories.get(tab.tab_id, ""), "$text-muted"),
                )
                options.append(Option(label, id=tab.tab_id))
            yield OptionList(*options, id="tabs")
            hint = "enter: show ยท escape: close" if self.tabs else "No sessions yet (ctrl+t)."
            yield Static(hint, id="dialog-hint")

    def on_mount(self) -> None:
        options = self.query_one(OptionList)
        options.focus()
        active = next((i for i, tab in enumerate(self.tabs) if tab.active), 0)
        if self.tabs:
            options.highlighted = active

    def on_option_list_option_selected(self, event: OptionList.OptionSelected) -> None:
        self.dismiss(event.option_id)

    def action_dismiss_none(self) -> None:
        """Close."""
        self.dismiss(None)

action_dismiss_none

action_dismiss_none() -> None

Close.

Source code in src/acptui/ui/screens/dialogs.py
def action_dismiss_none(self) -> None:
    """Close."""
    self.dismiss(None)

:fa-brands-github: Show source on GitHub