From bec7a6e1686cf1f4c26ef6c2ba25eda36ccdd6c5 Mon Sep 17 00:00:00 2001 From: Jaakko Salonen Date: Wed, 7 Nov 2012 10:35:35 -0800 Subject: [PATCH] fix unicode chars on windows --- lib/reporters/base.js | 21 +++++++++++++++++++-- lib/reporters/dot.js | 9 ++++----- lib/reporters/list.js | 2 +- lib/reporters/progress.js | 2 +- lib/reporters/spec.js | 4 ++-- 5 files changed, 27 insertions(+), 11 deletions(-) diff --git a/lib/reporters/base.js b/lib/reporters/base.js index 2178963fb2..f716fd4a54 100644 --- a/lib/reporters/base.js +++ b/lib/reporters/base.js @@ -61,6 +61,23 @@ exports.colors = { , 'diff removed': 41 }; +/** + * Default symbol map. + */ + +exports.symbols = { + ok: '✔', + err: '✖', + dot: '․' +}; + +// With node.js on Windows: use symbols available in terminal default fonts +if (process && 'win32' == process.platform) { + exports.symbols.ok = '\u221A'; + exports.symbols.err = '\u00D7'; + exports.symbols.dot = '.'; +} + /** * Color `str` with the given `type`, * allowing colors to be disabled, @@ -277,7 +294,7 @@ Base.prototype.epilogue = function(){ // failure if (stats.failures) { - fmt = color('bright fail', ' ✖') + fmt = color('bright fail', ' ' + exports.symbols.err) + color('fail', ' %d of %d %s failed') + color('light', ':') @@ -292,7 +309,7 @@ Base.prototype.epilogue = function(){ } // pass - fmt = color('bright pass', ' ✔') + fmt = color('bright pass', ' ' + exports.symbols.ok) + color('green', ' %d %s complete') + color('light', ' (%s)'); diff --git a/lib/reporters/dot.js b/lib/reporters/dot.js index c6403150ba..0c298ba71d 100644 --- a/lib/reporters/dot.js +++ b/lib/reporters/dot.js @@ -25,7 +25,6 @@ function Dot(runner) { var self = this , stats = this.stats , width = Base.window.width * .75 | 0 - , c = '․' , n = 0; runner.on('start', function(){ @@ -33,21 +32,21 @@ function Dot(runner) { }); runner.on('pending', function(test){ - process.stdout.write(color('pending', c)); + process.stdout.write(color('pending', Base.symbols.dot)); }); runner.on('pass', function(test){ if (++n % width == 0) process.stdout.write('\n '); if ('slow' == test.speed) { - process.stdout.write(color('bright yellow', c)); + process.stdout.write(color('bright yellow', Base.symbols.dot)); } else { - process.stdout.write(color(test.speed, c)); + process.stdout.write(color(test.speed, Base.symbols.dot)); } }); runner.on('fail', function(test, err){ if (++n % width == 0) process.stdout.write('\n '); - process.stdout.write(color('fail', c)); + process.stdout.write(color('fail', Base.symbols.dot)); }); runner.on('end', function(){ diff --git a/lib/reporters/list.js b/lib/reporters/list.js index 1a88989388..3328e157a8 100644 --- a/lib/reporters/list.js +++ b/lib/reporters/list.js @@ -42,7 +42,7 @@ function List(runner) { }); runner.on('pass', function(test){ - var fmt = color('checkmark', ' ✓') + var fmt = color('checkmark', ' '+Base.symbols.dot) + color('pass', ' %s: ') + color(test.speed, '%dms'); cursor.CR(); diff --git a/lib/reporters/progress.js b/lib/reporters/progress.js index 143b1a0d89..59536386cb 100644 --- a/lib/reporters/progress.js +++ b/lib/reporters/progress.js @@ -41,7 +41,7 @@ function Progress(runner, options) { // default chars options.open = options.open || '['; options.complete = options.complete || '▬'; - options.incomplete = options.incomplete || '⋅'; + options.incomplete = options.incomplete || Base.symbols.dot; options.close = options.close || ']'; options.verbose = false; diff --git a/lib/reporters/spec.js b/lib/reporters/spec.js index e546314dcf..cd97261c12 100644 --- a/lib/reporters/spec.js +++ b/lib/reporters/spec.js @@ -58,13 +58,13 @@ function Spec(runner) { runner.on('pass', function(test){ if ('fast' == test.speed) { var fmt = indent() - + color('checkmark', ' ✓') + + color('checkmark', ' ' + Base.symbols.ok) + color('pass', ' %s '); cursor.CR(); console.log(fmt, test.title); } else { var fmt = indent() - + color('checkmark', ' ✓') + + color('checkmark', ' ' + Base.symbols.ok) + color('pass', ' %s ') + color(test.speed, '(%dms)'); cursor.CR();