Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Commit

Permalink
[debugger] color mark in _debugger, kill child on Ctrl+D
Browse files Browse the repository at this point in the history
  • Loading branch information
indutny committed Sep 14, 2011
1 parent 0e0fbf7 commit f2ec46a
Showing 1 changed file with 22 additions and 40 deletions.
62 changes: 22 additions & 40 deletions lib/_debugger.js
Expand Up @@ -628,21 +628,19 @@ var helpMessage = 'Commands: ' + commands.join(', ');
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('');
}


Expand Down Expand Up @@ -681,6 +679,11 @@ function Interface() {
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',
Expand Down Expand Up @@ -713,6 +716,7 @@ function Interface() {
}
}

this.killed = false;
this.waiting = null;
this.paused = 0;
this.context = this.repl.context;
Expand All @@ -723,13 +727,13 @@ function Interface() {


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();
Expand All @@ -745,6 +749,7 @@ Interface.prototype.resume = function(silent) {

// Output
Interface.prototype.print = function(text) {
if (this.killed) return;
if (process.stdout.isTTY) {
process.stdout.cursorTo(0);
process.stdout.clearLine(1);
Expand Down Expand Up @@ -776,28 +781,6 @@ Interface.prototype.handleBreak = function(r) {
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();
Expand Down Expand Up @@ -964,9 +947,8 @@ Interface.prototype.list = function() {
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]);
}
Expand Down

0 comments on commit f2ec46a

Please sign in to comment.