summaryrefslogtreecommitdiff
path: root/lib/tty.js
diff options
context:
space:
mode:
authorRuben Bridgewater <ruben@bridgewater.de>2018-01-17 19:38:51 +0100
committerRuben Bridgewater <ruben@bridgewater.de>2018-01-24 13:07:35 +0100
commit373e893ee0f09108289f623f73213907b8b05889 (patch)
tree8fee5df8f94d21a0519fbdb36f2421fa8f1b1548 /lib/tty.js
parentbb9cedb0f07c4f74cada172845f2aea197efa456 (diff)
downloadandroid-node-v8-373e893ee0f09108289f623f73213907b8b05889.tar.gz
android-node-v8-373e893ee0f09108289f623f73213907b8b05889.tar.bz2
android-node-v8-373e893ee0f09108289f623f73213907b8b05889.zip
tty: refactor to es6
PR-URL: https://github.com/nodejs/node/pull/17615 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Diffstat (limited to 'lib/tty.js')
-rw-r--r--lib/tty.js30
1 files changed, 11 insertions, 19 deletions
diff --git a/lib/tty.js b/lib/tty.js
index dc3e2fcf82..584ff9d870 100644
--- a/lib/tty.js
+++ b/lib/tty.js
@@ -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');
@@ -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);
@@ -54,7 +51,7 @@ function ReadStream(fd, options) {
throw new errors.SystemError(ctx);
}
- options = util._extend({
+ options = _extend({
highWaterMark: 0,
readable: true,
writable: false,
@@ -74,7 +71,6 @@ ReadStream.prototype.setRawMode = function(flag) {
this.isRaw = flag;
};
-
function WriteStream(fd) {
if (!(this instanceof WriteStream))
return new WriteStream(fd);
@@ -100,8 +96,8 @@ 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];
@@ -109,7 +105,6 @@ function WriteStream(fd) {
}
inherits(WriteStream, net.Socket);
-
WriteStream.prototype.isTTY = true;
WriteStream.prototype.getColorDepth = function(env = process.env) {
@@ -178,16 +173,15 @@ 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;
@@ -195,8 +189,7 @@ WriteStream.prototype._refreshSize = function() {
}
};
-
-// backwards-compat
+// Backwards-compat
WriteStream.prototype.cursorTo = function(x, y) {
readline.cursorTo(this, x, y);
};
@@ -213,5 +206,4 @@ WriteStream.prototype.getWindowSize = function() {
return [this.columns, this.rows];
};
-
module.exports = { isatty, ReadStream, WriteStream };