Make sure you have inquirer installed:
npm install inquirer
Then, install inquirer-press-to-continue
:
npm install inquirer-press-to-continue
import inquirer from 'inquirer';
import PressToContinuePrompt from 'inquirer-press-to-continue';
import type { KeyDescriptor } from 'inquirer-press-to-continue';
inquirer.registerPrompt('press-to-continue', PressToContinuePrompt);
const { key: enterKey } = await inquirer.prompt<{ key: KeyDescriptor }>({
name: 'key',
type: 'press-to-continue',
enter: true,
});
console.log(enterKey.value); // "enter"
const { key: anyKey } = await inquirer.prompt<{ key: KeyDescriptor }>({
name: 'key',
type: 'press-to-continue',
anyKey: true,
pressToContinueMessage: 'Press a key to continue...',
});
console.log(anyKey.value);
Type: string
The key the user should press to continue.
Type: boolean
Whether to allow the user to press any key to continue.
Type: boolean
Only allow the enter key to be pressed.
Type: string
Custom message for prompting the user to press a key to continue.