Skip to content

Instantly share code, notes, and snippets.

@scribu
Last active December 23, 2017 15:20
Show Gist options
  • Save scribu/8656698 to your computer and use it in GitHub Desktop.
Save scribu/8656698 to your computer and use it in GitHub Desktop.
Simplistic REPL for CasperJS
// Usage: require('repl').start.call(this);
// Press Ctrl+D to continue script
// Press Ctrl+C to exit.
require = patchRequire(require);
var system = require('system');
var utils = require('utils');
exports.start = function(prompt) {
prompt = prompt || '> ';
var line, _;
do {
system.stdout.write(prompt);
line = system.stdin.readLine();
if (system.stdin.atEnd()) {
break;
}
try {
_ = eval(line);
console.log(_);
} catch (e) {
console.log(e);
}
} while (true);
}
Copy link

ghost commented Sep 22, 2017

Hi, I had the same problem. Did you solve it?

@stevenreddie
Copy link

This gist is written as a CasperJS module (see http://docs.casperjs.org/en/latest/writing_modules.html). It should be used from within the context of a normal CasperJS script. eg. in your script, add this line somewhere near the top:

var repl = require('./repl');

and at the point in your script that you want to drop into the REPL, add this line:

repl.start();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment