From 373e893ee0f09108289f623f73213907b8b05889 Mon Sep 17 00:00:00 2001 From: Ruben Bridgewater Date: Wed, 17 Jan 2018 19:38:51 +0100 Subject: tty: refactor to es6 PR-URL: https://github.com/nodejs/node/pull/17615 Reviewed-By: James M Snell Reviewed-By: Matteo Collina --- lib/tty.js | 30 +++++++++++------------------- 1 file changed, 11 insertions(+), 19 deletions(-) (limited to 'lib/tty.js') 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 }; -- cgit v1.2.3