vorpal icon indicating copy to clipboard operation
vorpal copied to clipboard

How close vorpal programmatically

Open ORESoftware opened this issue 6 years ago • 3 comments

The user can close vorpal with ctrl+c, but how can I close vorpal programmatically?

For example, if a vorpal terminal session is opened, but no further stdin is received after 25 seconds, I want to programmatically close vorpal, here is what my code looks like:

  vorpal
  .delimiter(shortCWD + chalk.magenta(' / suman>'))
  .show();

  const to = setTimeout(function () {
    vorpal.close();     // >>>  I want to programmatically close vorpal...but vorpal.close() is not a function
    process.stdin.end();
    log.error('No stdin was received after 25 seconds..closing...');
    p.killAllImmediately();
    process.exit(0);
  }, 25000);   // if no stdin has been received after 25 seconds

  process.stdin
  .setEncoding('utf8')
  .resume()
  .on('data', function customOnData(data: string) {
    clearTimeout(to);
    if (String(data) === 'q') {
      log.warning('killing all active workers.');
      p.killAllActiveWorkers();
    }
  });

ORESoftware avatar Nov 06 '17 00:11 ORESoftware

I asked a question on SO about this, if someone wants points: https://stackoverflow.com/questions/47128158/close-vorpal-instance-programmatically

ORESoftware avatar Nov 06 '17 00:11 ORESoftware

@dthree @milesj hopefully this is a quick one, help appreciated

ORESoftware avatar Nov 06 '17 00:11 ORESoftware

I left a quick answer on Stack Overflow in case other people find that as well, but you can use vorpal.exec("exit");

danielhickman avatar Nov 06 '17 01:11 danielhickman