fix: 改进终端兼容性 - FFM原生终端支持、dumb终端提示、双重Goodbye修复
- 添加jline-terminal-ffm依赖(JDK22+ FFM API原生终端) - JVM参数增加--enable-native-access=ALL-UNNAMED - dumb终端模式下显示黄色警告和建议 - 终端尺寸为0时不显示尺寸信息 - ExitCommand不再输出Goodbye(避免与ReplSession重复) - TerminalBuilder增加streams(System.in, System.out) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -63,6 +63,13 @@
|
||||
<version>${jline.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- JLine FFM 终端提供者(JDK 22+,Windows/Linux/Mac 原生终端支持) -->
|
||||
<dependency>
|
||||
<groupId>org.jline</groupId>
|
||||
<artifactId>jline-terminal-ffm</artifactId>
|
||||
<version>${jline.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Picocli: CLI 命令解析 -->
|
||||
<dependency>
|
||||
<groupId>info.picocli</groupId>
|
||||
@@ -90,7 +97,7 @@
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
<configuration>
|
||||
<jvmArguments>-Xmx512m -Xms256m</jvmArguments>
|
||||
<jvmArguments>-Xmx512m -Xms256m --enable-native-access=ALL-UNNAMED</jvmArguments>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
|
||||
@@ -30,6 +30,6 @@ public class ExitCommand implements SlashCommand {
|
||||
if (context.exitCallback() != null) {
|
||||
context.exitCallback().run();
|
||||
}
|
||||
return "Goodbye!";
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -97,8 +97,15 @@ public class ReplSession {
|
||||
|
||||
try (Terminal terminal = TerminalBuilder.builder()
|
||||
.system(true)
|
||||
.streams(System.in, System.out)
|
||||
.build()) {
|
||||
|
||||
// 检测是否为 dumb 终端并提示
|
||||
boolean isDumb = "dumb".equals(terminal.getType());
|
||||
if (isDumb) {
|
||||
log.info("当前为 dumb 终端模式,建议使用 Windows Terminal / PowerShell / cmd 获得完整体验");
|
||||
}
|
||||
|
||||
LineReader reader = LineReaderBuilder.builder()
|
||||
.terminal(terminal)
|
||||
.parser(new DefaultParser())
|
||||
@@ -156,9 +163,22 @@ public class ReplSession {
|
||||
BannerPrinter.printCompact(out);
|
||||
out.println(AnsiStyle.dim(" Working directory: " + System.getProperty("user.dir")));
|
||||
out.println(AnsiStyle.dim(" Tools: " + toolRegistry.size() + " registered"));
|
||||
out.println(AnsiStyle.dim(" Terminal: " + terminal.getType()
|
||||
+ " (" + terminal.getWidth() + "×" + terminal.getHeight() + ")"));
|
||||
out.println(AnsiStyle.dim(" Tip: Tab to complete commands, ↑↓ to browse history, Ctrl+D to exit"));
|
||||
|
||||
boolean isDumb = "dumb".equals(terminal.getType());
|
||||
int w = terminal.getWidth();
|
||||
int h = terminal.getHeight();
|
||||
String termInfo = terminal.getType();
|
||||
if (w > 0 && h > 0) {
|
||||
termInfo += " (" + w + "×" + h + ")";
|
||||
}
|
||||
out.println(AnsiStyle.dim(" Terminal: " + termInfo));
|
||||
|
||||
if (isDumb) {
|
||||
out.println(AnsiStyle.yellow(" ⚠ Dumb 终端模式:Tab补全和行编辑可能受限"));
|
||||
out.println(AnsiStyle.yellow(" 建议在 Windows Terminal / PowerShell / cmd.exe 中运行"));
|
||||
} else {
|
||||
out.println(AnsiStyle.dim(" Tip: Tab to complete commands, ↑↓ to browse history, Ctrl+D to exit"));
|
||||
}
|
||||
out.println();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user