From 5d600ce31b1d1162529ae8043bb342e2165c4b13 Mon Sep 17 00:00:00 2001 From: Jermolene Date: Tue, 21 Oct 2014 19:30:27 +0100 Subject: [PATCH] Coloured warnings and errors under Node.js --- boot/boot.js | 2 +- core/modules/utils/utils.js | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/boot/boot.js b/boot/boot.js index 47077c3ac..7c144a4a5 100644 --- a/boot/boot.js +++ b/boot/boot.js @@ -121,7 +121,7 @@ $tw.utils.error = function(err) { var errHeading = "Internal JavaScript Error", promptMsg = "Well, this is embarrassing. It is recommended that you restart TiddlyWiki by refreshing your browser"; // Log the error to the console - console.error(err); + console.error($tw.node ? "\x1b[1;31m" + err + "\x1b[0m" : err); if($tw.browser && !$tw.node) { // Display an error message to the user var dm = $tw.utils.domMaker, diff --git a/core/modules/utils/utils.js b/core/modules/utils/utils.js index b4242e1d0..9f9b041d3 100644 --- a/core/modules/utils/utils.js +++ b/core/modules/utils/utils.js @@ -12,6 +12,13 @@ Various static utility functions. /*global $tw: false */ "use strict"; +/* +Display a warning, in colour if we're on a terminal +*/ +exports.warning = function(text) { + console.log($tw.node ? "\x1b[1;33m" + text + "\x1b[0m" : text); +} + /* Trim whitespace from the start and end of a string Thanks to Steven Levithan, http://blog.stevenlevithan.com/archives/faster-trim-javascript