From e57ea6b05f71add02dcfe5f7e4e9dace6b25868f Mon Sep 17 00:00:00 2001 From: David da Silva Date: Mon, 15 Dec 2014 02:28:40 +0100 Subject: [PATCH] fixes #1461: nyan-reporter now respects Base.useColors, fixed bug where Base.color would not return a string when str wasn't a string. --- lib/reporters/base.js | 2 +- lib/reporters/nyan.js | 26 +++++++++++++------------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/lib/reporters/base.js b/lib/reporters/base.js index 6d51fcfdd0..abbeb0119f 100644 --- a/lib/reporters/base.js +++ b/lib/reporters/base.js @@ -97,7 +97,7 @@ if ('win32' == process.platform) { */ var color = exports.color = function(type, str) { - if (!exports.useColors) return str; + if (!exports.useColors) return String(str); return '\u001b[' + exports.colors[type] + 'm' + str + '\u001b[0m'; }; diff --git a/lib/reporters/nyan.js b/lib/reporters/nyan.js index a8d43bf5ff..63056b1777 100644 --- a/lib/reporters/nyan.js +++ b/lib/reporters/nyan.js @@ -2,8 +2,7 @@ * Module dependencies. */ -var Base = require('./base') - , color = Base.color; +var Base = require('./base'); /** * Expose `Dot`. @@ -80,17 +79,16 @@ NyanCat.prototype.draw = function(){ NyanCat.prototype.drawScoreboard = function(){ var stats = this.stats; - var colors = Base.colors; - function draw(color, n) { + function draw(type, n) { write(' '); - write('\u001b[' + color + 'm' + n + '\u001b[0m'); + write(Base.color(type, n)); write('\n'); } - draw(colors.green, stats.passes); - draw(colors.fail, stats.failures); - draw(colors.pending, stats.pending); + draw('green', stats.passes); + draw('fail', stats.failures); + draw('pending', stats.pending); write('\n'); this.cursorUp(this.numberOfLines); @@ -140,26 +138,26 @@ NyanCat.prototype.drawRainbow = function(){ NyanCat.prototype.drawNyanCat = function() { var self = this; var startWidth = this.scoreboardWidth + this.trajectories[0].length; - var color = '\u001b[' + startWidth + 'C'; + var dist = '\u001b[' + startWidth + 'C'; var padding = ''; - write(color); + write(dist); write('_,------,'); write('\n'); - write(color); + write(dist); padding = self.tick ? ' ' : ' '; write('_|' + padding + '/\\_/\\ '); write('\n'); - write(color); + write(dist); padding = self.tick ? '_' : '__'; var tail = self.tick ? '~' : '^'; var face; write(tail + '|' + padding + this.face() + ' '); write('\n'); - write(color); + write(dist); padding = self.tick ? ' ' : ' '; write(padding + '"" "" '); write('\n'); @@ -240,6 +238,8 @@ NyanCat.prototype.generateColors = function(){ */ NyanCat.prototype.rainbowify = function(str){ + if (!Base.useColors) + return str; var color = this.rainbowColors[this.colorIndex % this.rainbowColors.length]; this.colorIndex += 1; return '\u001b[38;5;' + color + 'm' + str + '\u001b[0m';