 # Using it looks like this:
 #
 #     coffee> console.log "#{num} bottles of beer" for num in [99..1]
+
+# Start by opening up `stdin` and `stdout`.
+stdin = process.openStdin()
+stdout = process.stdout
 
 # Require the **coffee-script** module to get access to the compiler.
 CoffeeScript = require './coffee-script'

# Return elements of candidates for which `prefix` is a prefix.
getCompletions = (prefix, candidates) ->
  (el for el in candidates when el.indexOf(prefix) is 0)

# Make sure that uncaught exceptions don't kill the REPL.
process.on 'uncaughtException', error

# Create the REPL by listening to **stdin**.
if readline.createInterface.length < 3
  repl = readline.createInterface stdin, autocomplete
  stdin.on 'data', (buffer) -> repl.write buffer
else
  repl = readline.createInterface stdin, stdout, autocomplete

repl.on 'attemptClose', ->
  if backlog
    backlog = ''
    process.stdout.write '\n'
    repl.setPrompt REPL_PROMPT
    repl.prompt()
  else
    repl.close()

repl.on 'close', ->
  process.stdout.write '\n'
  stdin.destroy()

repl.on 'line', run

repl.setPrompt REPL_PROMPT
repl.prompt()

    }
    if returnValue is undefined
      global._ = _
    repl.output.write "#{inspect returnValue, no, 2, enableColours}\n"
  catch err
    error err
  repl.prompt()

repl.setPrompt REPL_PROMPT
repl.prompt()

## Autocompletion

