enhance: improve assistant message rendering and console patching
- Split multi-line assistant messages into separate rendered lines - Add streaming cursor (▌) indicator for in-progress responses - Add patchConsole() to intercept System.out/err during TUI mode - Handle empty assistant message edge case Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -225,10 +225,42 @@ public class ClaudeCodeComponent extends Component<ClaudeCodeComponent.TuiState>
|
|||||||
|
|
||||||
case AssistantMsg m -> {
|
case AssistantMsg m -> {
|
||||||
List<Renderable> lines = new ArrayList<>();
|
List<Renderable> lines = new ArrayList<>();
|
||||||
lines.add(Text.of(
|
String text = m.text();
|
||||||
Text.of("● ").color(Color.BRIGHT_CYAN),
|
if (text == null || text.isEmpty()) {
|
||||||
Text.of(m.streaming() ? m.text() + "▌" : m.text()).color(Color.WHITE)
|
if (m.streaming()) {
|
||||||
));
|
lines.add(Text.of(
|
||||||
|
Text.of("● ").color(Color.BRIGHT_CYAN),
|
||||||
|
Text.of("▌").color(Color.BRIGHT_CYAN)
|
||||||
|
));
|
||||||
|
}
|
||||||
|
yield lines;
|
||||||
|
}
|
||||||
|
// 将多行文本拆分为单独的行
|
||||||
|
String[] textLines = text.split("\n", -1);
|
||||||
|
for (int i = 0; i < textLines.length; i++) {
|
||||||
|
String line = textLines[i];
|
||||||
|
if (i == 0) {
|
||||||
|
// 首行带 ● 前缀
|
||||||
|
String displayLine = line;
|
||||||
|
if (m.streaming() && i == textLines.length - 1) {
|
||||||
|
displayLine += "▌";
|
||||||
|
}
|
||||||
|
lines.add(Text.of(
|
||||||
|
Text.of("● ").color(Color.BRIGHT_CYAN),
|
||||||
|
Text.of(displayLine).color(Color.WHITE)
|
||||||
|
));
|
||||||
|
} else {
|
||||||
|
// 续行缩进对齐
|
||||||
|
String displayLine = line;
|
||||||
|
if (m.streaming() && i == textLines.length - 1) {
|
||||||
|
displayLine += "▌";
|
||||||
|
}
|
||||||
|
lines.add(Text.of(
|
||||||
|
Text.of(" ").dimmed(),
|
||||||
|
Text.of(displayLine).color(Color.WHITE)
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
yield lines;
|
yield lines;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -96,6 +96,9 @@ public class JinkReplSession {
|
|||||||
// 启动 jink 渲染
|
// 启动 jink 渲染
|
||||||
inkApp = Ink.render(component);
|
inkApp = Ink.render(component);
|
||||||
|
|
||||||
|
// 拦截 System.out/err,防止日志干扰 TUI
|
||||||
|
inkApp.patchConsole();
|
||||||
|
|
||||||
// 阻塞等待退出
|
// 阻塞等待退出
|
||||||
inkApp.waitUntilExit();
|
inkApp.waitUntilExit();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user