Skip to content

Commit 7e5eeda

Browse files
committed
feat(ui): 添加 raw 模式下消息直接渲染功能
- 在 Raw 模式下,使用 process.stdout.write 直接输出所有可见消息 - 清屏并重置光标位置,避免 Ink 组件干扰 - 显示提示信息,指导用户按 ESC 退出 raw 模式 - 优化终端尺寸变化时的重绘逻辑 - 更新依赖,确保 raw 模式变动触发重新渲染
1 parent 379ffc5 commit 7e5eeda

1 file changed

Lines changed: 25 additions & 1 deletion

File tree

src/ui/App.tsx

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -434,8 +434,31 @@ export function App({ projectRoot, initialPrompt, onRestart }: AppProps): React.
434434
}
435435
lastRenderedColumnsRef.current = stableColumns;
436436

437+
if (mode === RawMode.Raw) {
438+
// In raw mode, re-render all messages directly to stdout at the new width.
439+
// Use process.stdout.write instead of writeRef to avoid Ink interference.
440+
process.stdout.write("\u001B[2J\u001B[3J\u001B[H");
441+
const activeSessionId = sessionManager.getActiveSessionId();
442+
const allMessages = activeSessionId ? loadVisibleMessages(sessionManager, activeSessionId) : [];
443+
for (const msg of allMessages) {
444+
process.stdout.write("\n");
445+
process.stdout.write(renderMessageToStdout(msg, mode) + "\n\n");
446+
}
447+
if (allMessages.length > 0) {
448+
process.stdout.write("\n\n");
449+
process.stdout.write(chalk.dim("Press ESC to exit raw mode"));
450+
} else {
451+
process.stdout.write("\n");
452+
process.stdout.write(chalk.dim("(No messages in this session yet. Start chatting to see them here.)"));
453+
process.stdout.write("\n\n");
454+
process.stdout.write(chalk.dim("Press ESC to exit raw mode"));
455+
}
456+
return;
457+
}
458+
437459
// Force full redraw on terminal resize to avoid stale wrapped rows.
438460
writeRef.current("\u001B[2J\u001B[H");
461+
439462
setMessages([]);
440463
setShowWelcome(false);
441464
setWelcomeNonce((n) => n + 1);
@@ -447,7 +470,8 @@ export function App({ projectRoot, initialPrompt, onRestart }: AppProps): React.
447470
setMessages(nextMessages);
448471
setShowWelcome(true);
449472
}, 0);
450-
}, [busy, sessionManager, stableColumns, stdout]);
473+
}, [busy, mode, sessionManager, stableColumns, stdout]);
474+
451475
const screenWidth = useMemo(() => stableColumns ?? stdout?.columns ?? 80, [stableColumns, stdout]);
452476
const promptHistory = useMemo(() => {
453477
return messages

0 commit comments

Comments
 (0)