Files
fastapi-vue-setup/fastapi-vue/fastapi_vue/startupbox.py
T
LeoVasanko 465206067b Expose WebSocket connection id as ws.state.logid on accept
Store the two-digit WS id (colored when stderr supports color, plain
otherwise) in the ASGI scope state so user code can include it in its
own log lines via websocket.state.logid.

Move terminal helpers (use_color, strip_ansi, display width) into a new
dependency-free fastapi_vue.tty module, absorbing termwidth.py, to keep
imports one-directional and avoid the logging/accesslog cycle.
2026-10-21 19:40:24 +00:00

21 lines
681 B
Python

"""Startup banner: a rounded unicode box printed to stderr (not via logging)."""
import sys
from .tty import display_width, pad_display
def print_box(text: str) -> None:
"""Print text in a rounded unicode box sized to its longest line.
The text is split on newlines as-is (not trimmed). Padding accounts
for ANSI colors and unicode display width (see tty.display_width).
"""
lines = text.split("\n")
width = max(map(display_width, lines))
border = "─" * (width + 2)
out = [f"╭{border}╮"]
out.extend(f"│ {pad_display(line, width)} │" for line in lines)
out.append(f"╰{border}╯")
sys.stderr.write("\n".join(out) + "\n")