docs: function Terminal(file, args, opt) {
  
    var self = this,
        env, cwd, name, cols, rows, term, agent, debug;
  
    // Backward compatibility.
    if (typeof args === 'string') {
      opt = {
        name: arguments[1],
        cols: arguments[2],
        rows: arguments[3],
        cwd: process.env.HOME
      };
      args = [];
    }
  
    // Arguments.
    args = args || [];
    file = file || 'cmd.exe';
    opt = opt || {};
  
    env = extend({}, opt.env);
  
    cols = opt.cols || 80;
    rows = opt.rows || 30;
    cwd = opt.cwd || process.cwd();
    name = opt.name || env.TERM || 'Windows Shell';
    debug = opt.debug || false;
  
    env.TERM = name;
  
    // Initialize environment variables.
    env = environ(env);
  
    // If the terminal is ready
    this.isReady = false;
  
    // Functions that need to run after `ready` event is emitted.
    this.deferreds = [];
  
    // Create new termal.
    this.agent = new Agent(file, args, env, cwd, cols, rows, debug);
  
    // The dummy socket is used so that we can defer everything
    // until its available.
    this.socket = this.agent.ptySocket;
  
    // The terminal socket when its available
    this.dataPipe = null;
  
    // Not available until `ready` event emitted.
    this.pid = this.agent.pid;
    this.fd = this.agent.fd;
    this.pty = this.agent.pty;
  
    // The forked windows terminal is not available
    // until `ready` event is emitted.
    this.socket.on('ready_datapipe', function (socket) {
  
      // Set terminal socket
      self.dataPipe = socket;
  
      // These events needs to be forwarded.
      ['connect', 'data', 'end', 'timeout', 'drain'].forEach(function(event) {
        self.dataPipe.on(event, function(data) {
  
          // Wait until the first data event is fired
          // then we can run deferreds.
          if(!self.isReady && event == 'data') {
  
            // Terminal is now ready and we can
            // avoid having to defer method calls.
            self.isReady = true;
  
            // Execute all deferred methods
            self.deferreds.forEach(function(fn) {
              // NB! In order to ensure that `this` has all
              // its references updated any variable that
              // need to be available in `this` before
              // the deferred is run has to be declared
              // above this forEach statement.
              fn.run();
            });
  
            // Reset
            self.deferreds = [];
  
          }
  
          // Emit to dummy socket
          self.socket.emit(event, data);
  
        });
      });
  
      // Resume socket.
      self.dataPipe.resume();
  
      // Shutdown if `error` event is emitted.
      self.dataPipe.on('error', function (err) {
  
        // Close terminal session.
        self._close();
  
        // EIO, happens when someone closes our child
        // process: the only process in the terminal.
        // node < 0.6.14: errno 5
        // node >= 0.6.14: read EIO
        if (err.code) {
          if (~err.code.indexOf('errno 5') || ~err.code.indexOf('EIO')) return;
        }
  
        // Throw anything else.
        if (self.listeners('error').length < 2) {
          throw err;
        }
  
      });
  
      // Cleanup after the socket is closed.
      self.dataPipe.on('close', function () {
        Terminal.total--;
        self.emit('exit', null);
        self._close();
      });
  
    });
  
    this.file = file;
    this.name = name;
    this.cols = cols;
    this.rows = rows;
  
    this.readable = true;
    this.writable = true;
  
    Terminal.total++;
  }