Skip to content

Commit

Permalink
tty: refactor to es6
Browse files Browse the repository at this point in the history
Backport-PR-URL: #19230
PR-URL: #17615
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
  • Loading branch information
BridgeAR authored and MylesBorins committed Mar 20, 2018
1 parent ead727c commit 74f0d1a
Showing 1 changed file with 8 additions and 14 deletions.
22 changes: 8 additions & 14 deletions lib/tty.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,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 @@ -66,7 +65,6 @@ ReadStream.prototype.setRawMode = function(flag) {
this.isRaw = flag;
};


function WriteStream(fd) {
if (!(this instanceof WriteStream))
return new WriteStream(fd);
Expand All @@ -86,16 +84,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 @@ -164,25 +161,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', errors.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 @@ -199,5 +194,4 @@ WriteStream.prototype.getWindowSize = function() {
return [this.columns, this.rows];
};


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

0 comments on commit 74f0d1a

Please sign in to comment.