You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Alternative cancellation handling with callbacks #552
If the callback returns never, the prompt result type could narrow to exclude the cancel symbol:
// result: boolean
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.
Can you explain where you think having a callback would help?
I'd like to hear from you rather than your agent on this. You personally think it'd be better to have an onCancel handler? Can you explain why?
keep in mind you can do this today:
constexitIfCancelled=(obj: unknown)=>{if(isCancel(obj)){process.exit(0);}};// elsewhere...constvalue=awaitprompts.text(options);exitIfCancelled(value);// do other stuff with value
I find myself in the same situation. I agree with @aqeelat (or his AI agent… 😅) about the lack of a centralized way to handle cancellation in Clack right now. However, this proposal still puts onCancel on every individual prompt rather than solving that centrally, so I'm not so sure about what this proposal is about.
@43081j do you think adding an onCancel field to ClackSettings and updateSettings could be an option? It wouldn’t be perfect however. Spinner has its own cancel machinery, and group already exposes onCancel at the batch level, so there’d be some overlap to sort out. But it might still be a useful global default for the common interactive-prompt case.
the risk is that we're then maintaining two different approaches for achieving the same thing. given we haven't seen much demand for it, that'd mean introducing more complexity for no real gain.
my thoughts:
an onCancel for every prompt doesn't make sense. use isCancel - it'll be the same amount of code
a global onCancel may have some use but wouldn't work very well with types and wouldn't be as clear IMO (compared to seeing at the call site how a cancellation is handled)
i think this should be handled either by the CLI builder (clink in future, the new bombshell project) or by a wrapper so the exit handling still happens at the call site (await exitIfCancelled(prompts.text(opts)))
in future, if there's demand, we may look into exposing some kind of exitIfCancelled helper. This particular change (having onCancel callbacks) is unlikely to ever happen since it would just duplicate the existing cancellation pattern in a different place.
Activity
43081j commentedon Jun 5, 2026
Can you explain where you think having a callback would help?
I'd like to hear from you rather than your agent on this. You personally think it'd be better to have an
onCancelhandler? Can you explain why?keep in mind you can do this today:
arsnl commentedon Jun 11, 2026
I find myself in the same situation. I agree with @aqeelat (or his AI agent… 😅) about the lack of a centralized way to handle cancellation in Clack right now. However, this proposal still puts onCancel on every individual prompt rather than solving that centrally, so I'm not so sure about what this proposal is about.
@43081j do you think adding an onCancel field to ClackSettings and updateSettings could be an option? It wouldn’t be perfect however. Spinner has its own cancel machinery, and group already exposes onCancel at the batch level, so there’d be some overlap to sort out. But it might still be a useful global default for the common interactive-prompt case.
43081j commentedon Jun 14, 2026
the risk is that we're then maintaining two different approaches for achieving the same thing. given we haven't seen much demand for it, that'd mean introducing more complexity for no real gain.
my thoughts:
onCancelfor every prompt doesn't make sense. useisCancel- it'll be the same amount of codeonCancelmay have some use but wouldn't work very well with types and wouldn't be as clear IMO (compared to seeing at the call site how a cancellation is handled)i think this should be handled either by the CLI builder (clink in future, the new bombshell project) or by a wrapper so the exit handling still happens at the call site (
await exitIfCancelled(prompts.text(opts)))43081j commentedon Jun 17, 2026
we're going to close this for the time being.
in future, if there's demand, we may look into exposing some kind of
exitIfCancelledhelper. This particular change (havingonCancelcallbacks) is unlikely to ever happen since it would just duplicate the existing cancellation pattern in a different place.