Skip to content

Commit

Permalink
Fix (Core): Restore cursor on force exit. Fix #1237 #1114
Browse files Browse the repository at this point in the history
  • Loading branch information
SBoudrias committed May 29, 2023
1 parent 76fd5f6 commit 23c2a4b
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions packages/core/src/index.mts
Expand Up @@ -139,6 +139,22 @@ export function createPrompt<Value, Config extends AsyncPromptConfig>(
}) as InquirerReadline;
const screen = new ScreenManager(rl);

const onExit = () => {
if (context?.clearPromptOnDone) {
screen.clean();
} else {
screen.clearContent();
}
screen.done();

process.removeListener('exit', onExit);
rl.removeListener('SIGINT', onExit);
};

// Handle cleanup on force exit. Main reason is so we restore the cursor if a prompt hid it.
process.on('exit', onExit);
rl.on('SIGINT', onExit);

// Set our state before starting the prompt.
hooks.length = 0;
sessionRl = rl;
Expand All @@ -159,12 +175,7 @@ export function createPrompt<Value, Config extends AsyncPromptConfig>(
reject(err);
}

if (context?.clearPromptOnDone) {
screen.clean();
} else {
screen.clearContent();
}
screen.done();
onExit();

// Reset hooks state
index = 0;
Expand Down

0 comments on commit 23c2a4b

Please sign in to comment.