-
Notifications
You must be signed in to change notification settings - Fork 2.6k
fix: add UTF-8 encoding support for Windows terminal output #8531
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -114,9 +114,21 @@ export class TerminalProcess extends BaseTerminalProcess { | |
| (defaultWindowsShellProfile === null || | ||
| (defaultWindowsShellProfile as string)?.toLowerCase().includes("powershell")) | ||
|
|
||
| if (isPowerShell) { | ||
| let commandToExecute = command | ||
| let commandToExecute = command | ||
|
|
||
| // On Windows, prepend chcp 65001 to set UTF-8 code page for proper Unicode support | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [P3] chcp 65001 is executed before every command; the code page persists for the session, so this is redundant overhead. Consider setting it once per terminal session and caching a flag to skip subsequent calls. |
||
| // This fixes issues with non-ASCII characters being displayed as "?" or diamond symbols | ||
| if (process.platform === "win32") { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [P2] PowerShell detection relies on terminal.integrated.defaultProfile and may not match the active terminal shell at runtime. If mismatched, the PowerShell-style redirection ($null) will fail in CMD. Derive from terminal.state.shell.id/executable (when available) and only fall back to the setting. |
||
| if (isPowerShell) { | ||
| // PowerShell syntax: use semicolon to chain commands and redirect output to null | ||
| commandToExecute = `chcp 65001 > $null ; ${command}` | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [P2] chcp 65001 sets the console code page, but PowerShell may still output non‑UTF‑8 without $OutputEncoding being set. Setting both $OutputEncoding and [Console]::OutputEncoding improves reliability for Unicode output. |
||
| } else { | ||
| // CMD syntax: use && to chain commands and redirect output to nul | ||
| commandToExecute = `chcp 65001 > nul && ${command}` | ||
| } | ||
| } | ||
|
|
||
| if (isPowerShell) { | ||
| // Only add the PowerShell counter workaround if enabled | ||
| if (Terminal.getPowershellCounter()) { | ||
| commandToExecute += ` ; "(Roo/PS Workaround: ${this.terminal.cmdCounter++})" > $null` | ||
|
|
@@ -126,12 +138,10 @@ export class TerminalProcess extends BaseTerminalProcess { | |
| if (Terminal.getCommandDelay() > 0) { | ||
| commandToExecute += ` ; start-sleep -milliseconds ${Terminal.getCommandDelay()}` | ||
| } | ||
|
|
||
| terminal.shellIntegration.executeCommand(commandToExecute) | ||
| } else { | ||
| terminal.shellIntegration.executeCommand(command) | ||
| } | ||
|
|
||
| terminal.shellIntegration.executeCommand(commandToExecute) | ||
|
|
||
| this.isHot = true | ||
|
|
||
| // Wait for stream to be available | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[P1] Forcing LANG/LC_ALL to en_US.UTF-8 overrides user locale and can emit locale warnings on systems without that locale. Consider not overriding when already set and prefer a safer default like C.UTF-8; also avoid setting these on Windows where they don't influence the console code page.