Share popups: one layout, minted where the code is drawn
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 <noreply@anthropic.com>
This commit is contained in:
1 parent
5f8ffc1788
commit
f3de1d1213
3 files changed
+37
-20
No files matched your search
+2
-10
@@ -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:
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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")
|
||||
Reference in new issue
Block a user