Merge branch 'readline0.3.6' of https://github.com/agnoster/coffee-script into agnoster

This commit is contained in:
Timothy Jones
2011-01-23 00:43:18 +13:00
2 changed files with 23 additions and 13 deletions

View File

@@ -1,12 +1,13 @@
(function() {
var ACCESSOR, CoffeeScript, SIMPLEVAR, Script, autocomplete, backlog, completeAttribute, completeVariable, error, getCompletions, getPropertyNames, readline, repl, run, stdio;
var ACCESSOR, CoffeeScript, SIMPLEVAR, Script, autocomplete, backlog, completeAttribute, completeVariable, error, getCompletions, getPropertyNames, readline, repl, run, stdin, stdout;
var __hasProp = Object.prototype.hasOwnProperty;
CoffeeScript = require('./coffee-script');
readline = require('readline');
Script = process.binding('evals').Script;
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');
};
backlog = '';
run = function(buffer) {
@@ -77,13 +78,17 @@
return _results;
};
process.on('uncaughtException', error);
repl = readline.createInterface(stdio, autocomplete);
if (readline.createInterface.length === 3) {
repl = readline.createInterface(stdin, stdout, autocomplete);
} else {
repl = readline.createInterface(stdin, autocomplete);
stdin.on('data', function(buffer) {
return repl.write(buffer);
});
}
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();

View File

@@ -12,11 +12,12 @@ Script = process.binding('evals').Script
# REPL Setup
# Start by opening up **stdio**.
stdio = process.openStdin()
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'
# The current backlog of multi-line code.
backlog = ''
@@ -76,9 +77,13 @@ getPropertyNames = (obj) ->
process.on 'uncaughtException', error
# Create the REPL by listening to **stdin**.
repl = readline.createInterface stdio, autocomplete
if readline.createInterface.length == 3
repl = readline.createInterface stdin, stdout, autocomplete
else
repl = readline.createInterface stdin, autocomplete
stdin.on 'data', (buffer) -> repl.write buffer
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()