1
0
Fork 0
mirror of https://github.com/jashkenas/coffeescript.git synced 2022-11-09 12:23:24 -05:00
jashkenas--coffeescript/lib/repl.js

39 lines
924 B
JavaScript
Raw Normal View History

(function() {
var CoffeeScript, helpers, readline, repl, run, stdio;
CoffeeScript = require('./coffee-script');
2010-09-24 20:29:44 -04:00
helpers = require('./helpers');
readline = require('readline');
stdio = process.openStdin();
helpers.extend(global, {
quit: function() {
return process.exit(0);
}
});
run = function(buffer) {
2010-02-17 23:51:43 -05:00
var val;
2010-01-29 22:51:51 -05:00
try {
val = CoffeeScript.eval(buffer.toString(), {
2010-10-13 15:09:56 -04:00
bare: true,
globals: true,
fileName: 'repl'
});
if (val !== void 0) {
2010-10-24 21:15:20 -04:00
console.log(val);
2010-01-29 22:51:51 -05:00
}
} catch (err) {
console.error(err.stack || err.toString());
2010-01-29 22:51:51 -05:00
}
return repl.prompt();
2010-01-29 22:51:51 -05:00
};
repl = readline.createInterface(stdio);
repl.setPrompt('coffee> ');
stdio.on('data', function(buffer) {
return repl.write(buffer);
});
repl.on('close', function() {
return stdio.destroy();
});
repl.on('line', run);
repl.prompt();
}).call(this);