Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/toad/client/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,8 @@ def agent_processes(self) -> AgentProcesses:
def sidebar_layout(self) -> SidebarLayout:
"""The one placement owner of this terminal's sidebars, kept in the settings file
with every other setting, so an arrangement outlives the run in every frontend."""
return SidebarLayout(self.saved_settings, TerminalOrigin.of())
return SidebarLayout(self.saved_settings, TerminalOrigin.of(),
alone=lambda: self.selected_mode == WELCOME)

def keep_settings(self) -> None:
"""A change meant for the next start (a sidebar moved, resized, folded) reaches the
Expand Down
22 changes: 12 additions & 10 deletions src/toad/client/application_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,10 +261,8 @@ class NewSessionAction(ApplicationAction):
"""Start this launch's session: its attached agent's, or a native thread."""

# The docstring is the text every menu and palette shows the reader. Both frontends fire
# this (Textual's `StartSessionButton` and Qt's Welcome `NewSessionButton`): the body
# lives on the ClientApplication so one owner answers the "new session" intent
# regardless of toolkit. The Textual welcome screen still binds its `n` key through its
# own `WelcomeStartSession` action, which forwards here.
# it from the comms sidebar's New Session row while no tab is shown
# (`NewSessionControl.action`), and Textual's `n` key there (`SoleNewSessionAction`).
show = True

async def apply(self, app: ClientApplication) -> None:
Expand Down Expand Up @@ -380,13 +378,17 @@ async def apply(self, app: ClientApplication) -> None:


class NewSessionControl:
"""A control that starts a session: what it says and the action a press applies.
Textual's `NewSessionButton` (the Channels sidebar's row) and `StartSessionButton` (the
welcome's), Qt's `NewSessionRow` and `QtStartSessionButton` all inherit it. The sidebar's
starts a thread in the selected project; the welcome's starts this launch's session."""
"""The comms sidebar's first row, which starts a session: what it says and the action a
press applies. Textual's `NewSessionButton` and Qt's `NewSessionRow` inherit it. While no
tab is shown the sidebar holds the window where the welcome page stood, and the row starts
this launch's session as the welcome's button did (`NewSessionAction`: the attached agent's,
or a native thread); beside a tab it starts a thread in the selected project."""

label = "+ New Session"
action: type[ApplicationAction] = NewThreadAction

@staticmethod
def action(app: ClientApplication) -> ApplicationAction:
return NewSessionAction() if app.sidebar_layout.alone else NewThreadAction()

async def start_session(self, app: ClientApplication) -> None:
await self.action().apply(app)
await self.action(app).apply(app)
11 changes: 10 additions & 1 deletion src/toad/client/block_menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from toad.client.input_modality import InputModality, KeyboardInput
from toad.client.menu_entry import MenuEntry, strip_menu_markup
from toad.keymap import KeymapCatalog
from toad.menus import MenuCommand
from toad.menus import MenuCommand, standard_commands

if TYPE_CHECKING:
from toad.preferences import ToadSettings
Expand All @@ -28,6 +28,15 @@ class BlockMenu:

input_modality: ClassVar[type[InputModality]] = KeyboardInput

@staticmethod
def block_commands(target: object, offered: Iterable[MenuCommand]) -> tuple[MenuCommand, ...]:
"""A block's menu, declared once for both frontends: the family's commands that
apply to ``target`` (a Textual block cursor, a Qt history fragment; each answers
`allow_maximize`), then the block's own (``offered``: its `block_menu`). Textual's
`Menu` and Qt's `QtMenu` only draw it; a frontend that assembled its own list fails
`tests/model/test_menu_owners.py`."""
return (*standard_commands(target), *offered)

@staticmethod
def ordered(commands: Iterable[MenuCommand]) -> tuple[MenuCommand, ...]:
"""Commands with default keys first, each group in the order given."""
Expand Down
3 changes: 3 additions & 0 deletions src/toad/client/bus_selection.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,9 @@ class BusListing:
A plain parent: each frontend's widget brings its toolkit metaclass.
"""

buses_title = "Buses"
"""The title over the rows, wherever a listing draws one."""

def picker_host(self) -> BusPickerHost:
"""The application this listing opens buses in."""
raise NotImplementedError
Expand Down
27 changes: 26 additions & 1 deletion src/toad/client/bus_submission.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,10 @@ async def send(self) -> None: ...
def delivering(self) -> tuple[str, ...]:
"""The text this request still shows as submitting, or nothing once its destination has it."""

def previewed(self) -> tuple[str, ...]:
"""The text the delivery preview lists for this request: what is still submitting."""
return self.delivering()

def settle(self) -> None:
"""A drawn message retires the requests it satisfies; an agent prompt is retired by its RPC."""

Expand All @@ -198,6 +202,11 @@ class SubmittingPhase(ABC):
@abstractmethod
def submitting(self, text: str) -> tuple[str, ...]: ...

def previewed(self, text: str) -> tuple[str, ...]:
"""What the delivery preview lists for this submission: what is still submitting.
A phase whose message is neither submitting nor drawn yet keeps it listed."""
return self.submitting(text)


class BusOutcome(SubmittingPhase):
"""Where a bus send stands: only a sent message can be drawn by its view."""
Expand Down Expand Up @@ -234,6 +243,13 @@ class SentMessage(DeliveryOutcome):
def drawn_by(self, view: SubmissionView) -> bool:
return view.draws_user_message(self.reference)

def previewed(self, text: str) -> tuple[str, ...]:
"""Core has it and the history has not drawn it yet: the preview keeps it until the
execution settles on the draw, so a sent message is on screen at every instant (it
dropped out on Core's answer and showed nowhere until the history drew it — Tristan,
2026-11-18: "there's a gap where I don't see the queue and I don't see the message")."""
return (text,)

async def settle_into(self, execution: BusSubmissionExecution) -> None:
execution.outcome = self
execution.owner.publish_pending()
Expand Down Expand Up @@ -268,6 +284,9 @@ def delivering(self) -> tuple[str, ...]:
destination is still shown, which is a different question."""
return self.outcome.submitting(self.submission.text) if self.current else ()

def previewed(self) -> tuple[str, ...]:
return self.outcome.previewed(self.submission.text) if self.current else ()

def retire_unsent(self) -> None:
"""A message to a view that changed before it left comes back as the draft."""
self.owner.view.delivery_refused("Message route changed; reopen this view", self.submission)
Expand Down Expand Up @@ -380,9 +399,15 @@ def start_bus(self, submission: SubmittedText, destination: BusDestination):
def delivering(self) -> tuple[str, ...]:
return tuple(text for execution in self.active for text in execution.delivering())

@property
def previewed(self) -> tuple[str, ...]:
"""What the delivery preview lists: every request until the view draws it. Send now
reads `delivering` instead, since a message Core has cannot be sent again."""
return tuple(text for execution in self.active for text in execution.previewed())

@property
def submitting(self) -> SubmittingTexts:
return SubmittingTexts(self.delivering)
return SubmittingTexts(self.previewed)

@property
def input_decision(self) -> InputDecision:
Expand Down
2 changes: 2 additions & 0 deletions src/toad/client/fragments.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,8 @@ class CursorRest:

# The messages the cursor owns while the history draws them.
rested: tuple[HistoryFragment, ...] = ()
# A drawn message is never maximized (a Textual widget block may be, through its cursor).
allow_maximize: ClassVar[bool] = False

@property
def clipboard_text(self) -> str:
Expand Down
4 changes: 4 additions & 0 deletions src/toad/client/history_changes.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,8 @@ class PinsMessageHeader:
`top_page` and `live_message_header` answer."""

sticky_header: HeaderPin
histories: set
"""The pagers drawn in this window (`PagingWindow.histories`): each hears where it moved."""
arrival_burst: ArrivalBurst
_restoring: bool
pinned_scroll_y: float = 0.0
Expand All @@ -238,6 +240,8 @@ def repin_header(self) -> None:
self.pinned_scroll_y = self.scroll_y
pinned = self.top_message_header()
self.sticky_header.pin(pinned, burst.stack(self, pinned) if burst.messages else NO_STACK)
for history in tuple(self.histories):
history.window_shown()

def open_pinned(self, index: int) -> bool:
"""The reader chose the pin's `index`th header: a stacked one scrolls to its message,
Expand Down
27 changes: 25 additions & 2 deletions src/toad/client/history_pager.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,10 @@ class HistoryPager(ResumesSource):
@abstractmethod
def window(self) -> PagingWindow: ...

def window_shown(self) -> None:
"""The window's shown rows changed (a scroll offset or a committed layout); a pager
that draws no bus messages has nothing to do with that."""

@property
@abstractmethod
def can_draw_on_screen(self) -> bool: ...
Expand Down Expand Up @@ -1206,6 +1210,15 @@ def required_presentations(self, screen) -> tuple[NativePresentation, ...]:
class ConversationPager(HistoryPager):
"""A conversation's pager: it can replace its whole source with a newer reading of it."""

view: object
"""The conversation this pager draws, whose composer's submissions it settles."""

def window_shown(self) -> None:
"""The window moved or laid out: a sent message it now shows retires from the delivery
preview on this frame. The view settles after reading a change, but a following window
scrolls to the new row one layout later, and nothing settled then."""
self.view.submissions.settle()

async def show_newest(self, request: ReplacementViewportRequest, *,
arrivals: tuple[HistoryFragment, ...] = (),
publication_current: Callable[[], bool] = lambda: True) -> bool:
Expand Down Expand Up @@ -1258,7 +1271,7 @@ def publish_core(self, event: object) -> None:


class DrawsBusMessages:
"""The fragments the loaded pages draw, and whether they include a bus message, scrolled into view or not."""
"""The fragments the loaded pages draw, and whether the window shows a bus message."""

pages: deque[DrawnPage]

Expand All @@ -1267,4 +1280,14 @@ def fragments_in_range(self) -> tuple[HistoryFragment, ...]:
return tuple(fragment for page in self.pages for fragment in page.prepared.fragments_in_range)

def draws(self, reference: MessageReference) -> bool:
return any(fragment.draws(reference) for fragment in reversed(self.fragments_in_range))
"""Whether the window shows the bus message `reference` names: its first row is laid
out and starts above the window's bottom edge. A message only paged into range, or laid
out below the edge in the frame before a following window scrolls to it, is not shown
yet, so the delivery preview keeps it for that frame (it went for one frame before the
message came into view). `message_top` and `viewport_rows` are the window's unit."""
window = self.window
for fragment in reversed(self.fragments_in_range):
if fragment.draws(reference):
top = window.message_top(fragment.key)
return top is not None and top < window.scroll_y + window.viewport_rows
return False
4 changes: 2 additions & 2 deletions src/toad/client/message_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ def open(cls, composer: MessagePromptComposer) -> None: ...


class WindowFilePicker(TitledChoice, FilePicker):
"""The platform's file dialog. A phone shows its own file picker, which reaches the
phone's storage and its cloud drives."""
"""The platform's file dialog. A phone shows its own chooser: the apps that give a file
(its storage, photos and cloud drives) and the camera."""

title = "File dialog"

Expand Down
3 changes: 0 additions & 3 deletions src/toad/client/reader_position.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,6 @@ def row_of(self, item) -> int: ...
@abstractmethod
def drawn_pages(self) -> Iterator[ReaderPage]: ...

@abstractmethod
def anchor(self) -> None: ...

@abstractmethod
def release_anchor(self) -> None: ...

Expand Down
2 changes: 1 addition & 1 deletion src/toad/client/sidebar_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
two frontends disagreed by construction. This class is the single owner of the
match decision and the current text; Textual's `SideBar.search` reactive and
Qt's `QLineEdit` both write through it, and every listing (Textual's
`SidebarGroup.sync_members`, Qt's `QtChannelListing.keep` / `QtThreadListing.keep`)
`SidebarGroup.sync_members`, Qt's `Sidebar.draw_lines`)
reads through `matches` instead of comparing text itself. A new frontend never
reimplements the match rule; it hands the filter a row name and asks.

Expand Down
68 changes: 60 additions & 8 deletions src/toad/client/sidebar_lines.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,13 @@

from __future__ import annotations

from collections.abc import Callable
from typing import ClassVar

from toad.client.menu_entry import MenuEntry
from toad.client.relationship_row_menu import menu_entries_for_row
from toad.command_catalog import CommandCatalog


class DetailedLine:
"""A line of two rows: its title after its status prefix (the unread badge), then its
Expand Down Expand Up @@ -55,10 +60,10 @@ def members_toggled(self) -> None:


class WelcomeSectionLine(MemberGroupLine):
"""A welcome section: it opens as the shared sidebar state says
(`SidebarState.welcome_section_open`) and records what the reader leaves it as, so it
stays put however often the welcome is drawn again. Textual's `WelcomeSection` and Qt's
`OpenSection`."""
"""A titled section of rows that are not the sidebar model's: it opens as the shared
sidebar state says (`SidebarState.welcome_section_open`) and records what the reader
leaves it as, so it stays put however often it is drawn again. Qt's `OpenSection` (the
buses, under the sidebar's rows while it holds the window, and in the bus switcher)."""

@property
def section_title(self) -> str:
Expand All @@ -78,14 +83,14 @@ def members_toggled(self) -> None:
class SidebarStatusLine(DetailedLine):
"""The sidebar's status: an observation status (`Connecting…`, `Behind`) or why the bus
could not be read, its first line as the title and the rest as the detail under it.
Textual's `SidebarStatus`, Qt's `StatusSection` and `UnavailableSection`, and the
failed sidebar state's text all read it here."""
Textual's `SidebarStatus`, Qt's `StatusSection`, and the failed sidebar state's text all
read it here."""

key: ClassVar[str] = "__status__"

@staticmethod
def unavailable_text(error: BaseException) -> str:
"""What a sidebar or welcome says while the bus cannot be read: one persistent state,
"""What a sidebar says while the bus cannot be read: one persistent state,
the same however many reopen attempts (connection.ObservationRetry) fail behind it."""
return f"Comms unavailable; reconnecting\n{error}"

Expand All @@ -99,7 +104,13 @@ def status_rows(text: str) -> tuple[str, str]:
class TargetLine:
"""A line that opens a navigation target (a channel or a thread): it is keyed by the
target's name and opens its members as the target says by default. Textual's
`CommsRow` and Qt's `ConversationRow`."""
`CommsRow` and Qt's `ConversationRow`.

Its menu is declared here and nowhere else: `menu_entries` is what a right-click or a
held finger offers in every frontend, and each toolkit only draws the entries
(Textual's `ActionMenu.offer`, Qt's menu panel). A toolkit line that defined its own
`menu_entries`, or built a menu by calling the owners below, fails
`tests/model/test_menu_owners.py`."""

target: object

Expand All @@ -110,6 +121,47 @@ def target_name(self) -> str:
def opens_expanded(self) -> bool:
return self.target.expanded_by_default

@property
def menu_tree(self) -> LineMenuTree:
"""The tree the line is drawn in, which supplies the context its commands run in."""
raise NotImplementedError

async def menu_entries(self) -> tuple[MenuEntry, ...]:
"""The commands the line's target applies, in its tree's context."""
return await CommandCatalog.pointer_menu(self.menu_tree.row_menu_context(self))


class LineMenuTree:
"""A tree of `TargetLine`s: the context a line's commands run in, and how a Comms
relationship opens. Textual's sidebar trees and Qt's `ConversationRows` and
`QtThreadCommsPanel` answer it."""

def row_menu_context(self, line: TargetLine):
"""The command context for `line`'s target in this tree."""
raise NotImplementedError

def relationship_opener(self, line: RelationshipLine) -> Callable[[], object]:
"""What Open runs for a relationship line, captured when the menu opens."""
raise NotImplementedError

def copy_name(self, name: str) -> None:
raise NotImplementedError


class RelationshipLine(TargetLine):
"""A Comms relationship (Textual's `RelationshipRow`, Qt's `QtRelationshipItem`): its
menu is Open while the relationship is available, and Copy name."""

available: bool

async def menu_entries(self) -> tuple[MenuEntry, ...]:
tree = self.menu_tree
return menu_entries_for_row(
target_name=self.target_name,
copy=tree.copy_name,
open_callback=tree.relationship_opener(self) if self.available else None,
)


class HeaderLine:
"""A group's header line: its title, elided into the room the other stretches leave;
Expand Down
Loading
Loading