Backporting the REPL fix for Node 0.3.7 and Coffee 1.0-stable
This commit is contained in:
parent
37308e6760
commit
a487259e8e
21
lib/repl.js
21
lib/repl.js
|
@ -1,11 +1,12 @@
|
|||
(function() {
|
||||
var CoffeeScript, error, helpers, readline, repl, run, stdio;
|
||||
var CoffeeScript, error, helpers, readline, repl, run, stdin, stdout;
|
||||
CoffeeScript = require('./coffee-script');
|
||||
helpers = require('./helpers');
|
||||
readline = require('readline');
|
||||
stdio = process.openStdin();
|
||||
stdin = process.openStdin();
|
||||
stdout = process.stdout;
|
||||
error = function(err) {
|
||||
return stdio.write((err.stack || err.toString()) + '\n\n');
|
||||
return stdout.write((err.stack || err.toString()) + '\n\n');
|
||||
};
|
||||
helpers.extend(global, {
|
||||
quit: function() {
|
||||
|
@ -29,13 +30,17 @@
|
|||
return repl.prompt();
|
||||
};
|
||||
process.on('uncaughtException', error);
|
||||
repl = readline.createInterface(stdio);
|
||||
if (readline.createInterface.length < 3) {
|
||||
repl = readline.createInterface(stdin);
|
||||
stdin.on('data', function(buffer) {
|
||||
return repl.write(buffer);
|
||||
});
|
||||
} else {
|
||||
repl = readline.createInterface(stdin, stdout);
|
||||
}
|
||||
repl.setPrompt('coffee> ');
|
||||
stdio.on('data', function(buffer) {
|
||||
return repl.write(buffer);
|
||||
});
|
||||
repl.on('close', function() {
|
||||
return stdio.destroy();
|
||||
return stdin.destroy();
|
||||
});
|
||||
repl.on('line', run);
|
||||
repl.prompt();
|
||||
|
|
|
@ -9,12 +9,13 @@ CoffeeScript = require './coffee-script'
|
|||
helpers = require './helpers'
|
||||
readline = require 'readline'
|
||||
|
||||
# Start by opening up **stdio**.
|
||||
stdio = process.openStdin()
|
||||
# Start by opening up `stdin` and `stdout`.
|
||||
stdin = process.openStdin()
|
||||
stdout = process.stdout
|
||||
|
||||
# Log an error.
|
||||
error = (err) ->
|
||||
stdio.write (err.stack or err.toString()) + '\n\n'
|
||||
stdout.write (err.stack or err.toString()) + '\n\n'
|
||||
|
||||
# Quick alias for quitting the REPL.
|
||||
helpers.extend global, quit: -> process.exit(0)
|
||||
|
@ -34,9 +35,13 @@ run = (buffer) ->
|
|||
process.on 'uncaughtException', error
|
||||
|
||||
# Create the REPL by listening to **stdin**.
|
||||
repl = readline.createInterface stdio
|
||||
if readline.createInterface.length < 3
|
||||
repl = readline.createInterface stdin
|
||||
stdin.on 'data', (buffer) -> repl.write buffer
|
||||
else
|
||||
repl = readline.createInterface stdin, stdout
|
||||
|
||||
repl.setPrompt 'coffee> '
|
||||
stdio.on 'data', (buffer) -> repl.write buffer
|
||||
repl.on 'close', -> stdio.destroy()
|
||||
repl.on 'close', -> stdin.destroy()
|
||||
repl.on 'line', run
|
||||
repl.prompt()
|
||||
|
|
Loading…
Reference in New Issue