pad diff with same color

This commit is contained in:
Tj Holowaychuk 2012-02-01 11:52:24 -08:00
parent d7333c6ac6
commit 71cd41cfd5
2 changed files with 16 additions and 3 deletions

View File

@ -3,7 +3,7 @@ var a = require('../')('worker a')
, b = require('../')('worker b'); , b = require('../')('worker b');
function work() { function work() {
a('doing some larger work'); a('doing lots of uninteresting work');
setTimeout(work, Math.random() * 1000); setTimeout(work, Math.random() * 1000);
} }

View File

@ -69,6 +69,19 @@ function color() {
return colors[prevColor++ % colors.length]; return colors[prevColor++ % colors.length];
} }
/**
* Pad the given `str` to `len`.
*
* @param {String} str
* @param {String} len
* @return {String}
* @api private
*/
function pad(str, len) {
return Array(Math.max(len, 1)).join(' ') + str;
}
/** /**
* Create a debugger with the given `name`. * Create a debugger with the given `name`.
* *
@ -92,8 +105,8 @@ function debug(name) {
fmt = ' \033[9' + c + 'm' + name + ' ' fmt = ' \033[9' + c + 'm' + name + ' '
+ '\033[3' + c + 'm\033[90m' + '\033[3' + c + 'm\033[90m'
+ fmt + '\033[90m' + fmt + '\033[3' + c + 'm'
+ ' +' + ms + 'ms\033[0m'; + ' ' + pad(ms, 40 - fmt.length) + 'ms\033[0m';
console.log.apply(this, arguments); console.log.apply(this, arguments);
} }