From f3de1d1213d86824b2a10c7d1c8f365a2b50f7ff Mon Sep 17 00:00:00 2001 From: Jean-Pierre Martineau Date: Wed, 29 Jul 2026 23:07:49 -0400 Subject: [PATCH] Share popups: one layout, minted where the code is drawn MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The channel share and the contact card built the identical renderable — intro, code, URL — by hand, one copy each. share_popup in ui/qr.py is now the single spelling; callers bring their own intro and URL builder (housekeeping H-001). Co-Authored-By: Claude Fable 5 --- meshterm/ui/channels.py | 12 ++---------- meshterm/ui/config_editor.py | 16 ++++++---------- meshterm/ui/qr.py | 29 +++++++++++++++++++++++++++++ 3 files changed, 37 insertions(+), 20 deletions(-) diff --git a/meshterm/ui/channels.py b/meshterm/ui/channels.py index d09750e..348fb4d 100644 --- a/meshterm/ui/channels.py +++ b/meshterm/ui/channels.py @@ -63,7 +63,7 @@ from ..core.models import Conversation from ..persistence.repository import ACTIVITY_DRAWN_BUCKETS from .braillechart import activity_peak, activity_sparkline from .menus import back_rows, fit_cells, menu_rows, section_heading -from .qr import qr_text +from .qr import share_popup from .tui import CANCEL, Choice, SelectScreen, Separator from .widgets import _age_seconds, _format_age, channel_glyph, format_ago @@ -922,15 +922,7 @@ async def _show_share( ctx: "AppContext", name: str, secret: bytes, *, intro: str = "Scan to add this channel:" ) -> None: """Show the channel's QR code and its share URL in a dismissable window.""" - url = share_url(name, secret) - body = Group( - Text(intro, style="muted"), - Text(""), - qr_text(url), - Text(""), - Text(url, style="accent"), - ) - await ctx.ui.view(body, title=f"Share {name}", footer_hint="Esc close") + await share_popup(ctx, name=name, url=share_url(name, secret), intro=intro) async def _show_key(ctx: "AppContext", slot: ChannelSlot) -> None: diff --git a/meshterm/ui/config_editor.py b/meshterm/ui/config_editor.py index 79b57f0..ad258a8 100644 --- a/meshterm/ui/config_editor.py +++ b/meshterm/ui/config_editor.py @@ -34,7 +34,6 @@ from urllib.parse import quote from rich import box from rich.cells import cell_len -from rich.console import Group from rich.table import Table from rich.text import Text @@ -817,17 +816,14 @@ async def show_contact_card( node_type: The MeshCore advert type byte (1 companion, 2 repeater, 3 room, 4 sensor). """ - from .qr import qr_text + from .qr import share_popup - url = contact_share_url(name, public_key, node_type) - body = Group( - Text("Scan to add this node as a contact:", style="muted"), - Text(""), - qr_text(url), - Text(""), - Text(url, style="accent"), + await share_popup( + ctx, + name=name, + url=contact_share_url(name, public_key, node_type), + intro="Scan to add this node as a contact:", ) - await ctx.ui.view(body, title=f"Share {name}", footer_hint="Esc close") async def _show_contact_card(ctx: "AppContext", snapshot: dict) -> None: diff --git a/meshterm/ui/qr.py b/meshterm/ui/qr.py index 098ef56..aa8cef6 100644 --- a/meshterm/ui/qr.py +++ b/meshterm/ui/qr.py @@ -9,8 +9,14 @@ matter what colour theme the terminal itself is using. from __future__ import annotations +from typing import TYPE_CHECKING + +from rich.console import Group from rich.text import Text +if TYPE_CHECKING: + from ..context import AppContext + #: Quiet-zone width (modules) around the code. Scanners need at least 4 to lock on. _BORDER = 4 @@ -54,3 +60,26 @@ def qr_text(data: str, *, error: str = "m") -> Text: text.append(line, style=_STYLE) text.append("\n") return text + + +async def share_popup(ctx: "AppContext", *, name: str, url: str, intro: str) -> None: + """THE share popup: a muted intro, the scannable code, then the URL to copy out. + + One layout for every ``Share {name}`` surface — the channel share and the contact + card both come through here, so a change to how MeshTerm presents a share code (a + caption, a border, a "copied" affordance) lands on all of them at once. + + Args: + ctx: Shared application context (provides the UI surface). + name: What is being shared — the popup's title reads ``Share {name}``. + url: The ``meshcore://…`` share URL, encoded as the QR code and printed under it. + intro: The one-line instruction above the code ("Scan to add this channel:"). + """ + body = Group( + Text(intro, style="muted"), + Text(""), + qr_text(url), + Text(""), + Text(url, style="accent"), + ) + await ctx.ui.view(body, title=f"Share {name}", footer_hint="Esc close")