function SourceUnderline(sourceText, position) {
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 = ' ';
- for (var i = 0; i < position; i++) {
- if (sourceText[i] == '\t') {
- underline += '\t';
- } else {
- underline += ' ';
- }
+ var head = sourceText.slice(0, position),
+ tail = sourceText.slice(position);
+
+ // Colourize char if stdout supports colours
+ if (process.stdout.isTTY) {
+ tail = tail.replace(/(.{1,}?)([^\w]|$)/, '\033[32m$1\033[39m$2');
}
- underline += '^';
- // Return the source line text with the underline beneath.
- return underline;
+ // Return source line with coloured char at `position`
+ return [
+ head,
+ tail
+ ].join('');
}
this.repl = new repl.REPLServer('debug> ', null,
this.controlEval.bind(this));
+ this.repl.rli.addListener('close', function() {
+ self.killed = true;
+ self.killChild();
+ });
+
// Lift all instance methods to repl context
var proto = Interface.prototype,
ignored = ['pause', 'resume', 'exitRepl', 'handleBreak',
}
}
+ this.killed = false;
this.waiting = null;
this.paused = 0;
this.context = this.repl.context;
Interface.prototype.pause = function() {
- if (this.paused++ > 0) return false;
+ if (this.killed || this.paused++ > 0) return false;
this.repl.rli.pause();
process.stdin.pause();
};
Interface.prototype.resume = function(silent) {
- if (this.paused === 0 || --this.paused !== 0) return false;
+ if (this.killed || this.paused === 0 || --this.paused !== 0) return false;
this.repl.rli.resume();
if (silent !== true) {
this.repl.displayPrompt();
// Output
Interface.prototype.print = function(text) {
+ if (this.killed) return;
if (process.stdout.isTTY) {
process.stdout.cursorTo(0);
process.stdout.clearLine(1);
this.client.currentFrame = 0;
this.client.currentScript = r.script.name;
- 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();
pointer += '=';
}
pointer += '>';
- self.print(pointer + ' ' + lines[i]);
- self.print(SourceUnderline(client.currentSourceLineText,
- client.currentSourceColumn));
+ self.print(pointer + ' ' + SourceUnderline(lines[i],
+ client.currentSourceColumn));
} else {
self.print(leftPad(lineno) + ' ' + lines[i]);
}