From 87c9f9376213949afc82f85b130f2eb9e7736412 Mon Sep 17 00:00:00 2001 From: Stephen Steneker Date: Wed, 15 Oct 2014 16:01:28 +1100 Subject: [PATCH] Fix #76: Add Support for windows - move config.js before base.js in the Makefile so config options are set first - disable colors if Windows detected - add more verbose windows_warning on startup with suggestion to use ConEmu - add force_color option for Windows users who know their term has color support --- Makefile | 2 +- base.js | 22 ++++++++-------------- config.js | 13 +++++++++++++ hacks/color.js | 2 +- hacks/common.js | 1 + 5 files changed, 24 insertions(+), 16 deletions(-) diff --git a/Makefile b/Makefile index d90d235..2090657 100644 --- a/Makefile +++ b/Makefile @@ -4,7 +4,7 @@ config = config.js all: mongo_hacker.js install -mongo_hacker.js: ${base} ${config} ${hacks} +mongo_hacker.js: ${config} ${base} ${hacks} cat $^ > $@ install: diff --git a/base.js b/base.js index 80ec247..9aeebc4 100644 --- a/base.js +++ b/base.js @@ -1,16 +1,11 @@ -/* - * - * Mongo-Hacker - * MongoDB Shell Enhancements for Hackers - * - * Tyler J. Brock - 2013 - * - * http://tylerbrock.github.com/mongo-hacker - * - */ - -if (_isWindows()) { - print("\nSorry! MongoDB Shell Enhancements for Hackers isn't compatible with Windows.\n"); +if (_isWindows() && mongo_hacker_config['windows_warning']) { + print("\nMongoDB Shell Enhancements for Hackers does not support color highlighting in "); + print("the default Windows Command Prompt. If you are using an alternative console "); + print("such as ConEmu (https://github.com/Maximus5/ConEmu) you may wish to try enabling"); + print("highlighting in your mongo_hacker config by setting:"); + print("\n\tforce_color: true\n"); + print("You can hide this startup warning by setting:"); + print("\n\twindows_warning: false\n"); } if (typeof db !== 'undefined') { @@ -20,4 +15,3 @@ if (typeof db !== 'undefined') { print("Sorry! MongoDB Shell Enhancements for Hackers is only compatible with Mongo 2.2+\n"); } } - diff --git a/config.js b/config.js index 146b06a..4d03aa5 100644 --- a/config.js +++ b/config.js @@ -1,3 +1,14 @@ +/* + * + * Mongo-Hacker + * MongoDB Shell Enhancements for Hackers + * + * Tyler J. Brock - 2013 + * + * http://tylerbrock.github.com/mongo-hacker + * + */ + mongo_hacker_config = { verbose_shell: true, // additional verbosity index_paranoia: false, // querytime explain @@ -8,6 +19,8 @@ mongo_hacker_config = { banner_message: 'Mongo-Hacker ', // banner message version: '0.0.4', // current mongo-hacker version show_banner: true, // show mongo-hacker version banner on startup + windows_warning: true, // show warning banner for windows + force_color: false, // force color highlighting for Windows users // Shell Color Settings // Colors available: red, green, yellow, blue, magenta, cyan diff --git a/hacks/color.js b/hacks/color.js index 0ba070f..8a9801c 100644 --- a/hacks/color.js +++ b/hacks/color.js @@ -31,7 +31,7 @@ function controlCode( parameters ) { }; function applyColorCode( string, properties ) { - return controlCode(properties) + String(string) + controlCode(); + return __colorize ? controlCode(properties) + String(string) + controlCode() : String(string); }; function colorize( string, color ) { diff --git a/hacks/common.js b/hacks/common.js index 24d09df..54f7c11 100644 --- a/hacks/common.js +++ b/hacks/common.js @@ -1,4 +1,5 @@ __indent = Array(mongo_hacker_config.indent + 1).join(' '); +__colorize = (_isWindows() && !mongo_hacker_config['force_color']) ? false : true; ObjectId.prototype.toString = function() { return this.str;