diff --git a/meshterm/ui/rooms.py b/meshterm/ui/rooms.py index b721d93..2fb60d7 100644 --- a/meshterm/ui/rooms.py +++ b/meshterm/ui/rooms.py @@ -230,14 +230,19 @@ def _title(ctx: AppContext, room: Contact) -> str: async def _log_in(ctx: AppContext, room: Contact, password: str, *, flood: bool) -> RoomLogin: - """Send one login under a modal card that says how it went out and counts the wait.""" + """Send one login under a modal card that says how it went out and counts the wait. + + Two lines, by design: which room on the first, and how the login went out with the + seconds it has been waiting on the second — so a long name never pushes the count off + the end of the box, and the count ticks in the same place every second. + """ if flood or room.route_hops is None: how = "by flood" elif room.route_hops: how = f"along its {len(room.route_hops)}-hop route" else: how = "directly" - caption = f"logging in to {room.name} {how}…" + caption = f"logging in to {room.name}\n{how}…" started = time.monotonic() async with ctx.ui.busy_dialog(caption, title="Rooms") as busy: diff --git a/meshterm/ui/tui/screen.py b/meshterm/ui/tui/screen.py index 26d31e6..cc4a016 100644 --- a/meshterm/ui/tui/screen.py +++ b/meshterm/ui/tui/screen.py @@ -22,7 +22,7 @@ from rich.cells import cell_len from rich.console import RenderableType from rich.text import Text -from .render import render_lines +from .render import render_hanging, render_lines from .spinner import Spinner #: Sentinel a screen resolves with when the user presses Esc to cancel, distinct from a @@ -920,11 +920,22 @@ class BusyScreen(Screen): self._spinner.tick() def render_body(self, width: int) -> list[str]: - """Render the current spinner frame followed by the message.""" - line = self._spinner.text() - line.append(" ") - line.append(self._message) - return render_lines(line, width) + """Render the current spinner frame followed by the message, its lines hanging. + + A caption may carry line feeds — what it is doing on one line, how far along on the + next — and every line after the first, like any line too long for the box, hangs + under the caption's text rather than under the spinner: the wrapped-row rule every + labelled block follows. Left to wrap on its own, a caption that ends in a running + count dropped the count's last letter alone onto a line at column zero. + """ + first, *more = self._message.split("\n") + prefix = self._spinner.text() + prefix.append(" ") + indent = prefix.cell_len + lines = render_hanging(prefix, Text(first), width, indent=indent) + for line in more: + lines += render_hanging(Text(" " * indent), Text(line), width, indent=indent) + return lines def handle(self, action: str, data: str = "") -> None: """Swallow all keys: the splash dismisses itself when the task finishes.""" @@ -962,11 +973,12 @@ class BusyDialog(BusyScreen): the width ratchets, so a caption that grows mid-batch never makes the box shrink back and jitter. """ - return cell_len(self._message) + 8 # spinner, its two spaces, and the padded border + widest = max(cell_len(line) for line in self._message.split("\n")) + return widest + 8 # spinner, its two spaces, and the padded border @property def message(self) -> str: - """The caption beside the spinner.""" + """The caption beside the spinner; a line feed starts a line hung under its text.""" return self._message @message.setter diff --git a/tests/test_gallery.py b/tests/test_gallery.py index b62db46..3c3566a 100644 --- a/tests/test_gallery.py +++ b/tests/test_gallery.py @@ -627,6 +627,15 @@ def _rooms_page(cols: int, rows: int) -> Screen: return SelectScreen(title, items, footer_hint=_PAGE_HINT) +def _room_login_card(cols: int, rows: int) -> Screen: + """The join's busy card at its widest: a long room name, a long route, a long wait.""" + from meshterm.ui.tui.screen import BusyDialog + + return BusyDialog( + "logging in to YJN-ROOM-OBS St-Jean\nalong its 6-hop route… 137 s", title="Rooms" + ) + + def _room_page(cols: int, rows: int) -> Screen: """A joined room's page: its vital signs over its actions, the badge on Open the board.""" from meshterm.ui.rooms import _detail_items, _summary @@ -1645,6 +1654,7 @@ _ENTRIES: list[_Entry] = [ _Entry("room_retry", _room_retry), _Entry("rooms_page", _rooms_page), _Entry("room_page", _room_page), + _Entry("room_login_card", _room_login_card), _Entry("channels_manager", _channels_manager), _Entry("channel_detail", _channel_detail), _Entry("channel_detail_scoped", _channel_detail_scoped), diff --git a/tests/test_tui.py b/tests/test_tui.py index 6ad687a..f032ae4 100644 --- a/tests/test_tui.py +++ b/tests/test_tui.py @@ -2283,6 +2283,26 @@ def test_device_picker_quit_row_returns_none(tmp_path) -> None: # --- busy splash -------------------------------------------------------------- +def test_a_busy_caption_hangs_its_lines_under_its_text() -> None: + """A line feed starts a line under the caption; so does a line too long for the box. + + The reported card: a long room name pushed the count's last letter alone onto a line at + column zero. Broken on purpose instead, the second line starts under the first one's + text, and the card is only as wide as its widest line. + """ + from rich.text import Text as RichText + + from meshterm.ui.tui.screen import BusyDialog + + card = BusyDialog("logging in to YJN-ROOM-OBS St-Jean\nalong its 6-hop route… 37 s") + lines = RichText.from_ansi("\n".join(card.render_body(60))).plain.splitlines() + assert lines[0][3:] == "logging in to YJN-ROOM-OBS St-Jean" + assert lines[1] == " along its 6-hop route… 37 s" + assert card.dialog_width == len("logging in to YJN-ROOM-OBS St-Jean") + 8 + narrow = RichText.from_ansi("\n".join(card.render_body(24))).plain.splitlines() + assert all(line.startswith(" ") for line in narrow[1:]), narrow + + def test_busy_screen_spins_over_its_message() -> None: """The busy splash shows an ASCII spinner beside its message and advances on tick.""" from rich.text import Text as RichText