confirm
Yes or no question.
Preview
Active state (Yes focused)
confirm
◇ Deploy to production?│ Yes / No└
After submit
confirm
◆ Deploy to production?│ Yes
Usage
import { confirm, isCancel } from 'termprompt';
const shouldContinue = await confirm({
message: 'Deploy to production?',
});
if (isCancel(shouldContinue)) process.exit(0);
if (shouldContinue) {
console.log('Deploying...');
}
Props
| Prop | Type | Default | Description |
|---|---|---|---|
message | string | required | Question text |
initialValue | boolean | false | Pre-selected value |
active | string | "Yes" | Label for the true option |
inactive | string | "No" | Label for the false option |
Custom Labels
const gitInit = await confirm({
message: 'Initialize a git repository?',
active: 'Yeah',
inactive: 'Nah',
initialValue: true,
});
Keyboard
| Key | Action |
|---|---|
Left / h | Toggle |
Right / l | Toggle |
Tab | Toggle |
y / Y | Set to yes |
n / N | Set to no |
Enter | Submit |
Esc | Cancel |