- `eval` - function that will be used to eval each given line. Defaults to
an async wrapper for `eval()`. See below for an example of a custom `eval`.
+ - `useColors` - a boolean which specifies whether or not the `writer` function
+ should output colors. If a different `writer` function is set then this does
+ nothing. Defaults to the repl's `terminal` value.
+
- `useGlobal` - if set to `true`, then the repl will use the `global` object,
instead of running scripts in a separate context. Defaults to `false`.
}).join(',\n');
-function SourceUnderline(sourceText, position, tty) {
+function SourceUnderline(sourceText, position, repl) {
if (!sourceText) return '';
var head = sourceText.slice(0, position),
tail = sourceText.slice(position);
// Colourize char if stdout supports colours
- if (tty && !repl.disableColors) {
+ if (repl.useColors) {
tail = tail.replace(/(.+?)([^\w]|$)/, '\033[32m$1\033[39m$2');
}
if (parseInt(process.env['NODE_NO_READLINE'], 10)) {
opts.terminal = false;
}
+ if (parseInt(process.env['NODE_DISABLE_COLORS'], 10)) {
+ opts.useColors = false;
+ }
this.repl = repl.start(opts);
// Do not print useless warning
if (current) {
line = SourceUnderline(lines[i],
client.currentSourceColumn,
- self.stdout.isTTY);
+ self.repl);
} else {
line = lines[i];
}
var context;
-exports.disableColors = process.env.NODE_DISABLE_COLORS ? true : false;
-
// hack for require.resolve("./relative") to work properly.
module.filename = path.resolve('repl');
// figure out which "writer" function to use
self.writer = options.writer || exports.writer;
- if (rli.terminal && !exports.disableColors &&
- self.writer === util.inspect) {
+ if (typeof options.useColors === 'undefined') {
+ options.useColors = rli.terminal;
+ }
+ self.useColors = !!options.useColors;
+
+ if (self.useColors && self.writer === util.inspect) {
// Turn on ANSI coloring.
self.writer = function(obj, showHidden, depth) {
return util.inspect(obj, showHidden, depth, true);
if (parseInt(process.env['NODE_NO_READLINE'], 10)) {
opts.terminal = false;
}
+ if (parseInt(process.env['NODE_DISABLE_COLORS'], 10)) {
+ opts.useColors = false;
+ }
var repl = Module.requireRepl().start(opts);
repl.on('exit', function() {
process.exit();
assert.equal(r1.rli.input, r1.inputStream);
assert.equal(r1.rli.output, r1.outputStream);
assert.equal(r1.rli.terminal, true);
+assert.equal(r1.useColors, r1.rli.terminal);
assert.equal(r1.useGlobal, false);
assert.equal(r1.ignoreUndefined, false);
input: stream,
output: stream,
terminal: false,
+ useColors: true,
useGlobal: true,
ignoreUndefined: true,
eval: evaler,
assert.equal(r2.rli.input, r2.inputStream);
assert.equal(r2.rli.output, r2.outputStream);
assert.equal(r2.rli.terminal, false);
+assert.equal(r2.useColors, true);
assert.equal(r2.useGlobal, true);
assert.equal(r2.ignoreUndefined, true);
assert.equal(r2.eval, evaler);