From 68c75c7eb165696345176d37eb9fc1d57e347ebf Mon Sep 17 00:00:00 2001 From: Michael Ficarra Date: Tue, 5 Apr 2011 20:40:54 -0400 Subject: [PATCH 1/3] pretty node-like output in the REPL --- lib/repl.js | 5 +++-- src/repl.coffee | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/repl.js b/lib/repl.js index 1878382b..219aa3f7 100644 --- a/lib/repl.js +++ b/lib/repl.js @@ -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); diff --git a/src/repl.coffee b/src/repl.coffee index d986e87b..17b70806 100644 --- a/src/repl.coffee +++ b/src/repl.coffee @@ -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() From 8e7c454de050dc64e0e15bd2ee0f71446d5a0114 Mon Sep 17 00:00:00 2001 From: Michael Ficarra Date: Tue, 5 Apr 2011 20:51:28 -0400 Subject: [PATCH 2/3] disabling colours for win32 and in presence of NODE_DISABLE_COLORS environment variable --- lib/repl.js | 8 ++++++-- src/repl.coffee | 7 ++++++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/lib/repl.js b/lib/repl.js index 219aa3f7..d74d9391 100644 --- a/lib/repl.js +++ b/lib/repl.js @@ -1,10 +1,14 @@ (function() { - var ACCESSOR, CoffeeScript, SIMPLEVAR, Script, autocomplete, backlog, completeAttribute, completeVariable, error, getCompletions, getPropertyNames, inspect, 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 = process.binding('evals').Script; + enableColours = false; + if (process.platform !== 'win32') { + enableColours = !process.env.NODE_DISABLE_COLORS; + } stdin = process.openStdin(); stdout = process.stdout; error = function(err) { @@ -25,7 +29,7 @@ filename: 'repl' }); if (val !== void 0) { - process.stdout.write(inspect(val, false, 2, true) + '\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 17b70806..f3d02dc3 100644 --- a/src/repl.coffee +++ b/src/repl.coffee @@ -12,6 +12,11 @@ Script = process.binding('evals').Script # REPL Setup +# Config +enableColours = no +if process.platform isnt 'win32' + enableColours = !process.env.NODE_DISABLE_COLORS + # Start by opening up `stdin` and `stdout`. stdin = process.openStdin() stdout = process.stdout @@ -33,7 +38,7 @@ run = (buffer) -> backlog = '' try val = CoffeeScript.eval code, bare: on, globals: on, filename: 'repl' - process.stdout.write inspect(val, no, 2, yes) + '\n' if val isnt undefined + process.stdout.write inspect(val, no, 2, enableColours) + '\n' if val isnt undefined catch err error err repl.prompt() From d0f047dfe7ab863dc2fb755d5569bdce463d9623 Mon Sep 17 00:00:00 2001 From: Michael Ficarra Date: Thu, 7 Apr 2011 19:40:45 -0400 Subject: [PATCH 3/3] improved fix for #1266 --- src/repl.coffee | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/repl.coffee b/src/repl.coffee index f3d02dc3..308612cf 100644 --- a/src/repl.coffee +++ b/src/repl.coffee @@ -14,8 +14,8 @@ Script = process.binding('evals').Script # Config enableColours = no -if process.platform isnt 'win32' - enableColours = !process.env.NODE_DISABLE_COLORS +unless process.platform is 'win32' + enableColours = not process.env.NODE_DISABLE_COLORS # Start by opening up `stdin` and `stdout`. stdin = process.openStdin() @@ -38,7 +38,8 @@ run = (buffer) -> backlog = '' try val = CoffeeScript.eval code, bare: on, globals: on, filename: 'repl' - process.stdout.write inspect(val, no, 2, enableColours) + '\n' if val isnt undefined + unless val is undefined + process.stdout.write inspect(val, no, 2, enableColours) + '\n' catch err error err repl.prompt()