|
@ -628,21 +628,19 @@ var helpMessage = 'Commands: ' + commands.join(', '); |
|
|
function SourceUnderline(sourceText, position) { |
|
|
function SourceUnderline(sourceText, position) { |
|
|
if (!sourceText) return ''; |
|
|
if (!sourceText) return ''; |
|
|
|
|
|
|
|
|
// Create an underline with a caret pointing to the source position. If the
|
|
|
var head = sourceText.slice(0, position), |
|
|
// source contains a tab character the underline will have a tab character in
|
|
|
tail = sourceText.slice(position); |
|
|
// the same place otherwise the underline will have a space character.
|
|
|
|
|
|
var underline = ' '; |
|
|
// Colourize char if stdout supports colours
|
|
|
for (var i = 0; i < position; i++) { |
|
|
if (process.stdout.isTTY) { |
|
|
if (sourceText[i] == '\t') { |
|
|
tail = tail.replace(/(.{1,}?)([^\w]|$)/, '\033[32m$1\033[39m$2'); |
|
|
underline += '\t'; |
|
|
|
|
|
} else { |
|
|
|
|
|
underline += ' '; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
underline += '^'; |
|
|
|
|
|
|
|
|
|
|
|
// Return the source line text with the underline beneath.
|
|
|
// Return source line with coloured char at `position`
|
|
|
return underline; |
|
|
return [ |
|
|
|
|
|
head, |
|
|
|
|
|
tail |
|
|
|
|
|
].join(''); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -681,6 +679,11 @@ function Interface() { |
|
|
this.repl = new repl.REPLServer('debug> ', null, |
|
|
this.repl = new repl.REPLServer('debug> ', null, |
|
|
this.controlEval.bind(this)); |
|
|
this.controlEval.bind(this)); |
|
|
|
|
|
|
|
|
|
|
|
this.repl.rli.addListener('close', function() { |
|
|
|
|
|
self.killed = true; |
|
|
|
|
|
self.killChild(); |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
// Lift all instance methods to repl context
|
|
|
// Lift all instance methods to repl context
|
|
|
var proto = Interface.prototype, |
|
|
var proto = Interface.prototype, |
|
|
ignored = ['pause', 'resume', 'exitRepl', 'handleBreak', |
|
|
ignored = ['pause', 'resume', 'exitRepl', 'handleBreak', |
|
@ -713,6 +716,7 @@ function Interface() { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
this.killed = false; |
|
|
this.waiting = null; |
|
|
this.waiting = null; |
|
|
this.paused = 0; |
|
|
this.paused = 0; |
|
|
this.context = this.repl.context; |
|
|
this.context = this.repl.context; |
|
@ -723,13 +727,13 @@ function Interface() { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Interface.prototype.pause = function() { |
|
|
Interface.prototype.pause = function() { |
|
|
if (this.paused++ > 0) return false; |
|
|
if (this.killed || this.paused++ > 0) return false; |
|
|
this.repl.rli.pause(); |
|
|
this.repl.rli.pause(); |
|
|
process.stdin.pause(); |
|
|
process.stdin.pause(); |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
Interface.prototype.resume = function(silent) { |
|
|
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(); |
|
|
this.repl.rli.resume(); |
|
|
if (silent !== true) { |
|
|
if (silent !== true) { |
|
|
this.repl.displayPrompt(); |
|
|
this.repl.displayPrompt(); |
|
@ -745,6 +749,7 @@ Interface.prototype.resume = function(silent) { |
|
|
|
|
|
|
|
|
// Output
|
|
|
// Output
|
|
|
Interface.prototype.print = function(text) { |
|
|
Interface.prototype.print = function(text) { |
|
|
|
|
|
if (this.killed) return; |
|
|
if (process.stdout.isTTY) { |
|
|
if (process.stdout.isTTY) { |
|
|
process.stdout.cursorTo(0); |
|
|
process.stdout.cursorTo(0); |
|
|
process.stdout.clearLine(1); |
|
|
process.stdout.clearLine(1); |
|
@ -776,28 +781,6 @@ Interface.prototype.handleBreak = function(r) { |
|
|
this.client.currentFrame = 0; |
|
|
this.client.currentFrame = 0; |
|
|
this.client.currentScript = r.script.name; |
|
|
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.print(SourceInfo(r)); |
|
|
this.list(2); |
|
|
this.list(2); |
|
|
this.resume(); |
|
|
this.resume(); |
|
@ -964,8 +947,7 @@ Interface.prototype.list = function() { |
|
|
pointer += '='; |
|
|
pointer += '='; |
|
|
} |
|
|
} |
|
|
pointer += '>'; |
|
|
pointer += '>'; |
|
|
self.print(pointer + ' ' + lines[i]); |
|
|
self.print(pointer + ' ' + SourceUnderline(lines[i], |
|
|
self.print(SourceUnderline(client.currentSourceLineText, |
|
|
|
|
|
client.currentSourceColumn)); |
|
|
client.currentSourceColumn)); |
|
|
} else { |
|
|
} else { |
|
|
self.print(leftPad(lineno) + ' ' + lines[i]); |
|
|
self.print(leftPad(lineno) + ' ' + lines[i]); |
|
|