Files
wehub-resource-sync 8ef9db2513
Deploy to GitHub Pages / deploy (push) Has been cancelled
Deploy to GitHub Pages / build (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:56:49 +08:00

28 lines
790 B
Python

#!/usr/bin/env python3
"""Console encoding helpers for PPT Master CLI scripts."""
from __future__ import annotations
import io
import sys
from typing import TextIO
def _reconfigure_stream(stream: TextIO) -> TextIO:
try:
stream.reconfigure(encoding="utf-8", errors="replace")
return stream
except AttributeError:
buffer = getattr(stream, "buffer", None)
if buffer is None:
return stream
return io.TextIOWrapper(buffer, encoding="utf-8", errors="replace")
except (OSError, ValueError):
return stream
def configure_utf8_stdio() -> None:
"""Use UTF-8 for CLI stdout/stderr, including Windows non-UTF-8 locales."""
sys.stdout = _reconfigure_stream(sys.stdout)
sys.stderr = _reconfigure_stream(sys.stderr)