fix donotprintme printed by print()
[plstackapi.git] / planetstack / core / static / shell / opencloud_shell.js
index 861cd10..b08dbfa 100644 (file)
@@ -95,7 +95,7 @@ ReadLine.prototype = {
   },
 
   insertResponse: function(response) {
-    if((response.length < 1) || (response=='"donotprintme"')) {
+    if((response.length < 1) || (response=='"donotprintme"') || (response=='donotprintme')) {
       this.activeLine.parent().append("<p class='response'></p>");
     }
     else {
@@ -354,8 +354,39 @@ MongoHandler.prototype = {
   }
 };
 
+function replaceAll(find, replace, str) {
+  return str.replace(new RegExp(find, 'g'), replace);\r
+}
+
+/* stackoverflow: http://stackoverflow.com/questions/4810841/how-can-i-pretty-print-json-using-javascript */
+function syntaxHighlight(json) {
+    if ( json.hasOwnProperty("__str__")) {
+        return syntaxHighlight(json.__str__());
+    }
+    if (typeof json != 'string') {\r
+         json = JSON.stringify(json, undefined, "\t");\r
+    }\r
+    json = json.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');\r
+    return json.replace(/("(\\u[a-zA-Z0-9]{4}|\\[^u]|[^\\"])*"(\s*:)?|\b(true|false|null)\b|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?)/g, function (match) {\r
+        var cls = 'terminal_number';\r
+        if (/^"/.test(match)) {\r
+            if (/:$/.test(match)) {\r
+                cls = 'terminal_key';\r
+            } else {\r
+                cls = 'terminal_string';\r
+            }\r
+        } else if (/true|false/.test(match)) {\r
+            cls = 'terminal_boolean';\r
+        } else if (/null/.test(match)) {\r
+            cls = 'terminal_null';\r
+        }\r
+        return '<span class="' + cls + '">' + match + '</span>';\r
+    });\r
+}
+
 $htmlFormat = function(obj) {
-  result=tojson(obj, ' ', ' ', true);
+  //JSON.stringify(obj,undefined,2)
+  result=replaceAll("\t","&nbsp;",replaceAll("\n","<br>",syntaxHighlight(obj))); //tojson(obj, ' ', ' ', true);
   return result;
 }