diff --git a/lib/repl.js b/lib/repl.js index f253c4b1..865cf91e 100644 --- a/lib/repl.js +++ b/lib/repl.js @@ -1,9 +1,14 @@ (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, enableColours, 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 = require('vm').Script; + enableColours = false; + if (process.platform !== 'win32') { + enableColours = !process.env.NODE_DISABLE_COLORS; + } stdin = process.openStdin(); stdout = process.stdout; error = function(err) { @@ -24,7 +29,7 @@ filename: 'repl' }); if (val !== void 0) { - process.stdout.write(val + '\n'); + process.stdout.write(inspect(val, false, 2, enableColours) + '\n'); } } catch (err) { error(err); diff --git a/src/repl.coffee b/src/repl.coffee index d2bcc49e..59b2f4ce 100644 --- a/src/repl.coffee +++ b/src/repl.coffee @@ -7,10 +7,16 @@ # Require the **coffee-script** module to get access to the compiler. CoffeeScript = require './coffee-script' readline = require 'readline' +{inspect} = require 'util' {Script} = require 'vm' # REPL Setup +# Config +enableColours = no +unless process.platform is 'win32' + enableColours = not process.env.NODE_DISABLE_COLORS + # Start by opening up `stdin` and `stdout`. stdin = process.openStdin() stdout = process.stdout @@ -32,7 +38,8 @@ run = (buffer) -> backlog = '' try val = CoffeeScript.eval code, bare: on, globals: on, filename: 'repl' - process.stdout.write val + '\n' if val isnt undefined + unless val is undefined + process.stdout.write inspect(val, no, 2, enableColours) + '\n' catch err error err repl.prompt()