From d86f44368dd412f3de1b05c5ef48c8184569096b Mon Sep 17 00:00:00 2001 From: Alexander Date: Thu, 25 Jun 2026 07:30:49 -0400 Subject: [PATCH] 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). --- cli/assets/scripts/design_system.py | 8 ++++++++ src/ui-ux-pro-max/scripts/design_system.py | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/cli/assets/scripts/design_system.py b/cli/assets/scripts/design_system.py index 339aaba..f1f714e 100644 --- a/cli/assets/scripts/design_system.py +++ b/cli/assets/scripts/design_system.py @@ -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" diff --git a/src/ui-ux-pro-max/scripts/design_system.py b/src/ui-ux-pro-max/scripts/design_system.py index 339aaba..f1f714e 100644 --- a/src/ui-ux-pro-max/scripts/design_system.py +++ b/src/ui-ux-pro-max/scripts/design_system.py @@ -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"