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);