var proto = Interface.prototype,
ignored = ['pause', 'resume', 'exitRepl', 'handleBreak',
'requireConnection', 'killChild', 'trySpawn',
- 'controlEval', 'debugEval'],
+ 'controlEval', 'debugEval', 'print'],
synonym = {
'run': 'r',
'cont': 'c',
};
-Interface.prototype.handleBreak = function(r) {
- var expected = this.paused !== 0;
+// Output
+Interface.prototype.print = function(text) {
+ process.stdout.cursorTo(0);
+ process.stdout.clearLine(1);
+ process.stdout.write(text + '\n');
+};
+
+Interface.prototype.handleBreak = function(r) {
this.pause();
this.client.currentSourceLine = r.sourceLine;
this.client.currentFrame = 0;
this.client.currentScript = r.script.name;
- if (!expected) {
- console.log('');
- }
- console.log(SourceInfo(r));
- console.log(SourceUnderline(r.sourceLineText, r.sourceColumn));
+ this.print(SourceInfo(r) + '\n' +
+ SourceUnderline(r.sourceLineText, r.sourceColumn));
this.resume();
};
// Print help message
Interface.prototype.help = function() {
- console.log(helpMessage);
+ this.print(helpMessage);
};
this.pause();
this.client.reqVersion(function(v) {
- process.stdout.write(v);
+ self.print(v);
self.resume();
});
};
pointer += '=';
}
pointer += '>';
- console.log(pointer + ' ' + lines[i]);
+ self.print(pointer + ' ' + lines[i]);
} else {
- console.log(leftPad(lineno) + ' ' + lines[i]);
+ self.print(leftPad(lineno) + ' ' + lines[i]);
}
}
self.resume();
self.pause();
client.fullTrace(function(bt) {
if (bt.totalFrames == 0) {
- console.log('(empty stack)');
+ self.print('(empty stack)');
} else {
- var text = '';
- var firstFrameNative = bt.frames[0].script.isNative;
+ var trace = [],
+ firstFrameNative = bt.frames[0].script.isNative;
for (var i = 0; i < bt.frames.length; i++) {
var frame = bt.frames[i];
if (!firstFrameNative && frame.script.isNative) break;
- text += '#' + i + ' ';
+ var text = '#' + i + ' ';
if (frame.func.inferredName && frame.func.inferredName.length > 0) {
text += frame.func.inferredName + ' ';
}
text += require('path').basename(frame.script.name) + ':';
text += (frame.line + 1) + ':' + (frame.column + 1);
- text += '\n';
+
+ trace.push(text);
}
- console.log(text);
+ self.print(trace.join('\n'));
}
self.resume();
});
this.requireConnection();
var client = this.client;
- var text = '';
+ var scripts = [];
this.pause();
for (var id in client.scripts) {
if (displayNatives ||
script.name == client.currentScript ||
!script.isNative) {
- text += script.name == client.currentScript ? '* ' : ' ';
- text += require('path').basename(script.name) + '\n';
+ scripts.push(
+ (script.name == client.currentScript ? '* ' : ' ') +
+ require('path').basename(script.name)
+ );
}
}
}
- console.log(text);
+ this.print(scripts.join('\n'));
this.resume();
};
var self = this;
this.client.listbreakpoints(function(res) {
if (res.success) {
- console.log(res.body);
+ self.print(res.body);
} else {
throw Error(res.message || 'Some error happened');
}
var self = this;
- console.log('Press Ctrl + C to leave debug repl');
+ self.print('Press Ctrl + C to leave debug repl');
// Don't display any default messages
var listeners = this.repl.rli.listeners('SIGINT');
client.on('close', function() {
self.pause()
- console.log('program terminated');
+ self.print('program terminated');
self.resume();
self.client = null;
self.killChild();
client.on('unhandledResponse', function(res) {
self.pause();
- console.log('\r\nunhandled res:');
- console.log(res);
+ self.print('\nunhandled res:' + JSON.stringify(res));
self.resume();
});