Readline is a more robust REPL.
readline = require('readline')
repl = readline.createInterface(stdin, stdout, autocomplete)
repl.historyIndex = 0
repl.history = ['App.Post.all()']
repl.on 'attemptClose', ->
repl.close()
repl.on 'close', ->
stdin.destroy()
repl.on 'line', (line) ->
repl.setPrompt('node> ')
repl.prompt()
repl.terminal # true|false
# current line
repl.line
# cursor position on the line
repl.cursor = 0
repl._setRawMode(true)
repl.input # stream
repl.input.removeListener('keypress', onkeypress)
repl.output
repl.output.removeListener('resize', onresize)
repl.columns == repl.output.columns # number of columns in the terminal
repl._refreshLine()
repl.close()
repl.pause()
repl.resume()
repl.write()
repl.question(query, callback)
repl._moveCursor(0)
repl._getCursorPos()
repl._historyNext()
repl._historyPrev()
repl._line()
repl.clearLine()
repl._insertString(string)
repl._wordLeft()
repl._wordRight()
repl._deleteLeft()
repl._deleteRight()
repl._deleteWordLeft()
repl._deleteWordRight()
repl._deleteLineLeft()
repl._deleteLineRight()
# internal variable `kHistorySize` is 30, max length of repl history
# so you might want to customize `repl._addHistory()
repl._addHistory = ->
return '' if @line.length == 0
if @history.length == 0 || @history[0] != @line
@history.unshift(@line)
# Only store so many
@history.pop() if @history.length > repl.maxHistory
@historyIndex = -1
@history[0]
# then set max history
repl.maxHistory = 100