function SourceUnderline(sourceText, position) {
- if (!sourceText) return;
-
- var wrapper = require('module').wrapper[0];
- if (sourceText.indexOf(wrapper) === 0) {
- sourceText = sourceText.slice(wrapper.length);
- position -= wrapper.length;
- }
+ if (!sourceText) return '';
// Create an underline with a caret pointing to the source position. If the
// source contains a tab character the underline will have a tab character in
// the same place otherwise the underline will have a space character.
- var underline = '';
+ var underline = ' ';
for (var i = 0; i < position; i++) {
if (sourceText[i] == '\t') {
underline += '\t';
underline += '^';
// Return the source line text with the underline beneath.
- return sourceText + '\n' + underline;
+ return underline;
}
// Output
Interface.prototype.print = function(text) {
- process.stdout.cursorTo(0);
- process.stdout.clearLine(1);
+ if (process.stdout.isTTY) {
+ process.stdout.cursorTo(0);
+ process.stdout.clearLine(1);
+ }
process.stdout.write(typeof text === 'string' ? text : util.inspect(text));
process.stdout.write('\n');
};
this.pause();
this.client.currentSourceLine = r.sourceLine;
+ this.client.currentSourceLineText = r.sourceLineText;
+ this.client.currentSourceColumn = r.sourceColumn;
this.client.currentFrame = 0;
this.client.currentScript = r.script.name;
- this.print(SourceInfo(r) + '\n' +
- SourceUnderline(r.sourceLineText, r.sourceColumn));
+ if (process.stdout.isTTY) {
+ var step = {
+ 'next': true,
+ 'step': true,
+ 'out': true,
+ 'n': true,
+ 's': true,
+ 'o': true
+ },
+ history = this.repl.rli.history;
+
+ // If current cmd is 'step' and previous was too
+ // Clear previous lines and overwrite them
+ if (step[history[0]] && step[history[1]]) {
+ for (var i = 0; i < 8; i++) {
+ process.stdout.clearLine(0);
+ process.stdout.moveCursor(0, -1);
+ }
+ process.stdout.clearLine(0);
+ }
+ }
+
+ this.print(SourceInfo(r));
+ this.list(2);
this.resume();
};
Interface.prototype.requireConnection = function() {
- if (!this.client) this.error('App isn\'t running... Try `run` instead');
+ if (!this.client) {
+ this.error('App isn\'t running... Try `run` instead');
+ return false;
+ }
+ return true;
};
Interface.prototype.controlEval = function(code, context, filename, callback) {
// Print version
Interface.prototype.version = function() {
- this.requireConnection();
+ if (!this.requireConnection()) return;
+
var self = this;
this.pause();
// List source code
Interface.prototype.list = function() {
- this.requireConnection();
+ if (!this.requireConnection()) return;
var self = this,
client = this.client,
- from = client.currentSourceLine - 5,
- to = client.currentSourceLine + 5;
+ delta = arguments[0] || 5,
+ from = client.currentSourceLine - delta + 1,
+ to = client.currentSourceLine + delta + 1;
self.pause();
client.reqSource(from, to, function(res) {
}
pointer += '>';
self.print(pointer + ' ' + lines[i]);
+ self.print(SourceUnderline(client.currentSourceLineText,
+ client.currentSourceColumn));
} else {
self.print(leftPad(lineno) + ' ' + lines[i]);
}
// Print backtrace
Interface.prototype.backtrace = function() {
- this.requireConnection();
+ if (!this.requireConnection()) return;
var self = this,
client = this.client;
// argument full tells if it should display internal node scripts or not
Interface.prototype.scripts = function(displayNatives) {
- this.requireConnection();
+ if (!this.requireConnection()) return;
var client = this.client;
var scripts = [];
// Continue execution of script
Interface.prototype.cont = function() {
- this.requireConnection();
+ if (!this.requireConnection()) return;
this.pause();
var self = this;
};
-// Jump to next command
-Interface.prototype.next = function() {
- this.requireConnection();
+// Step commands generator
+Interface.stepGenerator = function(type, count) {
+ return function() {
+ if (!this.requireConnection()) return;
- this.pause();
+ var self = this;
- var self = this;
- this.client.step('next', 1, function(res) {
- self.resume();
- });
+ self.pause();
+ self.client.step(type, count, function(res) {
+ self.resume();
+ });
+ };
};
-// Step in
-Interface.prototype.step = function() {
- this.requireConnection();
+// Jump to next command
+Interface.prototype.next = Interface.stepGenerator('next', 1);
- this.pause();
- var self = this;
- this.client.step('in', 1, function(res) {
- self.resume();
- });
-};
+// Step in
+Interface.prototype.step = Interface.stepGenerator('in', 1);
// Step out
-Interface.prototype.out = function() {
- this.requireConnection();
-
- this.pause();
-
- var self = this;
- this.client.step('out', 1, function(res) {
- self.resume();
- });
-};
+Interface.prototype.out = Interface.stepGenerator('out', 1);
// Add breakpoint
// Show breakpoints
Interface.prototype.breakpoints = function() {
- this.requireConnection();
+ if (!this.requireConnection()) return;
+
this.pause();
var self = this;
this.client.listbreakpoints(function(res) {
// Activate debug repl
Interface.prototype.repl = function() {
- this.requireConnection();
+ if (!this.requireConnection()) return;
var self = this;