Permalink
Browse files

Experiment on disabling colors.

  • Loading branch information...
1 parent 8ff594b commit 1a53c8529dfbe3554b659723c47fabcb36a854bc Marcin Bunsch committed Jun 12, 2011
Showing with 44 additions and 16 deletions.
  1. +2 −1 bin/jessie
  2. +24 −0 lib/jessie/colors.js
  3. +7 −7 lib/jessie/formatters/nested.js
  4. +8 −8 lib/jessie/formatters/progress.js
  5. +3 −0 lib/jessie/runner.js
View
@@ -20,7 +20,8 @@ cli.setApp(pkg.name, pkg.version)
cli.setUsage('jessie [OPTIONS] [spec dirs/files]')
cli.parse({
- format: ['f', 'Output format to use', 'string', 'progress']
+ format: ['f', 'Output format to use', 'string', 'progress'],
+ nocolor: ['n', 'Disabled colored output']
}, null);
process.on('uncaughtException', function (err) {
View
@@ -0,0 +1,24 @@
+var codes = {
+ grey: '\033[90m',
+ green: '\033[32m',
+ red: '\033[31m',
+ yellow: '\033[33m',
+ clear: '\033[0m'
+}
+
+var colorizer = {
+ enabled: true,
+ colorize: function(string, color) {
+ if (this.enabled) {
+ return codes[color] + string + codes.clear;
+ } else {
+ return string;
+ }
+ },
+ grey: function(string) { return this.colorize(string, 'grey'); },
+ green: function(string) { return this.colorize(string, 'green'); },
+ yellow: function(string) { return this.colorize(string, 'yellow'); },
+ red: function(string) { return this.colorize(string, 'red'); },
+}
+
+module.exports = colorizer
@@ -1,6 +1,6 @@
var sys = require('sys')
var fs = require('fs')
-var ansi = require('jessie/ansi')
+var colors = require('jessie/colors')
exports.formatter = {
start: function() {
@@ -11,11 +11,11 @@ exports.formatter = {
},
spec: function(result, spec) {
if (result.pending) {
- sys.puts(ansi.yellow + spec.description + ansi.none)
+ sys.puts(colors.yellow(spec.description))
} else if (result.fail) {
- sys.puts(ansi.red + spec.description + ansi.none)
+ sys.puts(colors.red(spec.description))
} else {
- sys.puts(ansi.green + spec.description + ansi.none)
+ sys.puts(colors.green(spec.description))
}
},
suiteStart: function(suite) {
@@ -27,11 +27,11 @@ exports.formatter = {
this.depth -= 1
},
finish: function(result, runner) {
- if (result.failures.length > 0)
+ if (result.failures.length > 0)
this.reporter.printFailures(result.failures)
- if (result.pendings && result.pendings.length > 0)
+ if (result.pendings && result.pendings.length > 0)
this.reporter.printPendings(result.pendings)
-
+
this.reporter.printSummary(result)
},
printDepth: function() {
@@ -1,24 +1,24 @@
var sys = require('sys')
var fs = require('fs')
-var ansi = require('jessie/ansi')
+var colors = require('jessie/colors')
exports.formatter = {
spec: function(result, spec) {
if (result.pending) {
- sys.print(ansi.yellow + '*' + ansi.none)
+ sys.print(colors.yellow('*'))
} else if (result.fail) {
- sys.print(ansi.red + 'F' + ansi.none)
+ sys.print(colors.red('F'))
} else {
- sys.print(ansi.green + '.' + ansi.none)
+ sys.print(colors.green('.'))
}
},
finish: function(result, runner) {
- sys.puts('')
- if (result.failures.length > 0)
+ sys.puts('')
+ if (result.failures.length > 0)
this.reporter.printFailures(result.failures)
- if (result.pendings && result.pendings.length > 0)
+ if (result.pendings && result.pendings.length > 0)
this.reporter.printPendings(result.pendings)
-
+
this.reporter.printSummary(result)
}
}
View
@@ -1,4 +1,7 @@
exports.runner = function(args, options, callback) {
+ if (options.nocolor) {
+ require('jessie/colors').enabled = false
+ }
this.jasmine = jasmine.getEnv();
this.finder = new (require('jessie/finder')).finder(),
this.reporter = new (require('jessie/reporter')).reporter(options.format, callback)

0 comments on commit 1a53c85

Please sign in to comment.