pretty node-like output in the REPL

This commit is contained in:
Michael Ficarra
2011-04-05 20:40:54 -04:00
parent 31ae260282
commit 68c75c7eb1
2 changed files with 5 additions and 3 deletions

View File

@@ -1,8 +1,9 @@
(function() {
var ACCESSOR, CoffeeScript, SIMPLEVAR, Script, autocomplete, backlog, completeAttribute, completeVariable, error, getCompletions, getPropertyNames, readline, repl, run, stdin, stdout;
var ACCESSOR, CoffeeScript, SIMPLEVAR, Script, autocomplete, backlog, completeAttribute, completeVariable, error, getCompletions, getPropertyNames, inspect, readline, repl, run, stdin, stdout;
var __hasProp = Object.prototype.hasOwnProperty;
CoffeeScript = require('./coffee-script');
readline = require('readline');
inspect = require('util').inspect;
Script = process.binding('evals').Script;
stdin = process.openStdin();
stdout = process.stdout;
@@ -24,7 +25,7 @@
filename: 'repl'
});
if (val !== void 0) {
process.stdout.write(val + '\n');
process.stdout.write(inspect(val, false, 2, true) + '\n');
}
} catch (err) {
error(err);

View File

@@ -7,6 +7,7 @@
# Require the **coffee-script** module to get access to the compiler.
CoffeeScript = require './coffee-script'
readline = require 'readline'
{inspect} = require 'util'
Script = process.binding('evals').Script
# REPL Setup
@@ -32,7 +33,7 @@ run = (buffer) ->
backlog = ''
try
val = CoffeeScript.eval code, bare: on, globals: on, filename: 'repl'
process.stdout.write val + '\n' if val isnt undefined
process.stdout.write inspect(val, no, 2, yes) + '\n' if val isnt undefined
catch err
error err
repl.prompt()