Skip to content

Commit

Permalink
don't include ansi color codes when outputting to a file or pipe
Browse files Browse the repository at this point in the history
  • Loading branch information
dylang committed Aug 16, 2011
1 parent 08e9657 commit cc71f62
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
7 changes: 4 additions & 3 deletions lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ var Github = require('./github');
var Npm = require('./npm');
var log = require('./log');
var FS = require('fs');
var Util = require('./util');

CLI.setUsage('changelog <npm module name or github repo url> [OPTIONS]').parse({
color: ['c', 'Output as Color (default)'],
markdown: ['m', 'Output as Github-flavored Markdown'],
color: ['c', 'Output as Color (terminal default)'],
markdown: ['m', 'Output as Github-flavored Markdown (file default)'],
json: ['j', 'Output as JSON'],
debug: ['d', 'Enable debugging']
});
Expand All @@ -27,7 +28,7 @@ CLI.main(function (args, options) {
}
}

var output = options.json ? Output.json : options.markdown ? Output.markdown : Output.color;
var output = options.json ? Output.json : options.markdown ? Output.markdown : Util.enableColor() ? Output.color : Output.markdown;


Step(
Expand Down
14 changes: 10 additions & 4 deletions lib/util.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
var log = require('logging').from(__filename);
var WordWrap = require('wordwrap');
var log = require('logging').from(__filename);
var WordWrap = require('wordwrap');
var TTY = require('tty');

var wordwrap;

Expand All @@ -9,7 +10,7 @@ function padZero(n) {

function initWordWrap(width){
if (!width) {
width = require('tty').getWindowSize()[1];
width = TTY.getWindowSize()[1];
}

wordwrap = WordWrap(4, width);
Expand All @@ -23,7 +24,12 @@ function bullet(string, bulletCharacter) {
return ' ' + (bulletCharacter || '*') + ' ' + wordwrap(string).trim();
}

function enableColor() {
return TTY.isatty(1);
}

module.exports = {
padZero: padZero,
bullet: bullet
bullet: bullet,
enableColor: enableColor
};

0 comments on commit cc71f62

Please sign in to comment.