Skip to content

Commit

Permalink
tty: refactor to es6
Browse files Browse the repository at this point in the history
PR-URL: nodejs#17615
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
  • Loading branch information
BridgeAR authored and MayaLekova committed May 8, 2018
1 parent 343acf6 commit f0bddf2
Showing 1 changed file with 11 additions and 19 deletions.
30 changes: 11 additions & 19 deletions lib/tty.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,9 @@

'use strict';

const util = require('util');
const { inherits, _errnoException, _extend } = require('util');
const net = require('net');
const { TTY, isTTY } = process.binding('tty_wrap');
const { inherits } = util;
const errnoException = util._errnoException;
const errors = require('internal/errors');
const readline = require('readline');
const { release } = require('os');
Expand All @@ -41,7 +39,6 @@ function isatty(fd) {
return Number.isInteger(fd) && fd >= 0 && isTTY(fd);
}


function ReadStream(fd, options) {
if (!(this instanceof ReadStream))
return new ReadStream(fd, options);
Expand All @@ -54,7 +51,7 @@ function ReadStream(fd, options) {
throw new errors.SystemError(ctx);
}

options = util._extend({
options = _extend({
highWaterMark: 0,
readable: true,
writable: false,
Expand All @@ -74,7 +71,6 @@ ReadStream.prototype.setRawMode = function(flag) {
this.isRaw = flag;
};


function WriteStream(fd) {
if (!(this instanceof WriteStream))
return new WriteStream(fd);
Expand All @@ -100,16 +96,15 @@ function WriteStream(fd) {
// Ref: https://github.com/nodejs/node/pull/1771#issuecomment-119351671
this._handle.setBlocking(true);

var winSize = new Array(2);
var err = this._handle.getWindowSize(winSize);
const winSize = new Array(2);
const err = this._handle.getWindowSize(winSize);
if (!err) {
this.columns = winSize[0];
this.rows = winSize[1];
}
}
inherits(WriteStream, net.Socket);


WriteStream.prototype.isTTY = true;

WriteStream.prototype.getColorDepth = function(env = process.env) {
Expand Down Expand Up @@ -178,25 +173,23 @@ WriteStream.prototype.getColorDepth = function(env = process.env) {
};

WriteStream.prototype._refreshSize = function() {
var oldCols = this.columns;
var oldRows = this.rows;
var winSize = new Array(2);
var err = this._handle.getWindowSize(winSize);
const oldCols = this.columns;
const oldRows = this.rows;
const winSize = new Array(2);
const err = this._handle.getWindowSize(winSize);
if (err) {
this.emit('error', errnoException(err, 'getWindowSize'));
this.emit('error', _errnoException(err, 'getWindowSize'));
return;
}
var newCols = winSize[0];
var newRows = winSize[1];
const [newCols, newRows] = winSize;
if (oldCols !== newCols || oldRows !== newRows) {
this.columns = newCols;
this.rows = newRows;
this.emit('resize');
}
};


// backwards-compat
// Backwards-compat
WriteStream.prototype.cursorTo = function(x, y) {
readline.cursorTo(this, x, y);
};
Expand All @@ -213,5 +206,4 @@ WriteStream.prototype.getWindowSize = function() {
return [this.columns, this.rows];
};


module.exports = { isatty, ReadStream, WriteStream };

0 comments on commit f0bddf2

Please sign in to comment.