<commit_before>/**
 * pty.js
 * Copyright (c) 2012, <NAME> (MIT License)
 * Binding to the pseudo terminals.
 */

var net = require('net');
var pty = require('../build/Release/pty.node');

/**
 * Terminal
 */

// Example:
//  var term = new Terminal('bash', ['-i'], {
//    name: 'xterm-color',
//    cols: 80,
//    rows: 30,
//    cwd: process.env.HOME,
//    env: { HELLO: 'WORLD' }
//  });

var Terminal = function(file, args, opt) {
  if (!(this instanceof Terminal)) return new Terminal(file, args, opt);

  var self = this
    , env
    , cwd
    , name
    , cols
    , rows
    , term;

  // 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 || 'sh';
  opt = opt || {};

  name = opt.name || 'vt100';
  cols = opt.cols || 80;
  rows = opt.rows || 30;
  env = opt.env || clone(process.env);
  cwd = opt.cwd || process.cwd();

  if (opt.name) env.TERM = name;
  env = environ(env);

  // fork
  term = pty.fork(file, args, env, cwd, cols, rows);
  this.socket = new net.Socket(term.fd);
  this.socket.setEncoding('utf8');
  this.socket.resume();

  // setup
  this.socket.on('error', function(err) {
    self.socket.writable = false;
    self.write = function() {};
    self.end = self.write;
    self.writable = false;

    // EIO, happens when someone closes our child
    // process: the only process in the terminal.
    if (err.code && ~err.code.indexOf('errno 5')) return;

    // throw anything else
    if (self.listeners('error').length < 2) {
      throw err;
    }
  });

  this.pid = term.pid;
  this.fd = term.fd;
  this.pty = term.pty;

  this.file = file;
  this.name = name;
  this.cols = cols;
  this.rows = rows;

  Terminal.total++;
  this.socket.on('close', function() {
    Terminal.total--;
  });

  env = null;
};

Terminal.fork =
Terminal.spawn =
Terminal.createTerminal = function(file, args, opt) {
  return new Terminal(file, args, opt);
};
<commit_msg>set the readable and writable properties to true<commit_after>/**
 * pty.js
 * Copyright (c) 2012, <NAME> (MIT License)
 * Binding to the pseudo terminals.
 */

var net = require('net');
var pty = require('../build/Release/pty.node');

/**
 * Terminal
 */

// Example:
//  var term = new Terminal('bash', ['-i'], {
//    name: 'xterm-color',
//    cols: 80,
//    rows: 30,
//    cwd: process.env.HOME,
//    env: { HELLO: 'WORLD' }
//  });

var Terminal = function(file, args, opt) {
  if (!(this instanceof Terminal)) return new Terminal(file, args, opt);

  var self = this
    , env
    , cwd
    , name
    , cols
    , rows
    , term;

  // 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 || 'sh';
  opt = opt || {};

  name = opt.name || 'vt100';
  cols = opt.cols || 80;
  rows = opt.rows || 30;
  env = opt.env || clone(process.env);
  cwd = opt.cwd || process.cwd();

  if (opt.name) env.TERM = name;
  env = environ(env);

  // fork
  term = pty.fork(file, args, env, cwd, cols, rows);
  this.socket = new net.Socket(term.fd);
  this.socket.setEncoding('utf8');
  this.socket.resume();

  // setup
  this.socket.on('error', function(err) {
    self.socket.writable = false;
    self.write = function() {};
    self.end = self.write;
    self.writable = false;

    // EIO, happens when someone closes our child
    // process: the only process in the terminal.
    if (err.code && ~err.code.indexOf('errno 5')) return;

    // throw anything else
    if (self.listeners('error').length < 2) {
      throw err;
    }
  });

  this.pid = term.pid;
  this.fd = term.fd;
  this.pty = term.pty;

  this.file = file;
  this.name = name;
  this.cols = cols;
  this.rows = rows;
  this.readable = this.writable = true;

  Terminal.total++;
  this.socket.on('close', function() {
    Terminal.total--;
  });

  env = null;
};

Terminal.fork =
Terminal.spawn =
Terminal.createTerminal = function(file, args, opt) {
  return new Terminal(file, args, opt);
};

{'fraction_non_alphanumeric': 0.1794027745121091, 'fraction_numerical': 0.009875382083235363, 'mean_word_length': 2.4783319705641866, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6143294', 'n_tokens_mistral': 1586, 'n_tokens_neox': 1503, 'n_words': 384}