I wanted to add the ability to terminate inquirer.js prompts by using the esc key. But every time I call escExit()
before I call await inquirer.prompt(prompts)
the questions do not get updated but get printed onto a new line:
I am not sure what is causing the problem here. Here is the code that is used to run my cli:
const escExit = require('esc-exit');
const inquirer = require('inquirer');
const meow = require('meow');
const { PathPrompt } = require('inquirer-path');
const prompt = require('./prompt');
const cli = meow(`
Usage
$ carbon <file>
Options
--background, -bg Sets the background color (hex)
--interactive, -i Starts interactive mode
--horizontal-padding, -hp Sets the horizontal padding
--linenumbers, -ln Sets if line numbers should be used
--theme, -t Sets the theme
--shadows, -s Sets if shadows should be used
--verbose, -v Prints more stuff
--vertical-padding, -vp Sets the vertical padding
--window-controls, -wc Sets if the window controls should be used
Examples
carbon showcase.js
`, {
flags: {
background: {
alias: 'bg',
type: 'string',
},
interactive: {
alias: 'i',
type: 'boolean',
},
"linenumbers": {
alias: 'ln',
type: 'boolean',
},
"horizontalpadding": {
alias: 'hp',
type: 'string',
},
theme: {
alias: 't',
type: 'string',
},
shadows: {
alias: 's',
type: 'boolean',
},
verbose: {
alias: 'v',
type: 'boolean',
},
"verticalpadding": {
alias: 'vp',
type: 'string',
},
"windowcontrols": {
alias: 'wc',
type: 'boolean',
},
},
});
async function init(flags) {
escExit();
await startInteractive();
}
async function startInteractive() {
// add prompt for files.
inquirer.prompt.registerPrompt('path', PathPrompt);
const result = await inquirer.prompt(prompt);
console.log(result);
}
if (cli.input.length === 0) {
init(cli.flags);
}