From 496816acff58308aa3429068be95791faab5b06b Mon Sep 17 00:00:00 2001 From: Isaac Wolkerstorfer Date: Sat, 22 Jan 2011 12:30:22 +0100 Subject: [PATCH] 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. --- lib/repl.js | 9 ++++++++- src/repl.coffee | 7 ++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/lib/repl.js b/lib/repl.js index 923e9b25..65097cfb 100644 --- a/lib/repl.js +++ b/lib/repl.js @@ -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(); diff --git a/src/repl.coffee b/src/repl.coffee index 8418ecf0..1e2b3bff 100644 --- a/src/repl.coffee +++ b/src/repl.coffee @@ -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