2015-04-23 00:35:53 -07:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const REPL = require('repl');
|
2019-02-01 12:49:16 -05:00
|
|
|
|
2015-05-04 01:40:40 -07:00
|
|
|
module.exports = Object.create(REPL);
|
2018-02-11 19:17:03 +01:00
|
|
|
module.exports.createInternalRepl = createRepl;
|
2015-05-04 01:40:40 -07:00
|
|
|
|
2018-02-11 19:17:03 +01:00
|
|
|
function createRepl(env, opts, cb) {
|
2015-08-01 22:38:28 -07:00
|
|
|
if (typeof opts === 'function') {
|
|
|
|
cb = opts;
|
|
|
|
opts = null;
|
|
|
|
}
|
2018-12-18 03:15:57 +01:00
|
|
|
opts = {
|
2015-05-02 23:47:17 +02:00
|
|
|
ignoreUndefined: false,
|
|
|
|
terminal: process.stdout.isTTY,
|
2016-07-19 14:41:47 -04:00
|
|
|
useGlobal: true,
|
2018-12-18 03:15:57 +01:00
|
|
|
breakEvalOnSigint: true,
|
|
|
|
...opts
|
|
|
|
};
|
2015-04-23 00:35:53 -07:00
|
|
|
|
|
|
|
if (parseInt(env.NODE_NO_READLINE)) {
|
|
|
|
opts.terminal = false;
|
|
|
|
}
|
2017-06-22 18:47:44 +02:00
|
|
|
// The "dumb" special terminal, as defined by terminfo, doesn't support
|
2017-12-05 07:03:04 -08:00
|
|
|
// ANSI color control codes.
|
2015-09-05 18:03:46 +03:00
|
|
|
// see http://invisible-island.net/ncurses/terminfo.ti.html#toc-_Specials
|
|
|
|
if (parseInt(env.NODE_DISABLE_COLORS) || env.TERM === 'dumb') {
|
2015-04-23 00:35:53 -07:00
|
|
|
opts.useColors = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
opts.replMode = {
|
|
|
|
'strict': REPL.REPL_MODE_STRICT,
|
2017-02-27 18:45:53 -08:00
|
|
|
'sloppy': REPL.REPL_MODE_SLOPPY
|
2015-04-23 00:35:53 -07:00
|
|
|
}[String(env.NODE_REPL_MODE).toLowerCase().trim()];
|
|
|
|
|
|
|
|
if (opts.replMode === undefined) {
|
2017-02-27 18:45:53 -08:00
|
|
|
opts.replMode = REPL.REPL_MODE_SLOPPY;
|
2015-04-23 00:35:53 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
const historySize = Number(env.NODE_REPL_HISTORY_SIZE);
|
2018-02-13 00:56:35 +01:00
|
|
|
if (!Number.isNaN(historySize) && historySize > 0) {
|
2015-04-23 00:35:53 -07:00
|
|
|
opts.historySize = historySize;
|
|
|
|
} else {
|
|
|
|
opts.historySize = 1000;
|
|
|
|
}
|
|
|
|
|
|
|
|
const repl = REPL.start(opts);
|
2019-02-01 12:49:16 -05:00
|
|
|
repl.setupHistory(opts.terminal ? env.NODE_REPL_HISTORY : '', cb);
|
2015-04-23 00:35:53 -07:00
|
|
|
}
|