diff --git a/lib/tty.js b/lib/tty.js index 4e9023b0eb6114..b36adf2534c326 100644 --- a/lib/tty.js +++ b/lib/tty.js @@ -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); } @@ -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() {