Skip to content

Commit

Permalink
debugger: count space for line numbers correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
rlidwka authored and bnoordhuis committed Oct 6, 2013
1 parent 58729f1 commit 5b23000
Showing 1 changed file with 6 additions and 20 deletions.
26 changes: 6 additions & 20 deletions lib/_debugger.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 += ' ';
}
Expand Down Expand Up @@ -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();
});
Expand Down Expand Up @@ -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]));
});

Expand Down

0 comments on commit 5b23000

Please sign in to comment.