bombshell-dev / clack

Effortlessly build beautiful command-line apps
https://clack.cc
5.53k stars 90 forks source link

[Feature Request] Need a `onCancel` property #54

Closed AkaraChen closed 1 year ago

AkaraChen commented 1 year ago

Is your feature request related to a problem? Please describe.

I think have a onCancel property will be better.

Currently I need to call isCanceled in every prompts, I think it is troublesome.

Describe the solution you'd like

import { text, cancel } from '@clack/prompts'

const result = await text({
    /* Other options */
    onCancel() {
        cancel('Operation canceled.')
        process.exit(1)
    }
})
cpreston321 commented 1 year ago

Hey @AkaraChen until there is a definite solution within core then we can't add these options per prompt without duplication. In the meantime you can wrap within a the new 'group' function and within the second param you pass onCancel like you have above.

Example here: https://github.com/natemoo-re/clack/blob/main/examples/basic/index.ts

AkaraChen commented 1 year ago

Thanks for such a quick reply.