function UI() {
    _classCallCheck(this, UI);

    var _this = _possibleConstructorReturn(this, (UI.__proto__ || Object.getPrototypeOf(UI)).call(this));

    var self = _this;

    // Attached vorpal instance. The UI can
    // only attach to one instance of Vorpal
    // at a time, and directs all events to that
    // instance.
    _this.parent = undefined;

    // Hook to reference active inquirer prompt.
    _this._activePrompt = undefined;

    // Fail-safe to ensure there is no double
    // prompt in odd situations.
    _this._midPrompt = false;

    // Handle for inquirer's prompt.
    _this.inquirer = inquirer;

    // prompt history from inquirer
    _this.inquirerStdout = [];

    // Whether a prompt is currently in cancel mode.
    _this._cancelled = false;

    // Middleware for piping stdout through.
    _this._pipeFn = undefined;

    // Custom function on sigint event.
    _this._sigintCalled = false;
    _this._sigintCount = 0;
    _this._sigint = function () {
      if (_this._sigintCount > 1) {
        _this.parent.emit('vorpal_exit');
        process.exit(0);
      } else {
        var text = _this.input();
        if (!_this.parent) {
          // If Vorpal isn't shown, just exit.
          process.exit(0);
        } else if (_this.parent.session.cancelCommands) {
          // There are commands running if
          // cancelCommands function is available.
          _this.imprint();
          _this.submit('');
          _this._sigintCalled = false;
          _this._sigintCount = 0;
          _this.parent.session.emit('vorpal_command_cancel');
        } else if (String(text).trim() !== '') {
          _this.imprint();
          _this.submit('');
          _this._sigintCalled = false;
          _this._sigintCount = 0;
        } else {
          _this._sigintCalled = false;
          _this.delimiter(' ');
          _this.submit('');
          _this.log('(^C again to quit)');
        }
      }
    };

    process.stdin.on('keypress', function (letter, key) {
      key = key || {};
      if (key.ctrl === true && key.shift === false && key.meta === false && ['c', 'C'].indexOf(key.name) > -1) {
        _this._sigintCount++;
        if (_this._sigint !== undefined && !_this._sigintCalled) {
          _this._sigintCalled = true;
          _this._sigint.call(self.parent);
          _this._sigintCalled = false;
        }
      } else {
        _this._sigintCalled = false;
        _this._sigintCount = 0;
      }
    });

    // Extend the render function to steal the active prompt object,
    // as inquirer doesn't expose it and we need it.
    var prompts = ['input', 'checkbox', 'confirm', 'expand', 'list', 'password', 'rawlist'];

    var _loop = function _loop(key) {
      var promptType = prompts[key];

      // Add method to Inquirer to get type of prompt.
      inquirer.prompt.prompts[promptType].prototype.getType = function () {
        return promptType;
      };

      // Hook in to steal Inquirer's keypress.
      inquirer.prompt.prompts[promptType].prototype.onKeypress = function (e) {
        // Inquirer seems to have a bug with release v0.10.1
        // (not 0.10.0 though) that triggers keypresses for
        // the previous prompt in addition to the current one.
        // So if the prompt is answered, shut it up.
        if (this.status && this.status === 'answered') {
          return;
        }
        self._activePrompt = this;
        self.parent.emit('client_keypress', e);
        self._keypressHandler(e, this);
      };

      // Add hook to render method.
      var render = inquirer.prompt.prompts[promptType].prototype.render;
      inquirer.prompt.prompts[promptType].prototype.render = function () {
        self._activePrompt = this;
        return render.apply(this, arguments);
      };
    };

    for (var key in prompts) {
      _loop(key);
    }

    // Sigint handling - make it more graceful.
    var onSigInt = function onSigInt() {
      if (_.isFunction(_this._sigint) && !_this._sigintCalled) {
        _this._sigintCalled = true;
        _this._sigint.call(_this.parent);
      }
    };
    process.on('SIGINT', onSigInt);
    process.on('SIGTERM', onSigInt);
    return _this;
  }
Sets intial variables and registers
listeners. This is called once in a
process thread regardless of how many
instances of Vorpal have been generated.

@api private