Files
operating-room-monitor-server/backend/app/terminal_markdown.py
Kevin 1af442481e 重组为 backend/clients/docs 三层结构,并清理 git 污染。
将后端迁入 backend/,完善根目录 .gitignore,删除误提交的 .mypy_cache 缓存文件。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-05-21 16:02:25 +08:00

21 lines
731 B
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""在终端中渲染 Markdown含 GFM 表格),依赖 Rich。非 TTY 时仍尽量输出为可读表格。"""
from __future__ import annotations
from loguru import logger
from rich.console import Console
from rich.markdown import Markdown
def print_markdown_stderr(content: str) -> None:
text = (content or "").rstrip()
if not text:
return
try:
# stderr=True 与 loguru 的默认输出一致,便于在同一终端里对齐其它日志
console = Console(stderr=True, soft_wrap=True)
console.print(Markdown(text))
except Exception as exc: # pragma: no cover
logger.warning("Rich Markdown 渲染失败 ({}), 回退为纯文本", exc)
logger.info("{}", text)