From 71cd41cfd5146c7af35fb01f02735ee2bbcb5149 Mon Sep 17 00:00:00 2001 From: Tj Holowaychuk Date: Wed, 1 Feb 2012 11:52:24 -0800 Subject: [PATCH] pad diff with same color --- example/worker.js | 2 +- lib/debug.js | 17 +++++++++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/example/worker.js b/example/worker.js index beea841..e17a3e3 100644 --- a/example/worker.js +++ b/example/worker.js @@ -3,7 +3,7 @@ var a = require('../')('worker a') , b = require('../')('worker b'); function work() { - a('doing some larger work'); + a('doing lots of uninteresting work'); setTimeout(work, Math.random() * 1000); } diff --git a/lib/debug.js b/lib/debug.js index 5212d57..a765de1 100644 --- a/lib/debug.js +++ b/lib/debug.js @@ -69,6 +69,19 @@ function color() { 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`. * @@ -92,8 +105,8 @@ function debug(name) { fmt = ' \033[9' + c + 'm' + name + ' ' + '\033[3' + c + 'm\033[90m' - + fmt + '\033[90m' - + ' +' + ms + 'ms\033[0m'; + + fmt + '\033[3' + c + 'm' + + ' ' + pad(ms, 40 - fmt.length) + 'ms\033[0m'; console.log.apply(this, arguments); }