Browse Source

no color output on windows jsconsole

cl-refactor
Marek Kotewicz 10 years ago
parent
commit
ec461cafce
  1. 2
      libjsengine/CMakeLists.txt
  2. 5
      libjsengine/JSV8Engine.cpp
  3. 26
      libjsengine/PrettyPrint.js

2
libjsengine/CMakeLists.txt

@ -22,6 +22,8 @@ eth_add_resources("${CMAKE_CURRENT_SOURCE_DIR}/JSResources.cmake" "JSRES")
message(STATUS "HERE!!! ${JSRES}")
add_library(${EXECUTABLE} ${SRC_LIST} ${HEADERS} ${JSRES})
add_dependencies(${EXECUTABLE} BuildInfo.h)
# macos brew version of v8 needs to be compiled with libstdc++
# it also needs to be dynamic library
# xcode needs libstdc++ to be explicitly set as it's attribute

5
libjsengine/JSV8Engine.cpp

@ -23,6 +23,10 @@
#include <memory>
#include "JSV8Engine.h"
#include "libjsengine/JSEngineResources.hpp"
#include "BuildInfo.h"
#define TO_STRING_HELPER(s) #s
#define TO_STRING(s) TO_STRING_HELPER(s)
using namespace std;
using namespace dev;
@ -145,6 +149,7 @@ JSString JSV8Value::toString() const
JSV8Engine::JSV8Engine(): m_env(JSV8Env::getInstance()), m_scope(new JSV8Scope())
{
JSEngineResources resources;
eval("env = typeof(env) === 'undefined' ? {} : env; env.os = '" TO_STRING(ETH_BUILD_PLATFORM) "'");
string common = resources.loadResourceAsString("common");
string web3 = resources.loadResourceAsString("web3");
string admin = resources.loadResourceAsString("admin");

26
libjsengine/PrettyPrint.js

@ -1,4 +1,14 @@
var prettyPrint = (function () {
var onlyDecentPlatform = function (x) {
return env.os.indexOf('Windows') === -1 ? x : '';
};
var color_red = onlyDecentPlatform('\033[31m');
var color_green = onlyDecentPlatform('\033[32m');
var color_pink = onlyDecentPlatform('\033[35m');
var color_white = onlyDecentPlatform('\033[0m');
var color_blue = onlyDecentPlatform('\033[30m');
function pp(object, indent) {
try {
JSON.stringify(object)
@ -16,13 +26,13 @@ var prettyPrint = (function () {
}
str += " ]";
} else if (object instanceof Error) {
str += "\033[31m" + "Error:\033[0m " + object.message;
str += color_red + "Error: " + color_white + object.message;
} else if (object === null) {
str += "\033[1m\033[30m" + "null";
str += color_blue + "null";
} else if(typeof(object) === "undefined") {
str += "\033[1m\033[30m" + object;
str += color_blue + object;
} else if (isBigNumber(object)) {
str += "\033[32m'" + object.toString(10) + "'";
str += color_green + object.toString(10) + "'";
} else if(typeof(object) === "object") {
str += "{\n";
indent += " ";
@ -41,15 +51,15 @@ var prettyPrint = (function () {
});
str += indent.substr(2, indent.length) + "}";
} else if(typeof(object) === "string") {
str += "\033[32m'" + object + "'";
str += color_green + object + "'";
} else if(typeof(object) === "number") {
str += "\033[31m" + object;
str += color_red + object;
} else if(typeof(object) === "function") {
str += "\033[35m[Function]";
str += color_pink + "[Function]";
} else {
str += object;
}
str += "\033[0m";
str += color_white;
return str;
}
var redundantFields = [

Loading…
Cancel
Save