Last active
December 23, 2017 15:20
-
-
Save scribu/8656698 to your computer and use it in GitHub Desktop.
Simplistic REPL for CasperJS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); | |
} |
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
Hi, I had the same problem. Did you solve it?