Skip to content

Commit 373e893

Browse files
committedJan 24, 2018
tty: refactor to es6
PR-URL: #17615 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Matteo Collina <[email protected]>
1 parent bb9cedb commit 373e893

File tree

1 file changed

+11
-19
lines changed

1 file changed

+11
-19
lines changed
 

‎lib/tty.js

+11-19
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,9 @@
2121

2222
'use strict';
2323

24-
const util = require('util');
24+
const { inherits, _errnoException, _extend } = require('util');
2525
const net = require('net');
2626
const { TTY, isTTY } = process.binding('tty_wrap');
27-
const { inherits } = util;
28-
const errnoException = util._errnoException;
2927
const errors = require('internal/errors');
3028
const readline = require('readline');
3129
const { release } = require('os');
@@ -41,7 +39,6 @@ function isatty(fd) {
4139
return Number.isInteger(fd) && fd >= 0 && isTTY(fd);
4240
}
4341

44-
4542
function ReadStream(fd, options) {
4643
if (!(this instanceof ReadStream))
4744
return new ReadStream(fd, options);
@@ -54,7 +51,7 @@ function ReadStream(fd, options) {
5451
throw new errors.SystemError(ctx);
5552
}
5653

57-
options = util._extend({
54+
options = _extend({
5855
highWaterMark: 0,
5956
readable: true,
6057
writable: false,
@@ -74,7 +71,6 @@ ReadStream.prototype.setRawMode = function(flag) {
7471
this.isRaw = flag;
7572
};
7673

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

103-
var winSize = new Array(2);
104-
var err = this._handle.getWindowSize(winSize);
99+
const winSize = new Array(2);
100+
const err = this._handle.getWindowSize(winSize);
105101
if (!err) {
106102
this.columns = winSize[0];
107103
this.rows = winSize[1];
108104
}
109105
}
110106
inherits(WriteStream, net.Socket);
111107

112-
113108
WriteStream.prototype.isTTY = true;
114109

115110
WriteStream.prototype.getColorDepth = function(env = process.env) {
@@ -178,25 +173,23 @@ WriteStream.prototype.getColorDepth = function(env = process.env) {
178173
};
179174

180175
WriteStream.prototype._refreshSize = function() {
181-
var oldCols = this.columns;
182-
var oldRows = this.rows;
183-
var winSize = new Array(2);
184-
var err = this._handle.getWindowSize(winSize);
176+
const oldCols = this.columns;
177+
const oldRows = this.rows;
178+
const winSize = new Array(2);
179+
const err = this._handle.getWindowSize(winSize);
185180
if (err) {
186-
this.emit('error', errnoException(err, 'getWindowSize'));
181+
this.emit('error', _errnoException(err, 'getWindowSize'));
187182
return;
188183
}
189-
var newCols = winSize[0];
190-
var newRows = winSize[1];
184+
const [newCols, newRows] = winSize;
191185
if (oldCols !== newCols || oldRows !== newRows) {
192186
this.columns = newCols;
193187
this.rows = newRows;
194188
this.emit('resize');
195189
}
196190
};
197191

198-
199-
// backwards-compat
192+
// Backwards-compat
200193
WriteStream.prototype.cursorTo = function(x, y) {
201194
readline.cursorTo(this, x, y);
202195
};
@@ -213,5 +206,4 @@ WriteStream.prototype.getWindowSize = function() {
213206
return [this.columns, this.rows];
214207
};
215208

216-
217209
module.exports = { isatty, ReadStream, WriteStream };

0 commit comments

Comments
 (0)
Please sign in to comment.