fix: 修复Windows终端UTF-8编码问题,恢复emoji字符
根因: 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>
This commit is contained in:
@@ -97,7 +97,7 @@
|
|||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||||
<configuration>
|
<configuration>
|
||||||
<jvmArguments>-Xmx512m -Xms256m --enable-native-access=ALL-UNNAMED</jvmArguments>
|
<jvmArguments>-Xmx512m -Xms256m --enable-native-access=ALL-UNNAMED -Dstdout.encoding=UTF-8 -Dstderr.encoding=UTF-8 -Dfile.encoding=UTF-8</jvmArguments>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
|
|||||||
@@ -15,6 +15,9 @@ REM === AI API 配置(按需修改) ===
|
|||||||
REM set ANTHROPIC_API_KEY=your-api-key-here
|
REM set ANTHROPIC_API_KEY=your-api-key-here
|
||||||
REM set AI_MODEL=claude-sonnet-4-20250514
|
REM set AI_MODEL=claude-sonnet-4-20250514
|
||||||
|
|
||||||
|
REM === 设置控制台 UTF-8 编码(支持 emoji 等字符) ===
|
||||||
|
chcp 65001 >nul 2>&1
|
||||||
|
|
||||||
REM === 启动应用 ===
|
REM === 启动应用 ===
|
||||||
cd /d %~dp0
|
cd /d %~dp0
|
||||||
mvn spring-boot:run -q
|
mvn spring-boot:run -q
|
||||||
|
|||||||
@@ -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:ANTHROPIC_API_KEY = "your-api-key-here"
|
||||||
# $env:AI_MODEL = "claude-sonnet-4-20250514"
|
# $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
|
Set-Location $PSScriptRoot
|
||||||
mvn spring-boot:run -q
|
mvn spring-boot:run -q
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ import org.slf4j.LoggerFactory;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.PrintStream;
|
import java.io.PrintStream;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
@@ -52,7 +53,8 @@ public class ReplSession {
|
|||||||
this.agentLoop = agentLoop;
|
this.agentLoop = agentLoop;
|
||||||
this.toolRegistry = toolRegistry;
|
this.toolRegistry = toolRegistry;
|
||||||
this.commandRegistry = commandRegistry;
|
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.toolStatusRenderer = new ToolStatusRenderer(out);
|
||||||
this.markdownRenderer = new MarkdownRenderer(out);
|
this.markdownRenderer = new MarkdownRenderer(out);
|
||||||
this.spinner = new SpinnerAnimation(out);
|
this.spinner = new SpinnerAnimation(out);
|
||||||
|
|||||||
Reference in New Issue
Block a user