Skip to content

Commit 3eb38de

Browse files
BridgeARMylesBorins
authored andcommitted
readline: lazy loaded
PR-URL: #20567 Reviewed-By: Gus Caplan <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Jeremiah Senkpiel <[email protected]>
1 parent 4a92da1 commit 3eb38de

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

lib/tty.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,11 @@ const net = require('net');
2626
const { TTY, isTTY } = process.binding('tty_wrap');
2727
const errors = require('internal/errors');
2828
const { ERR_INVALID_FD, ERR_TTY_INIT_FAILED } = errors.codes;
29-
const readline = require('readline');
3029
const { getColorDepth } = require('internal/tty');
3130

31+
// Lazy loaded for startup performance.
32+
let readline;
33+
3234
function isatty(fd) {
3335
return Number.isInteger(fd) && fd >= 0 && isTTY(fd);
3436
}
@@ -122,15 +124,19 @@ WriteStream.prototype._refreshSize = function() {
122124

123125
// Backwards-compat
124126
WriteStream.prototype.cursorTo = function(x, y) {
127+
if (readline === undefined) readline = require('readline');
125128
readline.cursorTo(this, x, y);
126129
};
127130
WriteStream.prototype.moveCursor = function(dx, dy) {
131+
if (readline === undefined) readline = require('readline');
128132
readline.moveCursor(this, dx, dy);
129133
};
130134
WriteStream.prototype.clearLine = function(dir) {
135+
if (readline === undefined) readline = require('readline');
131136
readline.clearLine(this, dir);
132137
};
133138
WriteStream.prototype.clearScreenDown = function() {
139+
if (readline === undefined) readline = require('readline');
134140
readline.clearScreenDown(this);
135141
};
136142
WriteStream.prototype.getWindowSize = function() {

0 commit comments

Comments
 (0)