Skip to content

Commit

Permalink
use chalk for base reporter colors; closes #1200
Browse files Browse the repository at this point in the history
  • Loading branch information
boneskull committed Dec 2, 2015
1 parent 67d0fac commit 1192914
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 21 deletions.
42 changes: 22 additions & 20 deletions lib/reporters/base.js
Expand Up @@ -7,6 +7,8 @@ var diff = require('diff');
var ms = require('../ms');
var utils = require('../utils');
var supportsColor = process.browser ? null : require('supports-color');
var chalk = require('chalk');
chalk.enabled = supportsColor;

/**
* Expose `Base`.
Expand Down Expand Up @@ -50,25 +52,25 @@ exports.inlineDiffs = false;
*/

exports.colors = {
pass: 90,
fail: 31,
'bright pass': 92,
'bright fail': 91,
'bright yellow': 93,
pending: 36,
suite: 0,
'error title': 0,
'error message': 31,
'error stack': 90,
checkmark: 32,
fast: 90,
medium: 33,
slow: 31,
green: 32,
light: 90,
'diff gutter': 90,
'diff added': 32,
'diff removed': 31
pass: chalk.gray,
fail: chalk.red,
'bright pass': chalk.green.bold,
'bright fail': chalk.red.bold,
'bright yellow': chalk.yellow.bold,
pending: chalk.cyan,
suite: chalk.white,
'error title': chalk.gray,
'error message': chalk.red,
'error stack': chalk.white,
checkmark: chalk.green,
fast: chalk.gray,
medium: chalk.yellow,
slow: chalk.red,
green: chalk.green,
light: chalk.white.bold,
'diff gutter': chalk.gray,
'diff added': chalk.green,
'diff removed': chalk.red
};

/**
Expand Down Expand Up @@ -103,7 +105,7 @@ var color = exports.color = function(type, str) {
if (!exports.useColors) {
return String(str);
}
return '\u001b[' + exports.colors[type] + 'm' + str + '\u001b[0m';
return '\u001b[' + exports.colors[type](str) + '\u001b[0m';

This comment has been minimized.

Copy link
@octref

octref Dec 2, 2015

If I remember correctly, you don't need the beginning \u001b[ if you are using chalk, or do you?

This comment has been minimized.

Copy link
@octref

octref Dec 2, 2015

And you can use chalk's reset at the end of string instead of \u001b[0m. @boneskull

This comment has been minimized.

Copy link
@boneskull

boneskull Dec 2, 2015

Author Member

I don't know. I'll take a look. I can't imagine we'd need reset()...

This comment has been minimized.

Copy link
@octref

octref Dec 2, 2015

@boneskull reset is for making sure the current style doesn't infect the string after it. \u001b[0m is for the same purpose.

This comment has been minimized.

Copy link
@boneskull

boneskull Dec 2, 2015

Author Member

I understand that, but I just would imagine chalk would take care of this for you

This comment has been minimized.

Copy link
@rstacruz

rstacruz Jan 27, 2016

Contributor

chalk will take care of this for you.

return exports.colors[type](str);

...will do just fine.

};

/**
Expand Down
3 changes: 2 additions & 1 deletion package.json
Expand Up @@ -274,6 +274,7 @@
"test": "make test-all"
},
"dependencies": {
"chalk": "0.4.0",
"commander": "2.3.0",
"debug": "2.2.0",
"diff": "1.4.0",
Expand Down Expand Up @@ -312,4 +313,4 @@
"url": "https://raw.github.com/mochajs/mocha/master/LICENSE"
}
]
}
}

7 comments on commit 1192914

@mroien
Copy link

@mroien mroien commented on 1192914 Jan 26, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Chalk update breaks colors in terminal in 2.4.1 works fine in 2.3.4. It does not show the colors only shows the color codes [[1m

@danielstjules
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

screen shot 2016-01-26 at 1 48 36 pm

What shell are you using? (edit: pending dots seem larger with chalk)

@jbnicolai
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can confirm it works locally for me as well. @mrjoelkemp as Daniel asked, what shell + OS + terminal emulator are you using?

I'm double interested, as I've helped develop Chalk ;-)

@mroien
Copy link

@mroien mroien commented on 1192914 Jan 26, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am using Z shell through Webstorm. Another person having same error is running Cmder with Powershell

@jbnicolai
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mrjoelkemp could you confirm that your shell supports color codes by placing, e.g.:

console.log("\033[31m Hello World")

somewhere in your test, and confirming the printed string is red?

@thedark1337
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in Strict mode that throws but I tested it in non strict and it works fine in red: hello world

I fixed the issue in a pull request: #2072

Fixed

@jbnicolai
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I had missed the PR, thanks for creating one. Let's continue the discussion there.

Please sign in to comment.