From 14df49b11011d2c01496a0291198bd5b5ba4bbe4 Mon Sep 17 00:00:00 2001 From: Mplan Date: Fri, 12 Jun 2026 00:36:01 +0800 Subject: [PATCH] refactor(cli): replace process.exit prompts with interactive selection for empty states --- index.ts | 43 ++++++++++++++++++++++++++++--------------- 1 file changed, 28 insertions(+), 15 deletions(-) diff --git a/index.ts b/index.ts index 9915d8c..d13cfd4 100644 --- a/index.ts +++ b/index.ts @@ -611,11 +611,14 @@ async function showMenu(): Promise { if (selected === null || selected === BACK) return; - if (selected === "commit") await handleCommit(false, false); - else if (selected === "pr") await handlePR(false); - else await handleConfig(); + const result = + selected === "commit" + ? await handleCommit(false, false) + : selected === "pr" + ? await handlePR(false) + : await handleConfig(); - return; + if (result !== "back") return; } } @@ -660,9 +663,13 @@ async function handleCommit( const unstagedFiles = await getUnstagedFiles(); if (stagedFiles.length === 0 && unstagedFiles.length === 0) { - console.log(`\n ${YELLOW}Nothing to commit.${RESET}`); - await ask(` ${DIM}Press Enter to exit...${RESET}`); - process.exit(0); + const choice = await selectOne({ + title: "Nothing to commit", + subtitle: "No staged or unstaged changes.", + items: [{ label: "Back", value: "back" as const }], + }); + if (choice === null) process.exit(0); + return "done"; } if (unstagedFiles.length > 0) { @@ -685,9 +692,13 @@ async function handleCommit( const diff = await getStagedDiff(); if (!diff) { - console.log(`\n ${YELLOW}No staged changes to commit.${RESET}`); - await ask(` ${DIM}Press Enter to exit...${RESET}`); - process.exit(0); + const choice = await selectOne({ + title: "Nothing to commit", + subtitle: "No staged changes to commit.", + items: [{ label: "Back", value: "back" as const }], + }); + if (choice === null) process.exit(0); + return "done"; } const MAX_DIFF_SIZE = 15000; @@ -815,11 +826,13 @@ async function handlePR(draft: boolean): Promise<"done" | "back"> { const commits = await getBranchCommits(baseBranch); if (commits.length === 0) { - console.error( - `\n ${YELLOW}No commits on ${branchName} compared to ${baseBranch}. Commit something first.${RESET}`, - ); - await ask(` ${DIM}Press Enter to exit...${RESET}`); - process.exit(0); + const choice = await selectOne({ + title: "No commits to compare", + subtitle: `No commits on ${branchName} compared to ${baseBranch}. Commit something first.`, + items: [{ label: "Back", value: "back" as const }], + }); + if (choice === null) process.exit(0); + return "done"; } console.log(