Browse files

colors and log prefix representation

  • Loading branch information...
1 parent d88a92d commit 7426d2d195a068fe5451f6f0075a22d5e6774d97 @rlidwka committed Nov 10, 2012
Showing with 59 additions and 55 deletions.
  1. +30 −0 assets/css/pupergrep.css
  2. +29 −55 assets/js/pupergrep.js
View
30 assets/css/pupergrep.css
@@ -72,3 +72,33 @@ li.log .heart {
background-color: white;
}
+.log-prefix {
+ display: inline-block;
+ width: 3em;
+ text-align: center;
+}
+
+.log-prefix-fatal {
+ color: #ff0000;
+}
+
+.log-prefix-error {
+ color: #ee0000;
+}
+
+.log-prefix-warn {
+ color: #cc4466;
+}
+
+.log-prefix-info {
+ color: #3366ff;
+}
+
+.log-prefix-debug {
+ color: #bbb;
+}
+
+.log-prefix-trace {
+ color: #ddd;
+}
+
View
84 assets/js/pupergrep.js
@@ -32,7 +32,6 @@ $(document).ready(function() {
connected = false,
healthIconTimer = undefined,
currentLog = undefined,
- currentLogType = 'ansi',
bufferLength = 20,
outputPaused = false,
mouseDowned = false,
@@ -194,7 +193,6 @@ $(document).ready(function() {
});
currentLog = element.data("log-name");
- currentLogType = element.data("log-type");
rebuildCurrentLink();
@@ -337,22 +335,8 @@ $(document).ready(function() {
container = $("<tr>");
line = $("<td>");
- if (currentLogType == "html") {
- line.html(text);
- } else {
- // escaping html
- text = text.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
- // making some links
- text = text.replace(/(https?:\/\/[^\s]+)/g, function(url) {
- return '<a href="' + url + '">' + url + '</a>';
- });
-
- line.html(text);
- }
-
- if (currentLogType == "ansi") {
- line.colorizeConsoleOutput();
- }
+ line.html(text);
+ line.colorizeConsoleOutput();
if (!isGrepAcceptedLine(text)) {
return;
@@ -469,28 +453,27 @@ $(document).ready(function() {
var text = window.utiljs.inspect(this.origObject, undefined, null, true);
- text = text.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
- // making some links
- text = text.replace(/(https?:\/\/[^\s]+)/g, function(url) {
- return '<a href="' + url + '">' + url + '</a>';
- });
+ text = html_escape(text);
+ text = replaceLeadingSpace(text);
- text = text.replace(/(^|\n)[ \t]+/g, function(br) {
- var result = '<br>';
- for (var i=0; i<br.length; i++) {
- if (br[i] === ' ') result += '&nbsp;';
- if (br[i] === '\t') result += '&nbsp;&nbsp;&nbsp;&nbsp;';
- }
- return result;
- });
-
container = $("<tr>");
container.addClass('log-object');
container.html("<td>"+text+"</td>");
container.colorizeConsoleOutput();
$(this).after(container);
});
+
+ function replaceLeadingSpace(text) {
+ return text.replace(/(^|\n)[ \t]+/g, function(br) {
+ var result = br[0] == '\n' ? '<br>' : '';
+ for (var i=0; i<br.length; i++) {
+ if (br[i] === ' ') result += '&nbsp;';
+ if (br[i] === '\t') result += '&nbsp;&nbsp;&nbsp;&nbsp;';
+ }
+ return result;
+ });
+ };
var interpolateObject = (function() {
function getlvl(x) {
@@ -509,26 +492,6 @@ $(document).ready(function() {
}
}
- // adopted from socket.io
- var levels = {
- fatal: 31,
- error: 31,
- warn: 33,
- info: 36,
- debug: 90,
- trace: 90
- };
-
- var max = 0;
- for (var l in levels) {
- max = Math.max(max, l.length);
- }
-
- var pad = function pad(str) {
- if (str.length < max) return str + new Array(max - str.length + 1).join(' ');
- return str;
- };
-
var print = function print(obj) {
var type = obj.level;
var msg = obj.msg;
@@ -548,16 +511,27 @@ $(document).ready(function() {
}
return window.utiljs.inspect(str, undefined, undefined, true);
});
- return (" \x1b[" + levels[type] + "m" + (pad(type)) + " -\x1b[39m ") + finalmsg;
+ return ("<span class=\"log-prefix log-prefix-"+type+"\">" + type + "</span> &ndash; ") + html_escape(finalmsg);
};
return print;
})();
+ function html_escape(text) {
+ // escaping html
+ text = text.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
+ // making some links
+ text = text.replace(/(https?:\/\/[^\s]+)/g, function(url) {
+ return '<a href="' + url + '">' + url + '</a>';
+ });
+
+ return text;
+ }
+
function objectToText(object) {
if (typeof(object.msg) === 'string') {
- return interpolateObject(object);
+ return interpolateObject(object);
}
- return window.utiljs.inspect(object, undefined, null, true);
+ return html_escape(window.utiljs.inspect(object, undefined, null, true));
};
});

0 comments on commit 7426d2d

Please sign in to comment.