Skip to content

fix(tui): preserve utf8 when copying via powershell#35122

Closed
BROCCOLO1D wants to merge 1 commit into
NousResearch:mainfrom
BROCCOLO1D:fix/35107-tui-wsl-copy-utf8
Closed

fix(tui): preserve utf8 when copying via powershell#35122
BROCCOLO1D wants to merge 1 commit into
NousResearch:mainfrom
BROCCOLO1D:fix/35107-tui-wsl-copy-utf8

Conversation

@BROCCOLO1D

Copy link
Copy Markdown
Contributor

Summary

  • Fixes TUI /copy on WSL/Windows when text is written through PowerShell.
  • Sets PowerShell stdin decoding to UTF-8 before reading piped clipboard text.
  • Keeps the existing Linux/macOS clipboard fallback order unchanged.

Why

WSL sends /copy text to powershell.exe Set-Clipboard over stdin. On systems with non-UTF-8 ANSI code pages, PowerShell can decode those UTF-8 bytes as the local code page before writing the Windows clipboard, which garbles CJK and other non-ASCII text.

Changes

  • Replace the $input PowerShell write path with [Console]::In.ReadToEnd() after setting [Console]::InputEncoding to UTF-8.
  • Reuse the same UTF-8 PowerShell command for native Windows and WSL clipboard writes.
  • Add clipboard unit assertions covering the UTF-8 PowerShell write command.

Validation

  • cd ui-tui && npx eslint src/lib/clipboard.ts src/__tests__/clipboard.test.ts
  • cd ui-tui && npm test -- --run src/__tests__/clipboard.test.ts

Scope

Focused on TUI clipboard writes through PowerShell. Clipboard reads and non-PowerShell Linux/macOS backends are unchanged.

Closes #35107

@alt-glitch alt-glitch added type/bug Something isn't working comp/tui Terminal UI (ui-tui/ + tui_gateway/) P2 Medium — degraded but workaround exists labels May 30, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Competing fix: #35124 uses base64 encoding to bypass PowerShell stdin entirely, while this PR sets [Console]::InputEncoding to UTF-8 and still pipes via stdin. Both fix #35107. The base64 approach in #35124 is more robust since it avoids stdin encoding entirely.

@BROCCOLO1D

Copy link
Copy Markdown
Contributor Author

Closing this in favor of #35124. Both PRs fix the WSL/PowerShell clipboard UTF-8 bug, and #35124's base64 argument path avoids stdin decoding entirely, so it is the more robust approach. Thanks for the quick duplicate-scope check.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/tui Terminal UI (ui-tui/ + tui_gateway/) P2 Medium — degraded but workaround exists type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

/copy in TUI produces garbled CJK text on WSL2

2 participants