mirror of
https://github.com/debug-js/debug.git
synced 2026-02-01 17:20:44 +00:00
pad diff with same color
This commit is contained in:
parent
d7333c6ac6
commit
71cd41cfd5
@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
17
lib/debug.js
17
lib/debug.js
@ -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);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user