[PR #10489] fix(pty): Add UTF-8 defaults for Windows PTY #13462

Closed
opened 2026-02-16 18:18:19 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/10489

State: closed
Merged: No


Summary

Fix CJK (Chinese, Japanese, Korean) character display issues in Windows terminals by adding proper UTF-8 encoding defaults.

Problem

Windows terminals don't have UTF-8 encoding enabled by default, causing CJK characters to display as gibberish or question marks. This affects:

  • Terminal output with CJK characters
  • Python scripts with CJK strings
  • Git operations with CJK filenames
  • Any CLI tool outputting CJK text

Solution

This PR adds platform-specific UTF-8 defaults for Windows:

Environment Variables

  • LANG=en_US.UTF-8 - Sets locale for Unix-style tools
  • LC_ALL=en_US.UTF-8 - Overrides all locale categories
  • PYTHONUTF8=1 - Enables UTF-8 mode for Python 3.7+
  • PYTHONIOENCODING=utf-8 - Sets Python stdin/stdout/stderr encoding

Shell Startup Arguments

  • CMD.exe: Runs chcp 65001 to set code page to UTF-8
  • PowerShell: Sets OutputEncoding and InputEncoding to UTF-8

Testing

Tested on Windows with:

  • Terminal displaying Chinese characters correctly
  • Python scripts printing CJK text without errors
  • Git operations with CJK filenames
  • CMD and PowerShell shells

Impact

  • Platform: Windows only (no impact on macOS/Linux)
  • Backwards Compatible: Yes (only sets defaults, can be overridden via env parameter)
  • User-Visible: Yes (fixes CJK display issues)

Related Issues

This PR addresses the root cause of several Windows encoding issues:

  • Fixes #10414 - OpenCode crashes with garbled console output on Windows
  • Fixes #10486 - Chinese characters appearing incorrectly
  • Fixes #9814 - Garbled characters after launching on Windows
  • Fixes #9793 - Chinese characters displaying as garbled text (命令行模式下中文显示突然全部变成乱码)
  • Related to #10265 - Ctrl+C terminal garbage issue
  • Related to #10341 - Scoop Windows garbled output issue

Closes #10491

**Original Pull Request:** https://github.com/anomalyco/opencode/pull/10489 **State:** closed **Merged:** No --- ## Summary Fix CJK (Chinese, Japanese, Korean) character display issues in Windows terminals by adding proper UTF-8 encoding defaults. ## Problem Windows terminals don't have UTF-8 encoding enabled by default, causing CJK characters to display as gibberish or question marks. This affects: - Terminal output with CJK characters - Python scripts with CJK strings - Git operations with CJK filenames - Any CLI tool outputting CJK text ## Solution This PR adds platform-specific UTF-8 defaults for Windows: ### Environment Variables - `LANG=en_US.UTF-8` - Sets locale for Unix-style tools - `LC_ALL=en_US.UTF-8` - Overrides all locale categories - `PYTHONUTF8=1` - Enables UTF-8 mode for Python 3.7+ - `PYTHONIOENCODING=utf-8` - Sets Python stdin/stdout/stderr encoding ### Shell Startup Arguments - **CMD.exe**: Runs `chcp 65001` to set code page to UTF-8 - **PowerShell**: Sets OutputEncoding and InputEncoding to UTF-8 ## Testing Tested on Windows with: - ✅ Terminal displaying Chinese characters correctly - ✅ Python scripts printing CJK text without errors - ✅ Git operations with CJK filenames - ✅ CMD and PowerShell shells ## Impact - **Platform**: Windows only (no impact on macOS/Linux) - **Backwards Compatible**: Yes (only sets defaults, can be overridden via env parameter) - **User-Visible**: Yes (fixes CJK display issues) ## Related Issues This PR addresses the root cause of several Windows encoding issues: - Fixes #10414 - OpenCode crashes with garbled console output on Windows - Fixes #10486 - Chinese characters appearing incorrectly - Fixes #9814 - Garbled characters after launching on Windows - Fixes #9793 - Chinese characters displaying as garbled text (命令行模式下中文显示突然全部变成乱码) - Related to #10265 - Ctrl+C terminal garbage issue - Related to #10341 - Scoop Windows garbled output issue Closes #10491
yindo added the pull-request label 2026-02-16 18:18:19 -05:00
yindo closed this issue 2026-02-16 18:18:19 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#13462