Skip to content

Commit 74f0d1a

Browse files
BridgeARMylesBorins
authored andcommitted
tty: refactor to es6
Backport-PR-URL: #19230 PR-URL: #17615 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
1 parent ead727c commit 74f0d1a

File tree

1 file changed

+8
-14
lines changed

1 file changed

+8
-14
lines changed

lib/tty.js

+8-14
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ function isatty(fd) {
3939
return Number.isInteger(fd) && fd >= 0 && isTTY(fd);
4040
}
4141

42-
4342
function ReadStream(fd, options) {
4443
if (!(this instanceof ReadStream))
4544
return new ReadStream(fd, options);
@@ -66,7 +65,6 @@ ReadStream.prototype.setRawMode = function(flag) {
6665
this.isRaw = flag;
6766
};
6867

69-
7068
function WriteStream(fd) {
7169
if (!(this instanceof WriteStream))
7270
return new WriteStream(fd);
@@ -86,16 +84,15 @@ function WriteStream(fd) {
8684
// Ref: https://github.com/nodejs/node/pull/1771#issuecomment-119351671
8785
this._handle.setBlocking(true);
8886

89-
var winSize = new Array(2);
90-
var err = this._handle.getWindowSize(winSize);
87+
const winSize = new Array(2);
88+
const err = this._handle.getWindowSize(winSize);
9189
if (!err) {
9290
this.columns = winSize[0];
9391
this.rows = winSize[1];
9492
}
9593
}
9694
inherits(WriteStream, net.Socket);
9795

98-
9996
WriteStream.prototype.isTTY = true;
10097

10198
WriteStream.prototype.getColorDepth = function(env = process.env) {
@@ -164,25 +161,23 @@ WriteStream.prototype.getColorDepth = function(env = process.env) {
164161
};
165162

166163
WriteStream.prototype._refreshSize = function() {
167-
var oldCols = this.columns;
168-
var oldRows = this.rows;
169-
var winSize = new Array(2);
170-
var err = this._handle.getWindowSize(winSize);
164+
const oldCols = this.columns;
165+
const oldRows = this.rows;
166+
const winSize = new Array(2);
167+
const err = this._handle.getWindowSize(winSize);
171168
if (err) {
172169
this.emit('error', errors.errnoException(err, 'getWindowSize'));
173170
return;
174171
}
175-
var newCols = winSize[0];
176-
var newRows = winSize[1];
172+
const [newCols, newRows] = winSize;
177173
if (oldCols !== newCols || oldRows !== newRows) {
178174
this.columns = newCols;
179175
this.rows = newRows;
180176
this.emit('resize');
181177
}
182178
};
183179

184-
185-
// backwards-compat
180+
// Backwards-compat
186181
WriteStream.prototype.cursorTo = function(x, y) {
187182
readline.cursorTo(this, x, y);
188183
};
@@ -199,5 +194,4 @@ WriteStream.prototype.getWindowSize = function() {
199194
return [this.columns, this.rows];
200195
};
201196

202-
203197
module.exports = { isatty, ReadStream, WriteStream };

0 commit comments

Comments
 (0)