fixed REPL to allow streamed input from stdin

This commit is contained in:
Michael Ficarra
2012-05-14 15:48:59 -04:00
parent 7792a3a6e3
commit 66c751be11
2 changed files with 31 additions and 8 deletions

View File

@@ -119,10 +119,17 @@ if stdin.readable
on: ->
stdin.on 'data', (chunk) ->
pipedInput += chunk
stdin.on 'end', ->
for line in pipedInput.trim().split "\n"
return if -1 is pipedInput.indexOf "\n"
lines = pipedInput.split "\n"
pipedInput = lines[lines.length - 1]
for line in lines[...-1]
stdout.write "#{line}\n"
run line
stdin.on 'end', ->
if trimmedInput = pipedInput.trim()
for line in trimmedInput.split "\n"
stdout.write "#{line}\n"
run line
stdout.write '\n'
process.exit 0
else