-
Notifications
You must be signed in to change notification settings - Fork 2k
/
repl.js
38 lines (38 loc) · 934 Bytes
/
repl.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
(function() {
var CoffeeScript, helpers, readline, repl, run, stdio;
CoffeeScript = require('./coffee-script');
helpers = require('./helpers');
readline = require('readline');
stdio = process.openStdin();
helpers.extend(global, {
quit: function() {
return process.exit(0);
}
});
run = function(buffer) {
var val;
try {
val = CoffeeScript.eval(buffer.toString(), {
bare: true,
globals: true,
fileName: 'repl'
});
if (val !== undefined) {
console.log(inspect(val));
}
} catch (err) {
console.log(err.stack || err.toString());
}
return repl.prompt();
};
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);