enquirer: osx/iterm/v0.4.1 using Ctrl+C to exit the cli app makes the text cursor disappear

To fix the problem, I’m able to re-run my app and do a proper exit with a list option and process.exit(). Any chance of getting something like enquirer.cleanup() to close any pipes/handles that aren’t cleaned up when an .ask is done?

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 21 (11 by maintainers)

Most upvoted comments

Haha, I agree! I wouldn’t call it customer service though, maybe community service instead.

@jonschlinkert Excuse the mess, I just extracted this from my project. Select “client” and then press ctrl + c.

const { prompt } = require('enquirer');

const contractor = async () => {
  const register = async () => {
    menu();
  }
  const menu = async () => {
    const { action } = await prompt({
      type: 'select',
      name: 'action',
      message: 'what would you like to do?',
      choices: ['register', 'update', 'mine'],
      initial: 'register',
    });
    switch (action) {
      case 'register': {
        await register();
        break;
      }
      case 'update': {
        console.log('update');
        break;
      }
      case 'mine': {
        console.log('mine');
        break;
      }
      default: {
        console.log('mine');
        break;
      }
    }
  }
  menu();
}

const client = async () => {
  const query = async () => {
    menu();
  }
  const menu = async () => {
    const { action } = await prompt({
      type: 'select',
      name: 'action',
      message: 'what would you like to do?',
      choices: ['query', 'check'],
      initial: 'query',
    });
    switch (action) {
      case 'query': {
        await query();
        break;
      }
      case 'check': {
        console.log('check');
        break;
      }
      default: {
        await query();
        break;
      }
    }
  }
  menu();
}

const program = async () => {
  const { type } = await prompt({
    type: 'select',
    name: 'type',
    message: 'would you like to start a contractor or client?',
    choices: ['contractor', 'client'],
    initial: 'client',
  });

  if (!type || type === 'contractor') {
    return contractor();
  }
  return client();
}

program().catch((err) => {
  console.log(err);
});

This is proof that @jonschlinkert and @doowb have put a lot of thought into making this a great tool for CLI developers. And the customer service is top notch

Ahhh, got it. It’s, fortunately a much simpler issue than what I was thinking (assuming you agree).

Try adding the following right below the require statement:

const { prompt } = require('enquirer');

prompt.on('cancel', () => process.exit());

Sorry about the confusion on this, I just wasn’t thinking. The reason it works this way is that you can control whether or not to exit the process.

Let me know if this is what you’re looking for, or if you have suggestions for other before.

Any chance of getting something like enquirer.cleanup() to close any pipes/handles that aren’t cleaned up when an .ask is done?

@doowb and I just talked about something related (I believe). @doowb did you mention having a local branch with a fix for this?