Skip to content

Commit 1781e3f

Browse files
committed
fix: properly implement UTF-8 support for Windows terminals
- Add LANG and LC_ALL environment variables for UTF-8 encoding - Prepend 'chcp 65001' command on Windows to set code page to UTF-8 - Handle both PowerShell and CMD syntax for code page switching - Remove incorrect CHCP environment variable approach - Update tests to reflect the corrected implementation This properly fixes non-ASCII characters (Cyrillic, Chinese, Hindi, etc.) being displayed as '?' or diamond symbols in terminal output on Windows. Fixes #8530
1 parent f30e88e commit 1781e3f

File tree

3 files changed

+16
-46
lines changed

3 files changed

+16
-46
lines changed

src/integrations/terminal/Terminal.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -165,11 +165,6 @@ export class Terminal extends BaseTerminal {
165165
LC_ALL: "en_US.UTF-8",
166166
}
167167

168-
// On Windows, set the code page to UTF-8 (65001) for proper Unicode support
169-
if (process.platform === "win32") {
170-
env.CHCP = "65001"
171-
}
172-
173168
// Set Oh My Zsh shell integration if enabled
174169
if (Terminal.getTerminalZshOhMy()) {
175170
env.ITERM_SHELL_INTEGRATION_INSTALLED = "Yes"

src/integrations/terminal/TerminalProcess.ts

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,21 @@ export class TerminalProcess extends BaseTerminalProcess {
114114
(defaultWindowsShellProfile === null ||
115115
(defaultWindowsShellProfile as string)?.toLowerCase().includes("powershell"))
116116

117-
if (isPowerShell) {
118-
let commandToExecute = command
117+
let commandToExecute = command
118+
119+
// On Windows, prepend chcp 65001 to set UTF-8 code page for proper Unicode support
120+
// This fixes issues with non-ASCII characters being displayed as "?" or diamond symbols
121+
if (process.platform === "win32") {
122+
if (isPowerShell) {
123+
// PowerShell syntax: use semicolon to chain commands and redirect output to null
124+
commandToExecute = `chcp 65001 > $null ; ${command}`
125+
} else {
126+
// CMD syntax: use && to chain commands and redirect output to nul
127+
commandToExecute = `chcp 65001 > nul && ${command}`
128+
}
129+
}
119130

131+
if (isPowerShell) {
120132
// Only add the PowerShell counter workaround if enabled
121133
if (Terminal.getPowershellCounter()) {
122134
commandToExecute += ` ; "(Roo/PS Workaround: ${this.terminal.cmdCounter++})" > $null`
@@ -126,12 +138,10 @@ export class TerminalProcess extends BaseTerminalProcess {
126138
if (Terminal.getCommandDelay() > 0) {
127139
commandToExecute += ` ; start-sleep -milliseconds ${Terminal.getCommandDelay()}`
128140
}
129-
130-
terminal.shellIntegration.executeCommand(commandToExecute)
131-
} else {
132-
terminal.shellIntegration.executeCommand(command)
133141
}
134142

143+
terminal.shellIntegration.executeCommand(commandToExecute)
144+
135145
this.isHot = true
136146

137147
// Wait for stream to be available

src/integrations/terminal/__tests__/TerminalRegistry.spec.ts

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -126,40 +126,5 @@ describe("TerminalRegistry", () => {
126126
Terminal.setTerminalZshP10k(false)
127127
}
128128
})
129-
130-
it("adds CHCP=65001 on Windows for UTF-8 support", () => {
131-
// Mock platform as Windows
132-
const originalPlatform = process.platform
133-
Object.defineProperty(process, "platform", {
134-
value: "win32",
135-
writable: true,
136-
configurable: true,
137-
})
138-
139-
try {
140-
TerminalRegistry.createTerminal("/test/path", "vscode")
141-
142-
expect(mockCreateTerminal).toHaveBeenCalledWith({
143-
cwd: "/test/path",
144-
name: "Roo Code",
145-
iconPath: expect.any(Object),
146-
env: {
147-
PAGER: "",
148-
VTE_VERSION: "0",
149-
PROMPT_EOL_MARK: "",
150-
LANG: "en_US.UTF-8",
151-
LC_ALL: "en_US.UTF-8",
152-
CHCP: "65001",
153-
},
154-
})
155-
} finally {
156-
// Restore original platform
157-
Object.defineProperty(process, "platform", {
158-
value: originalPlatform,
159-
writable: true,
160-
configurable: true,
161-
})
162-
}
163-
})
164129
})
165130
})

0 commit comments

Comments
 (0)