Skip to content

Commit e92c1e4

Browse files
ashtuchkinindexzero
authored andcommitted
Added --no-color option to suppress terminal colors
1 parent 8788a52 commit e92c1e4

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

bin/vows

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ var help = [
5959
" --cover-plain Print plain coverage map if detected",
6060
" --cover-html Write coverage map to \"coverage.html\"",
6161
" --cover-json Write unified coverage map to \"coverage.json\"",
62-
//" --no-color Don't use terminal colors",
62+
" --no-color Don't use terminal colors",
6363
" --version Show version",
6464
" -h, --help You're staring at it"
6565
].join('\n');
@@ -69,7 +69,8 @@ var options = {
6969
matcher: /.*/,
7070
watch: false,
7171
coverage: false,
72-
isolate: false
72+
isolate: false,
73+
nocolor: !process.stdout.isTTY
7374
};
7475

7576
var files = [];
@@ -151,6 +152,9 @@ while (arg = argv.shift()) {
151152
case 'no-color':
152153
options.nocolor = true;
153154
break;
155+
case 'color':
156+
options.nocolor = false;
157+
break;
154158
case 'no-error':
155159
options.error = false;
156160
break;
@@ -167,6 +171,11 @@ while (arg = argv.shift()) {
167171
}
168172
}
169173

174+
if (options.nocolor) {
175+
cutils.nocolor = true;
176+
inspect = require('eyes').inspector({ stream: null, styles: false });
177+
}
178+
170179
if (options.supressStdout) {
171180
_reporter.setStream && _reporter.setStream(process.stdout);
172181
var devNullStream = fs.createWriteStream('/dev/null');

lib/vows/console.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ var eyes = require('eyes').inspector({ stream: null, styles: false });
22

33
// Stylize a string
44
this.stylize = function stylize(str, style) {
5+
if (module.exports.nocolor)
6+
return str;
7+
58
var styles = {
69
'bold' : [1, 22],
710
'italic' : [3, 23],
@@ -85,6 +88,8 @@ this.result = function (event) {
8588
};
8689

8790
this.inspect = function inspect(val) {
91+
if (module.exports.nocolor)
92+
return eyes(val);
8893
return '\033[1m' + eyes(val) + '\033[22m';
8994
};
9095

0 commit comments

Comments
 (0)