Add backwards compatibility for older readline

Check the readline.createInterface for arity. If it is 3,
assume the newer interface requiring separate stdin and stdout.
Otherwise, use the older calling style.
This commit is contained in:
Isaac Wolkerstorfer
2011-01-22 12:30:22 +01:00
parent 78b52f5716
commit 496816acff
2 changed files with 14 additions and 2 deletions

View File

@@ -78,7 +78,14 @@
return _results;
};
process.on('uncaughtException', error);
repl = readline.createInterface(stdin, stdout, autocomplete);
if (readline.createInterface.length === 3) {
repl = readline.createInterface(stdin, stdout, autocomplete);
} else {
repl = readline.createInterface(stdin, autocomplete);
stdin.on('data', function(buffer) {
return repl.write(buffer);
});
}
repl.setPrompt('coffee> ');
repl.on('close', function() {
return stdin.destroy();

View File

@@ -77,7 +77,12 @@ getPropertyNames = (obj) ->
process.on 'uncaughtException', error
# Create the REPL by listening to **stdin**.
repl = readline.createInterface stdin, stdout, autocomplete
if readline.createInterface.length == 3
repl = readline.createInterface stdin, stdout, autocomplete
else
repl = readline.createInterface stdin, autocomplete
stdin.on 'data', (buffer) -> repl.write buffer
repl.setPrompt 'coffee> '
repl.on 'close', -> stdin.destroy()
repl.on 'line', run