Browse Source

[debugger] fix 'debug> connecting...', fixed autostart (XXX figure out why it wasn't working in some cases), fixed highlighting for first line of module's code

v0.7.4-release
Fedor Indutny 13 years ago
committed by Ryan Dahl
parent
commit
3148f1400e
  1. 68
      lib/_debugger.js

68
lib/_debugger.js

@ -682,7 +682,11 @@ function SourceInfo(body) {
if (body.script) {
if (body.script.name) {
result += ', ' + body.script.name;
var name = body.script.name;
// TODO Change path to relative, if possible
result += ', ' + name;
} else {
result += ', [unnamed]';
}
@ -718,7 +722,8 @@ function Interface() {
var proto = Interface.prototype,
ignored = ['pause', 'resume', 'exitRepl', 'handleBreak',
'requireConnection', 'killChild', 'trySpawn',
'controlEval', 'debugEval', 'print', 'childPrint'],
'controlEval', 'debugEval', 'print', 'childPrint',
'clearline'],
shortcut = {
'run': 'r',
'cont': 'c',
@ -762,7 +767,16 @@ function Interface() {
this.breakpoints = [];
// Run script automatically
this.run();
this.clearline();
this.pause();
// XXX Need to figure out why we need this delay
setTimeout(function() {
self.run(function() {
self.resume();
});
}, 10);
};
@ -790,15 +804,24 @@ Interface.prototype.resume = function(silent) {
};
// Print text to output stream
Interface.prototype.print = function(text) {
if (this.killed) return;
// Clear current line
Interface.prototype.clearline = function() {
if (process.stdout.isTTY) {
process.stdout.cursorTo(0);
process.stdout.clearLine(1);
}
};
// Print text to output stream
Interface.prototype.print = function(text, oneline) {
if (this.killed) return;
this.clearline();
process.stdout.write(typeof text === 'string' ? text : util.inspect(text));
process.stdout.write('\n');
if (oneline !== true) {
process.stdout.write('\n');
}
};
// Format and print text from child process
@ -956,10 +979,13 @@ Interface.prototype.help = function() {
// Run script
Interface.prototype.run = function() {
var callback = arguments[0];
if (this.child) {
this.error('App is already running... Try `restart` instead');
callback && callback(true);
} else {
this.trySpawn();
this.trySpawn(callback);
}
};
@ -1015,22 +1041,28 @@ Interface.prototype.list = function() {
var lineno = res.fromLine + i + 1;
if (lineno < from || lineno > to) continue;
var current = lineno == 1 + client.currentSourceLine,
breakpoint = client.breakpoints.some(function(bp) {
return bp.script === client.currentScript &&
bp.line == lineno;
});
if (lineno == 1) {
// The first line needs to have the module wrapper filtered out of
// it.
var wrapper = require('module').wrapper[0];
lines[i] = lines[i].slice(wrapper.length);
client.currentSourceColumn -= wrapper.length;
}
var current = lineno == 1 + client.currentSourceLine,
breakpoint = client.breakpoints.some(function(bp) {
return bp.script === client.currentScript &&
bp.line == lineno;
}),
line = current ?
SourceUnderline(lines[i], client.currentSourceColumn)
:
lines[i];
// Highlight executing statement
var line;
if (current) {
line = SourceUnderline(lines[i], client.currentSourceColumn)
} else {
line = lines[i];
}
self.print(leftPad(lineno, breakpoint && '*') + ' ' + line);
}
@ -1412,7 +1444,7 @@ Interface.prototype.trySpawn = function(cb) {
}
setTimeout(function() {
process.stdout.write('connecting..');
self.print('connecting..', true);
attemptConnect();
}, 50);
};

Loading…
Cancel
Save