Draw the splash wordmark from a colored logo.ansi file
Replace the baked-in block-glyph constant with a pre-coloured logo.ansi read fresh on every render, so the wordmark can be re-styled by editing that file alone. It uses the ANSI Shadow face with green letters (#4ade80) and a single-line dark-green bevel (#166534). The banner path in compose_startup now centers already-coloured ANSI rows (as one left-aligned block) rather than force-styling them a single colour, and a new muted, centered footnote sits below the box — the splash uses it for a "© <year> Homestead" copyright notice. The plain-text source is kept as logo.txt for regenerating the art, and the old ansilogo.txt is removed. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
1 parent
b66d1f7626
commit
e52e5daf87
10 files changed
+134
-35
No files matched your search
@@ -1,5 +0,0 @@
|
||||
███ ███ ███████ ███████ ██ ██ ████████ ███████ ██████ ███ ███
|
||||
████ ████ ██ ██ ██ ██ ██ ██ ██ ██ ████ ████
|
||||
██ ████ ██ █████ ███████ ███████ ██ █████ ██████ ██ ████ ██
|
||||
██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
|
||||
██ ██ ███████ ███████ ██ ██ ██ ███████ ██ ██ ██ ██
|
||||
@@ -10,6 +10,7 @@ it actually connects.
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from datetime import datetime
|
||||
from typing import TYPE_CHECKING, Optional
|
||||
|
||||
from rich.cells import cell_len
|
||||
@@ -17,12 +18,17 @@ from rich.text import Text
|
||||
|
||||
from ..core.device_store import RememberedDevice
|
||||
from ..core.discovery import DiscoveredDevice
|
||||
from .logo import LOGO
|
||||
from .logo import load_logo
|
||||
from .tui import Choice, Separator
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from .surface import Ui
|
||||
|
||||
|
||||
def _copyright() -> str:
|
||||
"""The splash's muted copyright line, dated to the current year."""
|
||||
return f"© {datetime.now().year} Johnputer"
|
||||
|
||||
#: Trailing tag per discovery confidence tier (see :attr:`DiscoveredDevice.confidence`).
|
||||
#: A bare serial bridge is only a weak hint, so it is not billed as a LoRa device.
|
||||
_TAG: dict[str, str] = {
|
||||
@@ -69,7 +75,8 @@ async def prompt_device(
|
||||
"Plug one in, pass [accent]--port[/accent], or run with [accent]--mock[/accent]."
|
||||
),
|
||||
title="Select a companion device",
|
||||
banner=LOGO,
|
||||
banner=load_logo(),
|
||||
footnote=_copyright(),
|
||||
)
|
||||
return None
|
||||
|
||||
@@ -117,5 +124,6 @@ async def prompt_device(
|
||||
default = device
|
||||
|
||||
return await ui.select_startup(
|
||||
"Select a companion device", items, default=default, banner=LOGO
|
||||
"Select a companion device", items, default=default, banner=load_logo(),
|
||||
footnote=_copyright(),
|
||||
)
|
||||
@@ -0,0 +1,6 @@
|
||||
[38;2;74;222;128m███[38;2;22;101;52m┐[0m [38;2;74;222;128m███[38;2;22;101;52m┐[38;2;74;222;128m███████[38;2;22;101;52m┐[38;2;74;222;128m███████[38;2;22;101;52m┐[38;2;74;222;128m██[38;2;22;101;52m┐[0m [38;2;74;222;128m██[38;2;22;101;52m┐[38;2;74;222;128m████████[38;2;22;101;52m┐[38;2;74;222;128m███████[38;2;22;101;52m┐[38;2;74;222;128m██████[38;2;22;101;52m┐[0m [38;2;74;222;128m███[38;2;22;101;52m┐[0m [38;2;74;222;128m███[38;2;22;101;52m┐[0m
|
||||
[38;2;74;222;128m████[38;2;22;101;52m┐[0m [38;2;74;222;128m████[38;2;22;101;52m│[38;2;74;222;128m██[38;2;22;101;52m┌────┘[38;2;74;222;128m██[38;2;22;101;52m┌────┘[38;2;74;222;128m██[38;2;22;101;52m│[0m [38;2;74;222;128m██[38;2;22;101;52m│└──[38;2;74;222;128m██[38;2;22;101;52m┌──┘[38;2;74;222;128m██[38;2;22;101;52m┌────┘[38;2;74;222;128m██[38;2;22;101;52m┌──[38;2;74;222;128m██[38;2;22;101;52m┐[38;2;74;222;128m████[38;2;22;101;52m┐[0m [38;2;74;222;128m████[38;2;22;101;52m│[0m
|
||||
[38;2;74;222;128m██[38;2;22;101;52m┌[38;2;74;222;128m████[38;2;22;101;52m┌[38;2;74;222;128m██[38;2;22;101;52m│[38;2;74;222;128m█████[38;2;22;101;52m┐[0m [38;2;74;222;128m███████[38;2;22;101;52m┐[38;2;74;222;128m███████[38;2;22;101;52m│[0m [38;2;74;222;128m██[38;2;22;101;52m│[0m [38;2;74;222;128m█████[38;2;22;101;52m┐[0m [38;2;74;222;128m██████[38;2;22;101;52m┌┘[38;2;74;222;128m██[38;2;22;101;52m┌[38;2;74;222;128m████[38;2;22;101;52m┌[38;2;74;222;128m██[38;2;22;101;52m│[0m
|
||||
[38;2;74;222;128m██[38;2;22;101;52m│└[38;2;74;222;128m██[38;2;22;101;52m┌┘[38;2;74;222;128m██[38;2;22;101;52m│[38;2;74;222;128m██[38;2;22;101;52m┌──┘[0m [38;2;22;101;52m└────[38;2;74;222;128m██[38;2;22;101;52m│[38;2;74;222;128m██[38;2;22;101;52m┌──[38;2;74;222;128m██[38;2;22;101;52m│[0m [38;2;74;222;128m██[38;2;22;101;52m│[0m [38;2;74;222;128m██[38;2;22;101;52m┌──┘[0m [38;2;74;222;128m██[38;2;22;101;52m┌──[38;2;74;222;128m██[38;2;22;101;52m┐[38;2;74;222;128m██[38;2;22;101;52m│└[38;2;74;222;128m██[38;2;22;101;52m┌┘[38;2;74;222;128m██[38;2;22;101;52m│[0m
|
||||
[38;2;74;222;128m██[38;2;22;101;52m│[0m [38;2;22;101;52m└─┘[0m [38;2;74;222;128m██[38;2;22;101;52m│[38;2;74;222;128m███████[38;2;22;101;52m┐[38;2;74;222;128m███████[38;2;22;101;52m│[38;2;74;222;128m██[38;2;22;101;52m│[0m [38;2;74;222;128m██[38;2;22;101;52m│[0m [38;2;74;222;128m██[38;2;22;101;52m│[0m [38;2;74;222;128m███████[38;2;22;101;52m┐[38;2;74;222;128m██[38;2;22;101;52m│[0m [38;2;74;222;128m██[38;2;22;101;52m│[38;2;74;222;128m██[38;2;22;101;52m│[0m [38;2;22;101;52m└─┘[0m [38;2;74;222;128m██[38;2;22;101;52m│[0m
|
||||
[38;2;22;101;52m└─┘[0m [38;2;22;101;52m└─┘└──────┘└──────┘└─┘[0m [38;2;22;101;52m└─┘[0m [38;2;22;101;52m└─┘[0m [38;2;22;101;52m└──────┘└─┘[0m [38;2;22;101;52m└─┘└─┘[0m [38;2;22;101;52m└─┘[0m
|
||||
+25
-11
@@ -1,16 +1,30 @@
|
||||
"""The MeshTerm wordmark, as block-glyph ASCII art for the startup screen.
|
||||
"""The MeshTerm wordmark for the startup splash, loaded from ``logo.ansi``.
|
||||
|
||||
Kept as a code constant (rather than a packaged data file) so it is always available at
|
||||
runtime regardless of how the package is installed.
|
||||
The art lives in a sibling ``logo.ansi`` file (pre-coloured ANSI, one row per line) and is
|
||||
read fresh on every call, so the wordmark can be re-styled by editing that file alone — no
|
||||
code change or restart of the design loop required.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
#: The wordmark, one string per row. Rows are equal width, so the block centers cleanly.
|
||||
LOGO: list[str] = [
|
||||
'███ ███ ███████ ███████ ██ ██ ████████ ███████ ██████ ███ ███',
|
||||
'████ ████ ██ ██ ██ ██ ██ ██ ██ ██ ████ ████',
|
||||
'██ ████ ██ █████ ███████ ███████ ██ █████ ██████ ██ ████ ██',
|
||||
'██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██',
|
||||
'██ ██ ███████ ███████ ██ ██ ██ ███████ ██ ██ ██ ██',
|
||||
]
|
||||
from pathlib import Path
|
||||
|
||||
#: The ANSI art file, kept beside this module so it ships inside the package.
|
||||
_LOGO_PATH = Path(__file__).with_name("logo.ansi")
|
||||
|
||||
|
||||
def load_logo() -> list[str]:
|
||||
"""Return the wordmark's rows (pre-coloured ANSI strings), or ``[]`` if unavailable.
|
||||
|
||||
Read from :data:`_LOGO_PATH` on each call so an edit to the art is picked up without a
|
||||
restart. A missing or unreadable file degrades to no banner rather than raising, so the
|
||||
splash still works.
|
||||
"""
|
||||
try:
|
||||
text = _LOGO_PATH.read_text(encoding="utf-8")
|
||||
except OSError:
|
||||
return []
|
||||
lines = text.split("\n")
|
||||
if lines and lines[-1] == "": # drop the trailing newline's empty row
|
||||
lines.pop()
|
||||
return lines
|
||||
@@ -0,0 +1,6 @@
|
||||
███╗ ███╗███████╗███████╗██╗ ██╗████████╗███████╗██████╗ ███╗ ███╗
|
||||
████╗ ████║██╔════╝██╔════╝██║ ██║╚══██╔══╝██╔════╝██╔══██╗████╗ ████║
|
||||
██╔████╔██║█████╗ ███████╗███████║ ██║ █████╗ ██████╔╝██╔████╔██║
|
||||
██║╚██╔╝██║██╔══╝ ╚════██║██╔══██║ ██║ ██╔══╝ ██╔══██╗██║╚██╔╝██║
|
||||
██║ ╚═╝ ██║███████╗███████║██║ ██║ ██║ ███████╗██║ ██║██║ ╚═╝ ██║
|
||||
╚═╝ ╚═╝╚══════╝╚══════╝╚═╝ ╚═╝ ╚═╝ ╚══════╝╚═╝ ╚═╝╚═╝ ╚═╝
|
||||
+43
-8
@@ -58,13 +58,24 @@ class Ui:
|
||||
raise NotImplementedError
|
||||
|
||||
async def select_startup(
|
||||
self, title: str, items: list, *, default: Any = None, banner: Any = None
|
||||
self,
|
||||
title: str,
|
||||
items: list,
|
||||
*,
|
||||
default: Any = None,
|
||||
banner: Any = None,
|
||||
footnote: Optional[str] = None,
|
||||
) -> Any:
|
||||
"""Choose one item on a chromeless startup splash; ``None`` if skipped."""
|
||||
raise NotImplementedError
|
||||
|
||||
async def notify_startup(
|
||||
self, renderable: RenderableType, *, title: str = "", banner: Any = None
|
||||
self,
|
||||
renderable: RenderableType,
|
||||
*,
|
||||
title: str = "",
|
||||
banner: Any = None,
|
||||
footnote: Optional[str] = None,
|
||||
) -> None:
|
||||
"""Show a message on a chromeless startup splash until the user dismisses it."""
|
||||
raise NotImplementedError
|
||||
@@ -146,13 +157,24 @@ class PlainUi(Ui):
|
||||
raise self._no_prompt()
|
||||
|
||||
async def select_startup(
|
||||
self, title: str, items: list, *, default: Any = None, banner: Any = None
|
||||
self,
|
||||
title: str,
|
||||
items: list,
|
||||
*,
|
||||
default: Any = None,
|
||||
banner: Any = None,
|
||||
footnote: Optional[str] = None,
|
||||
) -> Any:
|
||||
"""Unsupported in scripted CLI mode."""
|
||||
raise self._no_prompt()
|
||||
|
||||
async def notify_startup(
|
||||
self, renderable: RenderableType, *, title: str = "", banner: Any = None
|
||||
self,
|
||||
renderable: RenderableType,
|
||||
*,
|
||||
title: str = "",
|
||||
banner: Any = None,
|
||||
footnote: Optional[str] = None,
|
||||
) -> None:
|
||||
"""Unsupported in scripted CLI mode."""
|
||||
raise self._no_prompt()
|
||||
@@ -272,18 +294,31 @@ class TuiUi(Ui):
|
||||
return await self.session.select(title, items, default=default)
|
||||
|
||||
async def select_startup(
|
||||
self, title: str, items: list, *, default: Any = None, banner: Any = None
|
||||
self,
|
||||
title: str,
|
||||
items: list,
|
||||
*,
|
||||
default: Any = None,
|
||||
banner: Any = None,
|
||||
footnote: Optional[str] = None,
|
||||
) -> Any:
|
||||
"""Delegate to the session's chromeless startup select splash."""
|
||||
return await self.session.select_startup(
|
||||
title, items, default=default, banner=banner
|
||||
title, items, default=default, banner=banner, footnote=footnote
|
||||
)
|
||||
|
||||
async def notify_startup(
|
||||
self, renderable: RenderableType, *, title: str = "", banner: Any = None
|
||||
self,
|
||||
renderable: RenderableType,
|
||||
*,
|
||||
title: str = "",
|
||||
banner: Any = None,
|
||||
footnote: Optional[str] = None,
|
||||
) -> None:
|
||||
"""Delegate to the session's chromeless startup message splash."""
|
||||
await self.session.notify_startup(renderable, title=title, banner=banner)
|
||||
await self.session.notify_startup(
|
||||
renderable, title=title, banner=banner, footnote=footnote
|
||||
)
|
||||
|
||||
async def reorder(self, title: str, labels: list[str]) -> list[int]:
|
||||
"""Delegate to the session's reorder screen."""
|
||||
|
||||
@@ -14,7 +14,7 @@ from rich.console import Group, RenderableType
|
||||
from rich.panel import Panel
|
||||
from rich.text import Text
|
||||
|
||||
from .render import render_lines, render_to_ansi
|
||||
from .render import render_lines
|
||||
from .screen import Screen, ScrollScreen
|
||||
|
||||
|
||||
@@ -129,12 +129,17 @@ def _center(lines: list[str], cols: int) -> list[str]:
|
||||
|
||||
|
||||
def _banner_lines(banner: Sequence[str], cols: int) -> list[str]:
|
||||
"""Render the wordmark rows in the brand colour, centered within ``cols``."""
|
||||
"""Center the wordmark rows (already-coloured ANSI) as one left-aligned block.
|
||||
|
||||
Each row is padded to the block's widest display width first, so the shared left margin
|
||||
keeps the art internally aligned rather than centering every row on its own axis.
|
||||
"""
|
||||
if not banner:
|
||||
return []
|
||||
width = max(cell_len(row) for row in banner)
|
||||
lines = [render_to_ansi(Text(row, style="brand"), width) for row in banner]
|
||||
return _center(lines, cols)
|
||||
widths = [cell_len(Text.from_ansi(row).plain) for row in banner]
|
||||
width = max(widths)
|
||||
padded = [row + " " * (width - w) for row, w in zip(banner, widths)]
|
||||
return _center(padded, cols)
|
||||
|
||||
|
||||
def compose_startup(screen: Screen, cols: int, rows: int) -> str:
|
||||
@@ -182,7 +187,13 @@ def compose_startup(screen: Screen, cols: int, rows: int) -> str:
|
||||
)
|
||||
panel_lines = _center(render_lines(panel, inner_w + 4), cols)
|
||||
|
||||
block = banner + ([""] if banner else []) + panel_lines
|
||||
# A small muted line (e.g. a copyright notice) sits a blank row below the box.
|
||||
footnote_lines: list[str] = []
|
||||
if screen.footnote:
|
||||
note = Text.from_markup(f"[muted]{screen.footnote}[/muted]")
|
||||
footnote_lines = [""] + _center(render_lines(note, cell_len(screen.footnote)), cols)
|
||||
|
||||
block = banner + ([""] if banner else []) + panel_lines + footnote_lines
|
||||
top = max(0, (rows - len(block)) // 2)
|
||||
lines = [""] * top + block
|
||||
if len(lines) > rows:
|
||||
|
||||
@@ -39,6 +39,8 @@ class Screen:
|
||||
session instead centers it under the :attr:`banner` with no status bars.
|
||||
banner: Block-glyph art (one string per row) drawn, centered, above a chromeless
|
||||
base screen. Ignored while ``chrome`` is ``True``.
|
||||
footnote: A short line drawn muted and centered *below* a chromeless base screen's
|
||||
box (e.g. a copyright notice). Ignored while ``chrome`` is ``True``.
|
||||
"""
|
||||
|
||||
title: str = ""
|
||||
@@ -46,6 +48,7 @@ class Screen:
|
||||
floating: bool = True
|
||||
chrome: bool = True
|
||||
banner: Optional[Sequence[str]] = None
|
||||
footnote: Optional[str] = None
|
||||
|
||||
def __init__(self) -> None:
|
||||
"""Initialize scroll state and the (later-assigned) result future."""
|
||||
|
||||
@@ -137,19 +137,22 @@ class TuiSession:
|
||||
*,
|
||||
default: Any = None,
|
||||
banner: Optional[Any] = None,
|
||||
footnote: Optional[str] = None,
|
||||
footer_hint: str = "↑↓ move · Enter select · Esc skip",
|
||||
) -> Any:
|
||||
"""Show a chromeless select splash (banner above a content-sized box).
|
||||
|
||||
Like :meth:`select`, but drawn without the header/footer status bars and centered
|
||||
under ``banner`` — the startup device picker's presentation. Type-to-filter is off:
|
||||
the device list is short and fixed, so stray keys never narrow it.
|
||||
the device list is short and fixed, so stray keys never narrow it. An optional
|
||||
``footnote`` (e.g. a copyright notice) sits muted below the box.
|
||||
"""
|
||||
screen = SelectScreen(
|
||||
title, items, default=default, footer_hint=footer_hint, filterable=False
|
||||
)
|
||||
screen.chrome = False
|
||||
screen.banner = banner
|
||||
screen.footnote = footnote
|
||||
result = await self.run_screen(screen)
|
||||
return None if result is CANCEL else result
|
||||
|
||||
@@ -159,12 +162,14 @@ class TuiSession:
|
||||
*,
|
||||
title: str = "",
|
||||
banner: Optional[Any] = None,
|
||||
footnote: Optional[str] = None,
|
||||
footer_hint: str = "Enter continue",
|
||||
) -> None:
|
||||
"""Show a chromeless message splash (banner above a boxed renderable) until dismissed."""
|
||||
screen = ScrollScreen(renderable, title=title, footer_hint=footer_hint)
|
||||
screen.chrome = False
|
||||
screen.banner = banner
|
||||
screen.footnote = footnote
|
||||
await self.run_screen(screen)
|
||||
|
||||
async def reorder(self, title: str, labels: list[str]) -> list[int]:
|
||||
|
||||
+17
-1
@@ -200,6 +200,17 @@ def test_compose_startup_is_chromeless_and_shows_banner() -> None:
|
||||
assert all(len(line.rstrip()) < 80 for line in plain.split("\n"))
|
||||
|
||||
|
||||
def test_compose_startup_shows_footnote_below_box() -> None:
|
||||
"""A footnote (e.g. a copyright) is drawn, muted and centered, below the box."""
|
||||
screen = SelectScreen("pick", [Choice("a", 1)])
|
||||
screen.chrome = False
|
||||
screen.footnote = "© 2026 Johnputer"
|
||||
lines = Text.from_ansi(frame.compose_startup(screen, 80, 20)).plain.split("\n")
|
||||
note = next(ln for ln in lines if "Homestead" in ln)
|
||||
assert note.strip() == "© 2026 Johnputer" # its own line
|
||||
assert note.startswith(" ") # centered, not flush-left
|
||||
|
||||
|
||||
def test_compose_startup_box_is_horizontally_centered() -> None:
|
||||
"""The content-sized box is centered, so its rows carry a leading left margin."""
|
||||
screen = SelectScreen("pick", [Choice("a", 1)])
|
||||
@@ -285,14 +296,19 @@ def test_device_picker_builds_aligned_columns() -> None:
|
||||
captured: dict = {}
|
||||
|
||||
class _Ui:
|
||||
async def select_startup(self, title, items, *, default=None, banner=None):
|
||||
async def select_startup(
|
||||
self, title, items, *, default=None, banner=None, footnote=None
|
||||
):
|
||||
captured["items"] = items
|
||||
captured["banner"] = banner
|
||||
captured["footnote"] = footnote
|
||||
return None
|
||||
|
||||
asyncio.run(prompt_device(_Ui(), devices, None))
|
||||
# The banner (wordmark) is passed through so the splash can draw it.
|
||||
assert captured["banner"] and any("█" in row for row in captured["banner"])
|
||||
# A copyright footnote rides along for the splash to render below the box.
|
||||
assert "Homestead" in captured["footnote"]
|
||||
# Each device row's port sits at the same column, proving the name column is padded.
|
||||
rows = [it.label.plain for it in captured["items"] if isinstance(it, Choice)]
|
||||
assert len(rows) == 2
|
||||
|
||||
Reference in new issue
Block a user