Skip to content

Commit 41115cb

Browse files
authored
Merge pull request #201 from hqwlkj/main
refactor(ui): 修改退出后还展示状态提示信息
2 parents 47d1f03 + 888a20a commit 41115cb

2 files changed

Lines changed: 23 additions & 14 deletions

File tree

packages/cli/src/ui/views/App.tsx

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ import type {
4848
} from "@vegamo/deepcode-core";
4949
import { SessionManager } from "@vegamo/deepcode-core";
5050
import { getCompactPromptTokenThreshold } from "@vegamo/deepcode-core";
51+
import { writeStdout, writeStdoutLine } from "../../utils/stdio-helpers";
5152

5253
type View = "chat" | "session-list" | "undo" | "mcp-status";
5354

@@ -145,8 +146,8 @@ function App({ projectRoot, initialPrompt, resumeSessionId, onRestart }: AppProp
145146
onAssistantMessage: (message: SessionMessage) => {
146147
setMessages((prev) => [...prev, message]);
147148
if (rawModeRef.current === RawMode.Raw) {
148-
process.stdout.write("\n");
149-
process.stdout.write(renderMessageToStdout(message, rawModeRef.current) + "\n\n");
149+
writeStdoutLine("\n");
150+
writeStdoutLine(renderMessageToStdout(message, rawModeRef.current) + "\n\n");
150151
}
151152
},
152153
onSessionEntryUpdated: (entry) => {
@@ -196,7 +197,7 @@ function App({ projectRoot, initialPrompt, resumeSessionId, onRestart }: AppProp
196197
const resetStaticView = useCallback(
197198
(loadedMessages: SessionMessage[], options?: { clearScreen?: boolean }): Promise<void> => {
198199
if (options?.clearScreen) {
199-
process.stdout.write(ANSI_CLEAR_SCREEN);
200+
writeStdout(ANSI_CLEAR_SCREEN);
200201
}
201202
setMessages([]);
202203
setWelcomeNonce((n) => n + 1);
@@ -298,19 +299,19 @@ function App({ projectRoot, initialPrompt, resumeSessionId, onRestart }: AppProp
298299
const session = activeSessionId ? sessionManager.getSession(activeSessionId) : null;
299300
const resumeHint = buildResumeHintText(activeSessionId ?? undefined);
300301

301-
process.stdout.write("\n");
302+
writeStdoutLine("\n");
302303
if (showCommand) {
303-
process.stdout.write(chalk.rgb(34, 154, 195)("> /exit "));
304-
process.stdout.write("\n\n");
304+
writeStdoutLine(chalk.rgb(34, 154, 195)(" > /exit "));
305+
writeStdoutLine("\n");
305306
}
306307
if (showSummary) {
307308
const summary = buildExitSummaryText({ session, sessionId: activeSessionId ?? undefined });
308-
process.stdout.write(summary);
309-
process.stdout.write("\n\n");
309+
writeStdoutLine(summary);
310+
writeStdoutLine("\n");
310311
}
311312
if (resumeHint) {
312-
process.stdout.write(resumeHint);
313-
process.stdout.write("\n");
313+
writeStdoutLine(resumeHint);
314+
writeStdoutLine("\n");
314315
}
315316

316317
sessionManager.dispose();
@@ -628,7 +629,7 @@ function App({ projectRoot, initialPrompt, resumeSessionId, onRestart }: AppProp
628629
setShowWelcome(false);
629630
setMessages([]);
630631
// Clear screen to remove stale formatted text.
631-
process.stdout.write(ANSI_CLEAR_SCREEN);
632+
writeStdout(ANSI_CLEAR_SCREEN);
632633

633634
setTimeout(() => {
634635
if (nextMode === RawMode.Raw) {
@@ -666,8 +667,8 @@ function App({ projectRoot, initialPrompt, resumeSessionId, onRestart }: AppProp
666667

667668
if (mode === RawMode.Raw) {
668669
// In raw mode, re-render all messages directly to stdout at the new width.
669-
// Use process.stdout.write instead of writeRef to avoid Ink interference.
670-
process.stdout.write(ANSI_CLEAR_SCREEN);
670+
// Use direct stdout instead of writeRef to avoid Ink interference.
671+
writeStdout(ANSI_CLEAR_SCREEN);
671672
const activeSessionId = sessionManager.getActiveSessionId();
672673
const allMessages = activeSessionId ? loadVisibleMessages(sessionManager, activeSessionId) : [];
673674
renderRawModeMessages(allMessages, mode);
@@ -898,7 +899,7 @@ function App({ projectRoot, initialPrompt, resumeSessionId, onRestart }: AppProp
898899
);
899900
}}
900901
</Static>
901-
{busy || statusLine ? <StatusLine busy={busy} text={statusLine} /> : null}
902+
{(busy || statusLine) && !isExiting ? <StatusLine busy={busy} text={statusLine} /> : null}
902903
{errorLine ? (
903904
<Box>
904905
<Text color="red">Error: {errorLine}</Text>

packages/cli/src/utils/stdio-helpers.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
/**
2+
* Writes a message to stdout exactly as provided.
3+
* Use for terminal control sequences or output that manages its own spacing.
4+
*/
5+
export const writeStdout = (message: string): void => {
6+
process.stdout.write(message);
7+
};
8+
19
/**
210
* Writes a message to stdout with a trailing newline.
311
* Use for normal command output that the user expects to see.

0 commit comments

Comments
 (0)