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

Commit

Permalink
[debugger] fix 'debug> connecting...', fixed autostart (XXX figure ou…
Browse files Browse the repository at this point in the history
…t why it wasn't working in some cases), fixed highlighting for first line of module's code
  • Loading branch information
indutny authored and ry committed Sep 21, 2011
1 parent 320cf72 commit 3148f14
Showing 1 changed file with 50 additions and 18 deletions.
68 changes: 50 additions & 18 deletions lib/_debugger.js
Expand Up @@ -682,7 +682,11 @@ function SourceInfo(body) {

if (body.script) {
if (body.script.name) {
result += ', ' + body.script.name;
var name = body.script.name;

// TODO Change path to relative, if possible

result += ', ' + name;
} else {
result += ', [unnamed]';
}
Expand Down Expand Up @@ -718,7 +722,8 @@ function Interface() {
var proto = Interface.prototype,
ignored = ['pause', 'resume', 'exitRepl', 'handleBreak',
'requireConnection', 'killChild', 'trySpawn',
'controlEval', 'debugEval', 'print', 'childPrint'],
'controlEval', 'debugEval', 'print', 'childPrint',
'clearline'],
shortcut = {
'run': 'r',
'cont': 'c',
Expand Down Expand Up @@ -762,7 +767,16 @@ function Interface() {
this.breakpoints = [];

// Run script automatically
this.run();
this.clearline();
this.pause();

// XXX Need to figure out why we need this delay
setTimeout(function() {

self.run(function() {
self.resume();
});
}, 10);
};


Expand Down Expand Up @@ -790,15 +804,24 @@ Interface.prototype.resume = function(silent) {
};


// Print text to output stream
Interface.prototype.print = function(text) {
if (this.killed) return;
// Clear current line
Interface.prototype.clearline = function() {
if (process.stdout.isTTY) {
process.stdout.cursorTo(0);
process.stdout.clearLine(1);
}
};

// Print text to output stream
Interface.prototype.print = function(text, oneline) {
if (this.killed) return;
this.clearline();

process.stdout.write(typeof text === 'string' ? text : util.inspect(text));
process.stdout.write('\n');

if (oneline !== true) {
process.stdout.write('\n');
}
};

// Format and print text from child process
Expand Down Expand Up @@ -956,10 +979,13 @@ Interface.prototype.help = function() {

// Run script
Interface.prototype.run = function() {
var callback = arguments[0];

if (this.child) {
this.error('App is already running... Try `restart` instead');
callback && callback(true);
} else {
this.trySpawn();
this.trySpawn(callback);
}
};

Expand Down Expand Up @@ -1015,22 +1041,28 @@ Interface.prototype.list = function() {
var lineno = res.fromLine + i + 1;
if (lineno < from || lineno > to) continue;

var current = lineno == 1 + client.currentSourceLine,
breakpoint = client.breakpoints.some(function(bp) {
return bp.script === client.currentScript &&
bp.line == lineno;
});

if (lineno == 1) {
// The first line needs to have the module wrapper filtered out of
// it.
var wrapper = require('module').wrapper[0];
lines[i] = lines[i].slice(wrapper.length);

client.currentSourceColumn -= wrapper.length;
}

var current = lineno == 1 + client.currentSourceLine,
breakpoint = client.breakpoints.some(function(bp) {
return bp.script === client.currentScript &&
bp.line == lineno;
}),
line = current ?
SourceUnderline(lines[i], client.currentSourceColumn)
:
lines[i];
// Highlight executing statement
var line;
if (current) {
line = SourceUnderline(lines[i], client.currentSourceColumn)
} else {
line = lines[i];
}

self.print(leftPad(lineno, breakpoint && '*') + ' ' + line);
}
Expand Down Expand Up @@ -1412,7 +1444,7 @@ Interface.prototype.trySpawn = function(cb) {
}

setTimeout(function() {
process.stdout.write('connecting..');
self.print('connecting..', true);
attemptConnect();
}, 50);
};

0 comments on commit 3148f14

Please sign in to comment.