Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
tty: refactor to es6
PR-URL: #17615
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
  • Loading branch information
BridgeAR committed Mar 8, 2018
commit 073cf692be409891f6fee07dfcca7448acbffdbf
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 };