Session tabs: one line naming every open session, with what it is doing.
Each tab is a session screen in its own Textual mode (its own agent process and
dialogs); the app keeps them (see :class:~acptui.ui.app.AcpTui). The bar is shown
in every session screen (tabs setting: always, when there are several, never).
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
|
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(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))
|
What a tab shows.
Source code in src/acptui/ui/widgets/tabs.py
| @dataclass(frozen=True)
class TabInfo:
"""What a tab shows."""
tab_id: str
label: str
state: TabState
active: bool
|
tab_content
tab_content(index: int, tab: TabInfo) -> Content
One tab: its number, state icon and label.
Source code in src/acptui/ui/widgets/tabs.py
| def tab_content(index: int, tab: TabInfo) -> Content:
"""One tab: its number, state icon and label."""
icon, style = ICONS[tab.state]
label = tab.label if len(tab.label) <= MAX_LABEL else tab.label[: MAX_LABEL - 1] + "…"
content = Content.assemble(f" {index} ", (icon, style), " ", label, " ")
return content.stylize("reverse bold" if tab.active else "$text-muted")
|