Skip to content

Commit

Permalink
readline: lazy loaded
Browse files Browse the repository at this point in the history
PR-URL: #20567
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
  • Loading branch information
BridgeAR authored and MylesBorins committed May 22, 2018
1 parent 4a92da1 commit 3eb38de
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/tty.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@ const net = require('net');
const { TTY, isTTY } = process.binding('tty_wrap');
const errors = require('internal/errors');
const { ERR_INVALID_FD, ERR_TTY_INIT_FAILED } = errors.codes;
const readline = require('readline');
const { getColorDepth } = require('internal/tty');

// Lazy loaded for startup performance.
let readline;

function isatty(fd) {
return Number.isInteger(fd) && fd >= 0 && isTTY(fd);
}
Expand Down Expand Up @@ -122,15 +124,19 @@ WriteStream.prototype._refreshSize = function() {

// Backwards-compat
WriteStream.prototype.cursorTo = function(x, y) {
if (readline === undefined) readline = require('readline');
readline.cursorTo(this, x, y);
};
WriteStream.prototype.moveCursor = function(dx, dy) {
if (readline === undefined) readline = require('readline');
readline.moveCursor(this, dx, dy);
};
WriteStream.prototype.clearLine = function(dir) {
if (readline === undefined) readline = require('readline');
readline.clearLine(this, dir);
};
WriteStream.prototype.clearScreenDown = function() {
if (readline === undefined) readline = require('readline');
readline.clearScreenDown(this);
};
WriteStream.prototype.getWindowSize = function() {
Expand Down

0 comments on commit 3eb38de

Please sign in to comment.