Context
This came up while evaluating @clack/prompts as a potential replacement for enquirer.js, comparing it with enquirer.js and @inquirer/prompts.
Related: #83
Related PR: #544
Split out from: #550
Problem
Every prompt call site that handles Ctrl+C currently needs the same boilerplate:
const result = await confirm({ message: 'Continue?' })
if (isCancel(result)) {
cancel('Operation cancelled.')
process.exit(0)
}
This works, but applications with many prompts often centralize cancellation handling. Today, that has to happen after each prompt resolves.
Proposal
Consider supporting an optional cancellation callback on prompts:
const result = await confirm({
message: 'Continue?',
onCancel: () => {
cancel('Operation cancelled.')
process.exit(0)
},
})
If the callback returns never, the prompt result type could narrow to exclude the cancel symbol:
If the callback returns normally, the return type should remain unchanged:
// result: boolean | symbol
Notes
This is mainly about discussing whether callback-based cancellation belongs in clack at all. If the preferred approach is to keep cancellation exclusively result-based through isCancel, this can be closed.
Context
This came up while evaluating
@clack/promptsas a potential replacement forenquirer.js, comparing it withenquirer.jsand@inquirer/prompts.Related: #83
Related PR: #544
Split out from: #550
Problem
Every prompt call site that handles Ctrl+C currently needs the same boilerplate:
This works, but applications with many prompts often centralize cancellation handling. Today, that has to happen after each prompt resolves.
Proposal
Consider supporting an optional cancellation callback on prompts:
If the callback returns
never, the prompt result type could narrow to exclude the cancel symbol:// result: booleanIf the callback returns normally, the return type should remain unchanged:
// result: boolean | symbolNotes
This is mainly about discussing whether callback-based cancellation belongs in clack at all. If the preferred approach is to keep cancellation exclusively result-based through
isCancel, this can be closed.