Skip to content
This repository has been archived by the owner on Feb 1, 2022. It is now read-only.

Commit

Permalink
feat: repl command
Browse files Browse the repository at this point in the history
  • Loading branch information
Jan Krems committed Sep 12, 2016
1 parent 2f5dac6 commit c64155f
Showing 1 changed file with 59 additions and 2 deletions.
61 changes: 59 additions & 2 deletions lib/node-inspect.js
Original file line number Diff line number Diff line change
Expand Up @@ -476,8 +476,8 @@ function createCommandContext(inspector) {

const scripts = {};
const watchedExpressions = [];

const knownBreakpoints = [];
const history = { debug: [], control: [] };

const writer = createRemoteAwareWriter(true);
const formatValue = value => writer(value);
Expand Down Expand Up @@ -530,6 +530,21 @@ function createCommandContext(inspector) {
}
}

// Exit debug repl
function exitRepl() {
// Restore eval
repl.eval = (code, ctx, file, cb) =>
inspector.controlEval(code, ctx, file, cb);

// Swap history
history.debug = repl.rli.history;
repl.rli.history = history.control;

repl.context = inspector.context;
repl.rli.setPrompt('debug> ');
repl.displayPrompt();
}

const ctx = {
get help() {
const commands = [
Expand Down Expand Up @@ -582,6 +597,49 @@ function createCommandContext(inspector) {
.then(convertResultToRemoteObject);
},

get repl() {
// if (!this.requireConnection()) return;
print('Press Ctrl + C to leave debug repl');

// Don't display any default messages
const listeners = repl.rli.listeners('SIGINT').slice(0);
repl.rli.removeAllListeners('SIGINT');

function exitDebugRepl() {
// Restore all listeners
process.nextTick(() => {
listeners.forEach((listener) => {
repl.rli.on('SIGINT', listener);
});
});

// Exit debug repl
exitRepl();

repl.rli.removeListener('SIGINT', exitDebugRepl);
repl.removeListener('exit', exitDebugRepl);
}

// Exit debug repl on SIGINT
repl.rli.on('SIGINT', exitDebugRepl);

// Exit debug repl on repl exit
repl.on('exit', exitDebugRepl);

// Set new
repl.eval = (code, evalCtx, file, cb) => {
toCallback(ctx.debugEval(code), cb);
};
repl.context = {};

// Swap history
history.control = repl.rli.history;
repl.rli.history = history.debug;

repl.rli.setPrompt('> ');
repl.displayPrompt();
},

exec(code) {
return ctx.debugEval(code);
},
Expand Down Expand Up @@ -926,7 +984,6 @@ class Inspector {
this.waiting = null;
this.paused = 0;
this.context = this.repl.context;
this.history = { debug: [], control: [] };
this.breakpoints = [];
this._watchers = [];

Expand Down

0 comments on commit c64155f

Please sign in to comment.