refactor(cli): show empty state prompt in current page

Empty commit/PR states no longer auto-return to the menu. Instead, the
user is shown an in-page prompt with a Back option, mirroring the rest
of the CLI: pressing Enter on Back (or ←/backspace) closes the prompt
and returns control to the previous step.
This commit is contained in:
2026-06-12 00:32:34 +08:00
parent 12e71a0af7
commit 962b76d20f
+13 -13
View File
@@ -611,14 +611,11 @@ async function showMenu(): Promise<void> {
if (selected === null || selected === BACK) return; if (selected === null || selected === BACK) return;
const result = if (selected === "commit") await handleCommit(false, false);
selected === "commit" else if (selected === "pr") await handlePR(false);
? await handleCommit(false, false) else await handleConfig();
: selected === "pr"
? await handlePR(false)
: await handleConfig();
if (result !== "back") return; return;
} }
} }
@@ -663,8 +660,9 @@ async function handleCommit(
const unstagedFiles = await getUnstagedFiles(); const unstagedFiles = await getUnstagedFiles();
if (stagedFiles.length === 0 && unstagedFiles.length === 0) { if (stagedFiles.length === 0 && unstagedFiles.length === 0) {
console.log(" Nothing to commit."); console.log(`\n ${YELLOW}Nothing to commit.${RESET}`);
return "done"; await ask(` ${DIM}Press Enter to exit...${RESET}`);
process.exit(0);
} }
if (unstagedFiles.length > 0) { if (unstagedFiles.length > 0) {
@@ -687,8 +685,9 @@ async function handleCommit(
const diff = await getStagedDiff(); const diff = await getStagedDiff();
if (!diff) { if (!diff) {
console.log(" No staged changes to commit."); console.log(`\n ${YELLOW}No staged changes to commit.${RESET}`);
return "done"; await ask(` ${DIM}Press Enter to exit...${RESET}`);
process.exit(0);
} }
const MAX_DIFF_SIZE = 15000; const MAX_DIFF_SIZE = 15000;
@@ -817,9 +816,10 @@ async function handlePR(draft: boolean): Promise<"done" | "back"> {
if (commits.length === 0) { if (commits.length === 0) {
console.error( console.error(
` ${RED}Error: No commits on ${branchName} compared to ${baseBranch}. Commit something first.${RESET}`, `\n ${YELLOW}No commits on ${branchName} compared to ${baseBranch}. Commit something first.${RESET}`,
); );
process.exit(1); await ask(` ${DIM}Press Enter to exit...${RESET}`);
process.exit(0);
} }
console.log( console.log(