Skip to content

Commit

Permalink
fix: improved behavior w.r.t. ctrl+c cleanup
Browse files Browse the repository at this point in the history
when `ora` hides the cursor... it installs a SIGINT handler to clean up the hiding of the cursor. this causes major unreliability with ctrl+c handling.

```
  // re: hideCursor: false, ugh, otherwise ctrl+c doesn't work reliably
  // sindresorhus/ora#27
  // tapjs/signal-exit#49
```
  • Loading branch information
starpit committed Feb 2, 2023
1 parent dbdf76d commit ed7abfb
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
11 changes: 8 additions & 3 deletions packages/madwizard/src/fe/cli/commands/guide/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,14 @@ export default async function guideHandler<Writer extends Writable["write"]>(
if (!cleanExitPromise) {
// eslint-disable-next-line no-async-promise-executor
cleanExitPromise = new Promise(async (resolve) => {
Debug("madwizard/cleanup")("attempting a clean exit")
await Promise.all([memoizer.cleanup(signal), signal ? guide.onExitSignalFromUser(signal) : Promise.resolve()])
Debug("madwizard/cleanup")("attempting a clean exit... done")
try {
Debug("madwizard/cleanup")("attempting a clean exit")
await Promise.all([memoizer.cleanup(signal), signal ? guide.onExitSignalFromUser(signal) : Promise.resolve()])
} catch (err) {
console.error(err)
} finally {
Debug("madwizard/cleanup")("attempting a clean exit... done")
}
resolve()
})
}
Expand Down
2 changes: 1 addition & 1 deletion packages/madwizard/src/fe/raw/ask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function askViaHandler(ask: Prompt, description: string, onRaw: WithRawViaHandle
}

/** Ask a question via the raw api */
export async function ask(ask: Prompt, description: string | undefined, options: WithRawViaCLI | WithRawViaHandler) {
export function ask(ask: Prompt, description: string | undefined, options: WithRawViaCLI | WithRawViaHandler) {
if (isRawViaHandler(options)) {
return askViaHandler(ask, description, options.raw)
} else {
Expand Down
6 changes: 5 additions & 1 deletion packages/madwizard/src/util/ora-delayed-promise.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,14 @@ export async function oraPromise<T>(
.then(() => (isResolved = true))
.catch(() => (isResolved = true))

// re: hideCursor: false, ugh, otherwise ctrl+c doesn't work reliably
// https://github.com/sindresorhus/ora/issues/27
// https://github.com/tapjs/signal-exit/issues/49

if (!isResolved) {
setTimeout(() => {
if (!isResolved) {
theRealOraPromise(Promise.resolve(action), options).catch(() => {
theRealOraPromise(Promise.resolve(action), Object.assign({ hideCursor: false }, options)).catch(() => {
/* the caller will be alerted by our `return action` */
})
}
Expand Down

0 comments on commit ed7abfb

Please sign in to comment.