public static open()

in src/unixTerminal.ts [189:242]


  public static open(opt: IPtyOpenOptions): UnixTerminal {
    const self: UnixTerminal = Object.create(UnixTerminal.prototype);
    opt = opt || {};

    if (arguments.length > 1) {
      opt = {
        cols: arguments[1],
        rows: arguments[2]
      };
    }

    const cols = opt.cols || DEFAULT_COLS;
    const rows = opt.rows || DEFAULT_ROWS;
    const encoding = (opt.encoding === undefined ? 'utf8' : opt.encoding);

    // open
    const term: IUnixOpenProcess = pty.open(cols, rows);

    self._master = new PipeSocket(<number>term.master);
    if (encoding !== null) {
      self._master.setEncoding(encoding);
    }
    self._master.resume();

    self._slave = new PipeSocket(term.slave);
    if (encoding !== null) {
      self._slave.setEncoding(encoding);
    }
    self._slave.resume();

    self._socket = self._master;
    self._pid = null;
    self._fd = term.master;
    self._pty = term.pty;

    self._file = process.argv[0] || 'node';
    self._name = process.env.TERM || '';

    self._readable = true;
    self._writable = true;

    self._socket.on('error', err => {
      self._close();
      if (self.listeners('error').length < 2) {
        throw err;
      }
    });

    self._socket.on('close', () => {
      self._close();
    });

    return self;
  }