From 5b230007adba91163a2f49dbdd9a16d5834fd322 Mon Sep 17 00:00:00 2001 From: Alex Kocharin Date: Sun, 6 Oct 2013 09:22:41 +0400 Subject: [PATCH] debugger: count space for line numbers correctly --- lib/_debugger.js | 26 ++++++-------------------- 1 file changed, 6 insertions(+), 20 deletions(-) diff --git a/lib/_debugger.js b/lib/_debugger.js index a68a404..2613d8b 100644 --- a/lib/_debugger.js +++ b/lib/_debugger.js @@ -1018,28 +1018,13 @@ Interface.prototype.debugEval = function(code, context, filename, callback) { // Utils -// Returns number of digits (+1) -function intChars(n) { - // TODO dumb: - if (n < 50) { - return 3; - } else if (n < 950) { - return 4; - } else if (n < 9950) { - return 5; - } else { - return 6; - } -} - // Adds spaces and prefix to number -function leftPad(n, prefix) { +// maxN is a maximum number we should have space for +function leftPad(n, prefix, maxN) { var s = n.toString(), - nchars = intChars(n), + nchars = Math.max(2, String(maxN).length) + 1, nspaces = nchars - s.length - 1; - prefix || (prefix = ' '); - for (var i = 0; i < nspaces; i++) { prefix += ' '; } @@ -1160,7 +1145,7 @@ Interface.prototype.list = function(delta) { prefixChar = '*'; } - self.print(leftPad(lineno, prefixChar) + ' ' + line); + self.print(leftPad(lineno, prefixChar, to) + ' ' + line); } self.resume(); }); @@ -1322,7 +1307,8 @@ Interface.prototype.watchers = function() { if (verbose) self.print('Watchers:'); self._watchers.forEach(function(watcher, i) { - self.print(leftPad(i, ' ') + ': ' + watcher + ' = ' + + self.print(leftPad(i, ' ', self._watchers.length - 1) + + ': ' + watcher + ' = ' + JSON.stringify(values[i])); }); -- 2.7.4