mirror of
https://github.com/zebrajr/node.git
synced 2025-12-06 12:20:27 +01:00
tty: refactor to es6
Backport-PR-URL: https://github.com/nodejs/node/pull/19230 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>
This commit is contained in:
parent
ead727c274
commit
74f0d1aa60
22
lib/tty.js
22
lib/tty.js
|
|
@ -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);
|
||||
|
|
@ -66,7 +65,6 @@ ReadStream.prototype.setRawMode = function(flag) {
|
|||
this.isRaw = flag;
|
||||
};
|
||||
|
||||
|
||||
function WriteStream(fd) {
|
||||
if (!(this instanceof WriteStream))
|
||||
return new WriteStream(fd);
|
||||
|
|
@ -86,8 +84,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];
|
||||
|
|
@ -95,7 +93,6 @@ function WriteStream(fd) {
|
|||
}
|
||||
inherits(WriteStream, net.Socket);
|
||||
|
||||
|
||||
WriteStream.prototype.isTTY = true;
|
||||
|
||||
WriteStream.prototype.getColorDepth = function(env = process.env) {
|
||||
|
|
@ -164,16 +161,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', 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;
|
||||
|
|
@ -181,8 +177,7 @@ WriteStream.prototype._refreshSize = function() {
|
|||
}
|
||||
};
|
||||
|
||||
|
||||
// backwards-compat
|
||||
// Backwards-compat
|
||||
WriteStream.prototype.cursorTo = function(x, y) {
|
||||
readline.cursorTo(this, x, y);
|
||||
};
|
||||
|
|
@ -199,5 +194,4 @@ WriteStream.prototype.getWindowSize = function() {
|
|||
return [this.columns, this.rows];
|
||||
};
|
||||
|
||||
|
||||
module.exports = { isatty, ReadStream, WriteStream };
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user