1
0
Fork 0
mirror of https://github.com/jashkenas/coffeescript.git synced 2022-11-09 12:23:24 -05:00

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

@ -156,15 +156,31 @@
on: function() {}
};
stdin.on('data', function(chunk) {
return pipedInput += chunk;
});
stdin.on('end', function() {
var line, _i, _len, _ref;
_ref = pipedInput.trim().split("\n");
var line, lines, _i, _len, _ref, _results;
pipedInput += chunk;
if (-1 === pipedInput.indexOf("\n")) {
return;
}
lines = pipedInput.split("\n");
pipedInput = lines[lines.length - 1];
_ref = lines.slice(0, -1);
_results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
line = _ref[_i];
stdout.write("" + line + "\n");
run(line);
_results.push(run(line));
}
return _results;
});
stdin.on('end', function() {
var line, trimmedInput, _i, _len, _ref;
if (trimmedInput = pipedInput.trim()) {
_ref = trimmedInput.split("\n");
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
line = _ref[_i];
stdout.write("" + line + "\n");
run(line);
}
}
stdout.write('\n');
return process.exit(0);

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