forked from max-mapper/node-repl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrepl.js
32 lines (30 loc) · 848 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
;(function () { // uppercase namespaces var to avoid clashes
var NODE_REPL_SOURCES = []
var NODE_REPL_LOOP = (function * () {
while (true) {
if (NODE_REPL_SOURCES.length) {
var NODE_REPL_NEXT = NODE_REPL_SOURCES.shift()
try {
NODE_REPL_NEXT.callback(null, eval(NODE_REPL_NEXT.command))
} catch (e) {
NODE_REPL_NEXT.callback(e)
}
}
yield null
}
})()
;(function () {
var repl = require('repl')
var os = require('os')
var empty = '(' + os.EOL + ')'
repl.start({
input: process.stdin,
output: process.stdout,
eval: function (cmd, context, filename, callback) {
if (cmd === empty) return callback()
NODE_REPL_SOURCES.push({command: cmd, callback: callback})
NODE_REPL_LOOP.next()
}
})
})()
})()