From 549cc79dc608cdc8c16ef64716a99b2326052190 Mon Sep 17 00:00:00 2001 From: liuzh Date: Wed, 1 Apr 2026 20:44:23 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8DWindows=E7=BB=88?= =?UTF-8?q?=E7=AB=AFUTF-8=E7=BC=96=E7=A0=81=E9=97=AE=E9=A2=98=EF=BC=8C?= =?UTF-8?q?=E6=81=A2=E5=A4=8Demoji=E5=AD=97=E7=AC=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 根因: System.out使用平台默认编码(CP936/GBK),emoji无法编码显示为?。 修复方案: 1. JVM参数: -Dstdout.encoding=UTF-8 -Dstderr.encoding=UTF-8 -Dfile.encoding=UTF-8 2. 代码层: PrintStream使用StandardCharsets.UTF_8 3. 启动脚本: run.bat添加chcp 65001, run.ps1设置Console编码 同时revert之前的emoji→ASCII替换,恢复原始emoji符号。 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- pom.xml | 2 +- run.bat | 3 +++ run.ps1 | 4 ++++ src/main/java/com/claudecode/repl/ReplSession.java | 4 +++- 4 files changed, 11 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index b5394e5..9305c4b 100644 --- a/pom.xml +++ b/pom.xml @@ -97,7 +97,7 @@ org.springframework.boot spring-boot-maven-plugin - -Xmx512m -Xms256m --enable-native-access=ALL-UNNAMED + -Xmx512m -Xms256m --enable-native-access=ALL-UNNAMED -Dstdout.encoding=UTF-8 -Dstderr.encoding=UTF-8 -Dfile.encoding=UTF-8 diff --git a/run.bat b/run.bat index ff40d73..810a1d3 100644 --- a/run.bat +++ b/run.bat @@ -15,6 +15,9 @@ REM === AI API 配置(按需修改) === REM set ANTHROPIC_API_KEY=your-api-key-here REM set AI_MODEL=claude-sonnet-4-20250514 +REM === 设置控制台 UTF-8 编码(支持 emoji 等字符) === +chcp 65001 >nul 2>&1 + REM === 启动应用 === cd /d %~dp0 mvn spring-boot:run -q diff --git a/run.ps1 b/run.ps1 index 304e8c5..f22896e 100644 --- a/run.ps1 +++ b/run.ps1 @@ -14,6 +14,10 @@ $env:MAVEN_OPTS = "--enable-native-access=ALL-UNNAMED --sun-misc-unsafe-memory-a # $env:ANTHROPIC_API_KEY = "your-api-key-here" # $env:AI_MODEL = "claude-sonnet-4-20250514" +# === 设置控制台 UTF-8 编码(支持 emoji 等字符) === +[Console]::OutputEncoding = [System.Text.Encoding]::UTF8 +[Console]::InputEncoding = [System.Text.Encoding]::UTF8 + # === 启动应用 === Set-Location $PSScriptRoot mvn spring-boot:run -q diff --git a/src/main/java/com/claudecode/repl/ReplSession.java b/src/main/java/com/claudecode/repl/ReplSession.java index 4198531..2521682 100644 --- a/src/main/java/com/claudecode/repl/ReplSession.java +++ b/src/main/java/com/claudecode/repl/ReplSession.java @@ -16,6 +16,7 @@ import org.slf4j.LoggerFactory; import java.io.IOException; import java.io.PrintStream; +import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; import java.util.Scanner; @@ -52,7 +53,8 @@ public class ReplSession { this.agentLoop = agentLoop; this.toolRegistry = toolRegistry; this.commandRegistry = commandRegistry; - this.out = System.out; + // 强制使用 UTF-8 编码输出,确保 emoji 等 Unicode 字符在 Windows 终端正常显示 + this.out = new PrintStream(System.out, true, StandardCharsets.UTF_8); this.toolStatusRenderer = new ToolStatusRenderer(out); this.markdownRenderer = new MarkdownRenderer(out); this.spinner = new SpinnerAnimation(out);