Skip to content

Commit

Permalink
fixup: remove colors
Browse files Browse the repository at this point in the history
  • Loading branch information
BridgeAR committed Nov 26, 2019
1 parent 1a7de34 commit ea09aa5
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 25 deletions.
4 changes: 1 addition & 3 deletions lib/internal/util/inspect.js
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,6 @@ ObjectDefineProperty(inspect, 'defaultOptions', {
}
});

// TODO(BridgeAR): Add further color codes.
// http://en.wikipedia.org/wiki/ANSI_escape_code#graphics
inspect.colors = ObjectAssign(ObjectCreate(null), {
bold: [1, 22],
Expand All @@ -272,8 +271,7 @@ inspect.colors = ObjectAssign(ObjectCreate(null), {
green: [32, 39],
magenta: [35, 39],
red: [31, 39],
yellow: [33, 39],
brightRed: [91, 39]
yellow: [33, 39]
});

// Don't use 'blue' not visible on cmd.exe
Expand Down
15 changes: 2 additions & 13 deletions lib/repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -550,14 +550,9 @@ function REPLServer(prompt,
errStack = self.writer(e);
}
const lines = errStack.split(/(?<=\n)/);
let colors = '';
if (options.useColors) {
colors = `\u001b[${inspect.colors.brightRed[0]}m` +
`\u001b[${inspect.colors.bold[0]}m`;
}
let matched = false;

errStack = colors;
errStack = '';
for (const line of lines) {
if (!matched && /^\[?([A-Z][a-z0-9_]*)*Error/.test(line)) {
errStack += writer.options.breakLength >= line.length ?
Expand All @@ -570,16 +565,10 @@ function REPLServer(prompt,
}
if (!matched) {
const ln = lines.length === 1 ? ' ' : ':\n';
// eslint-disable-next-line no-control-regex
errStack = errStack.replace(/\u001b\[[0-9]{1,3}m/g, '');
errStack = `${colors}Uncaught${ln}${errStack}`;
errStack = `Uncaught${ln}${errStack}`;
}
// Normalize line endings.
errStack += errStack.endsWith('\n') ? '' : '\n';
if (options.useColors) {
errStack += `\u001b[${inspect.colors.brightRed[1]}m` +
`\u001b[${inspect.colors.bold[1]}m`;
}
top.outputStream.write(errStack);
top.clearBufferedCommand();
top.lines.level = [];
Expand Down
5 changes: 2 additions & 3 deletions test/parallel/test-repl-pretty-stack.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,8 @@ const tests = [
{
command: '(() => { const err = Error(\'Whoops!\'); ' +
'err.foo = \'bar\'; throw err; })()',
expected: '\u001b[91m\u001b[1m' +
'Uncaught Error: Whoops!\n at repl:*:* {\n foo: ' +
"\u001b[32m'bar'\u001b[39m\n}\n\u001b[39m\u001b[22m",
expected: 'Uncaught Error: Whoops!\n at repl:*:* {\n foo: ' +
"\u001b[32m'bar'\u001b[39m\n}\n",
useColors: true
},
{
Expand Down
8 changes: 2 additions & 6 deletions test/parallel/test-repl-uncaught-exception.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,12 @@ const tests = [
{
useColors: true,
command: 'x',
expected: '\u001b[91m\u001b[1m' +
'Uncaught ReferenceError: x is not defined\n' +
'\u001b[39m\u001b[22m'
expected: 'Uncaught ReferenceError: x is not defined\n'
},
{
useColors: true,
command: 'throw { foo: "test" }',
expected: '\u001b[91m\u001b[1m' +
"Uncaught { foo: 'test' }\n" +
'\u001b[39m\u001b[22m'
expected: "Uncaught { foo: \x1B[32m'test'\x1B[39m }\n"
},
{
command: 'process.on("uncaughtException", () => console.log("Foobar"));\n',
Expand Down

0 comments on commit ea09aa5

Please sign in to comment.