Skip to content

Commit

Permalink
Listen for line event instead of overriding eval
Browse files Browse the repository at this point in the history
  • Loading branch information
scttnlsn committed Nov 25, 2011
1 parent 0fcd4e2 commit 67065e8
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions index.js
Expand Up @@ -9,20 +9,15 @@ module.exports = function (repl, file) {
} catch (e) {}

var fd = fs.openSync(file, 'a'), reval = repl.eval;

repl.eval = function(code, context, file, cb) {
var last = code.substring(1)
last = last.substring(0, last.length-2);

if (last && last !== '.history') {
fs.write(fd, last + '\n');

repl.rli.addListener('line', function(code) {
if (code && code !== '.history') {
fs.write(fd, code + '\n');
} else {
repl.rli.historyIndex++;
repl.rli.history.pop();
}

reval(code, context, file, cb);
}
});

process.on('exit', function() {
fs.closeSync(fd);
Expand Down

0 comments on commit 67065e8

Please sign in to comment.