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]';
}
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',
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);
};
};
-// 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
// 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);
}
};
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);
}
}
setTimeout(function() {
- process.stdout.write('connecting..');
+ self.print('connecting..', true);
attemptConnect();
}, 50);
};