adding newlines after error stacktrace in REPL.

This commit is contained in:
Jeremy Ashkenas 2010-12-05 15:46:04 -05:00
parent 77e13e459b
commit b18d0d75fd
2 changed files with 12 additions and 8 deletions

View File

@ -1,9 +1,12 @@
(function() {
var CoffeeScript, helpers, readline, repl, run, stdio;
var CoffeeScript, error, helpers, readline, repl, run, stdio;
CoffeeScript = require('./coffee-script');
helpers = require('./helpers');
readline = require('readline');
stdio = process.openStdin();
error = function(err) {
return stdio.write((err.stack || err.toString()) + '\n\n');
};
helpers.extend(global, {
quit: function() {
return process.exit(0);
@ -21,13 +24,11 @@
console.log(val);
}
} catch (err) {
stdio.write(err.stack || err.toString());
error(err);
}
return repl.prompt();
};
process.on('uncaughtException', function(err) {
return stdio.write(err.stack || err.toString());
});
process.on('uncaughtException', error);
repl = readline.createInterface(stdio);
repl.setPrompt('coffee> ');
stdio.on('data', function(buffer) {

View File

@ -12,6 +12,10 @@ readline = require 'readline'
# Start by opening up **stdio**.
stdio = process.openStdin()
# Log an error.
error = (err) ->
stdio.write (err.stack or err.toString()) + '\n\n'
# Quick alias for quitting the REPL.
helpers.extend global, quit: -> process.exit(0)
@ -23,12 +27,11 @@ run = (buffer) ->
val = CoffeeScript.eval buffer.toString(), bare: on, globals: on, fileName: 'repl'
console.log val if val isnt undefined
catch err
stdio.write err.stack or err.toString()
error err
repl.prompt()
# Make sure that uncaught exceptions don't kill the REPL.
process.on 'uncaughtException', (err) ->
stdio.write err.stack or err.toString()
process.on 'uncaughtException', error
# Create the REPL by listening to **stdin**.
repl = readline.createInterface stdio