fix(scripts): force UTF-8 stdout/stderr in design_system.py on Windows (#390)

design_system.py prints box-drawing characters and swatches (--, OK marks,
block swatches), but unlike search.py it never reconfigured stdout. On a
non-UTF-8 Windows console (cp1252/gbk) running the CLI crashes with
UnicodeEncodeError, the same failure reported in #112 for search.py.

Mirror the wrapper search.py already uses: re-wrap stdout/stderr in a
UTF-8 TextIOWrapper when the console encoding is not UTF-8. Applied to
the source of truth and the synced cli/assets copy.

Verified: the CLI runs clean under PYTHONIOENCODING=cp1252 (exit 0, no
UnicodeEncodeError) while still emitting the box/swatch output;
check:assets passes.

Related to #112 (search.py is already fixed on main; this covers the
remaining design_system.py instance).
This commit is contained in:
Alexander 2026-06-25 07:30:49 -04:00 committed by GitHub
parent 7d62cd093b
commit d86f44368d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 16 additions and 0 deletions

View File

@ -16,10 +16,18 @@ Usage:
import csv
import json
import os
import sys
import io
from datetime import datetime
from pathlib import Path
from core import search, DATA_DIR
# Force UTF-8 for stdout/stderr to handle emojis/box-drawing chars on Windows (cp1252 default)
if sys.stdout.encoding and sys.stdout.encoding.lower() != 'utf-8':
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8')
if sys.stderr.encoding and sys.stderr.encoding.lower() != 'utf-8':
sys.stderr = io.TextIOWrapper(sys.stderr.buffer, encoding='utf-8')
# ============ CONFIGURATION ============
REASONING_FILE = "ui-reasoning.csv"

View File

@ -16,10 +16,18 @@ Usage:
import csv
import json
import os
import sys
import io
from datetime import datetime
from pathlib import Path
from core import search, DATA_DIR
# Force UTF-8 for stdout/stderr to handle emojis/box-drawing chars on Windows (cp1252 default)
if sys.stdout.encoding and sys.stdout.encoding.lower() != 'utf-8':
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8')
if sys.stderr.encoding and sys.stderr.encoding.lower() != 'utf-8':
sys.stderr = io.TextIOWrapper(sys.stderr.buffer, encoding='utf-8')
# ============ CONFIGURATION ============
REASONING_FILE = "ui-reasoning.csv"