Skip to content

Commit

Permalink
Merge pull request #968 from ajaxorg/hotfix/console_updates
Browse files Browse the repository at this point in the history
Hotfix/console updates
  • Loading branch information
Zef Hemel committed Feb 24, 2012
2 parents 5614043 + 3981521 commit 9ce3006
Show file tree
Hide file tree
Showing 10 changed files with 806 additions and 26 deletions.
3 changes: 2 additions & 1 deletion client/ext/console/console.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ var settings = require("core/settings");
var Logger = require("ext/console/logger");
var css = require("text!ext/console/console.css");
var markup = require("text!ext/console/console.xml");
var theme = require("text!ext/console/themes/arthur.css");

// Some constants used throughout the plugin
var RE_band = /^\s*!/;
Expand Down Expand Up @@ -86,7 +87,7 @@ module.exports = ext.register("ext/console/console", {
type : ext.GENERAL,
alone : true,
markup : markup,
css : css,
css : css + theme,
height : 200,
hidden : true,
nodes : [],
Expand Down
97 changes: 72 additions & 25 deletions client/ext/console/logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,7 @@ exports.test = {};
var MAX_LINES = 512;
var RE_relwsp = /(?:\s|^|\.\/)([\w\_\$-]+(?:\/[\w\_\$-]+)+(?:\.[\w\_\$]+))?(\:\d+)(\:\d+)*/g;
var RE_URL = /\b((?:(?:https?):(?:\/{1,3}|[a-z0-9%])|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}\/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()[\]{};:'".,<>?«»“”‘’]))/i;
var RE_COLOR = /\[(?:(\d+);)?(\d+)m/g;
var colors = {
0: "#eee",
31: "red",
32: "green",
33: "yellow",
34: "blue",
35: "magenta",
36: "cyan"
};
var RE_COLOR = /\u001b\[([\d;]+)?m/g;

// Remove as many elements in the console output area so that between
// the existing buffer and the stream coming in we have the right
Expand Down Expand Up @@ -61,6 +52,8 @@ var createItem = module.exports.test.createItem = function(line, ide) {
var davPrefix = ide.davPrefix;
var wsRe = new RegExp(escRegExp(workspaceDir) + "\\/([^:]*)(:\\d+)(:\\d+)*", "g");

line = apf.escapeXML(line);

if ((line.search(RE_relwsp) !== -1) || (line.search(wsRe) !== -1)) {
var html = "<a href='#' data-wsp='" + davPrefix + "/$1,$2,$3'>___$1$2$3</a>";
line = line
Expand All @@ -70,26 +63,79 @@ var createItem = module.exports.test.createItem = function(line, ide) {
else if (line.search(RE_URL) !== -1) {
line = line.replace(RE_URL, "<a href='$1' target='_blank'>$1</a>");
}

return line

var open = 0;
line = line
.replace(/\s{2,}/g, function(str) { return strRepeat("&nbsp;", str.length); })
.replace(/(\u0007|\u001b)\[(K|2J)/g, "")
.replace(RE_COLOR, function(m, extra, color) {
var styles = [
"color: " + (colors[color] || colors[0]),
extra === 1 ? ";font-weight: bold" : "",
extra === 4 ? ";text-decoration: underline" : ""
];
return "<span style='" + styles.join("").trim() + "'>";
});
.replace(RE_COLOR, function(m, style) {
if (!style)
return "";
style = parseInt(style.replace(";", ""), 10);
// check for end of style delimiters
if (open > 0 && (style === 39 || (style < 30 && style > 20))) {
--open;
return "</span>";
}
else {
if (style === 1) {
++open;
return "<span class=\"term_boldColor\" style=\"font-weight:bold\">";
}
else if (style === 3) {
++open;
return "<span style=\"font-style:italic\">";
}
else if (style === 4) {
++open;
return "<span style=\"text-decoration:underline\">";
}
else if (style >= 30 && !(style > 40 && style < 50)) {
++open;
var ansiColor = (style % 30);
if (ansiColor >= 10)
ansiColor -= 2;
return "<span class=\"term_ansi" + ansiColor + "Color\">";
}
else
return "";
}
})
.replace(/(\u0007|\u001b)\[(K|2J)/g, "");

if (open > 0)
return line + (new Array(open + 1).join("</span>"));
return line;
};

var childBuffer = {};
var childBufferInterval = {};
var eventsAttached;

var getOutputElement = function(choice) {
var ret = {
element: txtConsole.$ext,
id: "console"
};
if (!choice)
return ret;

// legacy support: choice passed as Boolean TRUE means 'use txtOutput'.
if (typeof choice == "boolean" && choice) {
ret.element = txtOutput.$ext;
ret.id = "output";
}
else if (choice.$ext && choice.id) {
ret.element = choice.$ext;
ret.id = choice.id;
}

return ret;
}

module.exports.logNodeStream = function(data, stream, useOutput, ide) {
var parentEl = (useOutput ? txtOutput : txtConsole).$ext;
var outputId = useOutput ? "output" : "console";
var out = getOutputElement(useOutput);
var parentEl = out.element;
var outputId = out.id;

if (eventsAttached !== true) {
parentEl.addEventListener("click", function(e) {
Expand Down Expand Up @@ -145,8 +191,9 @@ module.exports.log = function(msg, type, pre, post, useOutput) {
msg = messages[type].replace("__MSG__", msg);
}

var parentEl = (useOutput ? txtOutput : txtConsole).$ext;
var outputId = useOutput ? "output" : "console";
var out = getOutputElement(useOutput);
var parentEl = out.element;
var outputId = out.id;

if (!bufferInterval[outputId]) {
setBufferInterval(parentEl, outputId);
Expand Down
53 changes: 53 additions & 0 deletions client/ext/console/test_colors.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
var Util = require("util");

var levels = {
"info": ["\033[1m\033[90m", "\033[39m\033[22m"], // grey
"error": ["\033[31m", "\033[39m"], // red
"fatal": ["\033[35m", "\033[39m"], // magenta
"exit": ["\033[36m", "\033[39m"] // cyan
};
var _slice = Array.prototype.slice;


var log = function() {
var args = _slice.call(arguments);
var lastArg = args[args.length - 1];

var level = levels[lastArg] ? args.pop() : "info";
if (!args.length)
return;

var msg = args.map(function(arg) {
return typeof arg != "string" ? Util.inspect(arg) : arg;
}).join(" ");
var pfx = levels[level][0] + "[" + level + "]" + levels[level][1];

msg.split("\n").forEach(function(line) {
console.log(pfx + " " + line);
});
};

log("This is info");
log("This is error", "error");
log("This is fatal", "fatal");
log("This is exit", "exit");

console.log("");

// classic, additional test:
var T = "gYw"; // The test text

console.log("\n 40m 41m 42m 43m\
44m 45m 46m 47m");

[' m', ' 1m', ' 30m', '1;30m', ' 31m', '1;31m', ' 32m', '1;32m', ' 33m',
'1;33m', ' 34m', '1;34m', ' 35m', '1;35m', ' 36m', '1;36m', ' 37m',
'1;37m'].forEach(function(FGs) {
var FG = FGs.replace(/[\s\t]+/g, "");
console.log(" " + FGs + " \033[" + FG + " " + T + " ");
//["40m", "41m", "42m,", "43m", "44m", "45m", "46m", "47m"].forEach(function(BG) {
// console.log("\033[" + FG + "\033[" + BG + " " + T + " \033[0m");
//});
});

log("<b>" + levels["fatal"][0] + "Lastly:" + levels["fatal"][1] + " some HTML!</b>");
97 changes: 97 additions & 0 deletions client/ext/console/themes/arthur.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
/**
* This stylesheet is generated automatically, please don't edit manually.
* Generated by iterm2css - http://github.com/mikedeboer/iterm2css
*/

.term_ansi0Color {
color: rgb(61, 53, 42);
}

.term_ansi1Color {
color: rgb(205, 92, 92);
}

.term_ansi10Color {
color: rgb(136, 170, 34);
}

.term_ansi11Color {
color: rgb(255, 167, 93);
}

.term_ansi12Color {
color: rgb(135, 206, 235);
}

.term_ansi13Color {
color: rgb(153, 102, 0);
}

.term_ansi14Color {
color: rgb(176, 196, 222);
}

.term_ansi15Color {
color: rgb(221, 204, 187);
}

.term_ansi2Color {
color: rgb(134, 175, 128);
}

.term_ansi3Color {
color: rgb(232, 174, 91);
}

.term_ansi4Color {
color: rgb(100, 149, 237);
}

.term_ansi5Color {
color: rgb(222, 184, 135);
}

.term_ansi6Color {
color: rgb(176, 196, 222);
}

.term_ansi7Color {
color: rgb(187, 170, 153);
}

.term_ansi8Color {
color: rgb(85, 68, 68);
}

.term_ansi9Color {
color: rgb(204, 85, 51);
}

.term_backgroundColor {
background-color: rgb(28, 28, 28);
}

.term_boldColor {
color: rgb(255, 255, 255);
}

.term_cursorColor {
background-color: rgb(226, 187, 239);
}

.term_cursorTextColor {
background-color: rgb(0, 0, 0);
}

.term_foregroundColor {
color: rgb(221, 238, 221);
}

.term_selectedTextColor {
color: rgb(255, 255, 255);
}

.term_selectionColor {
color: rgb(77, 77, 77);
}

97 changes: 97 additions & 0 deletions client/ext/console/themes/n0tch2k.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
/**
* This stylesheet is generated automatically, please don't edit manually.
* Generated by iterm2css - http://github.com/mikedeboer/iterm2css
*/

.term_ansi0Color {
color: rgb(56, 56, 56);
}

.term_ansi1Color {
color: rgb(169, 85, 81);
}

.term_ansi10Color {
color: rgb(140, 140, 140);
}

.term_ansi11Color {
color: rgb(169, 145, 117);
}

.term_ansi12Color {
color: rgb(152, 189, 94);
}

.term_ansi13Color {
color: rgb(163, 163, 163);
}

.term_ansi14Color {
color: rgb(220, 220, 220);
}

.term_ansi15Color {
color: rgb(216, 200, 187);
}

.term_ansi2Color {
color: rgb(102, 102, 102);
}

.term_ansi3Color {
color: rgb(169, 128, 81);
}

.term_ansi4Color {
color: rgb(101, 125, 62);
}

.term_ansi5Color {
color: rgb(118, 118, 118);
}

.term_ansi6Color {
color: rgb(201, 201, 201);
}

.term_ansi7Color {
color: rgb(208, 184, 163);
}

.term_ansi8Color {
color: rgb(71, 71, 71);
}

.term_ansi9Color {
color: rgb(169, 119, 117);
}

.term_backgroundColor {
background-color: rgb(34, 34, 34);
}

.term_boldColor {
color: rgb(229, 229, 229);
}

.term_cursorColor {
background-color: rgb(169, 144, 117);
}

.term_cursorTextColor {
background-color: rgb(0, 0, 0);
}

.term_foregroundColor {
color: rgb(160, 160, 160);
}

.term_selectedTextColor {
color: rgb(255, 255, 255);
}

.term_selectionColor {
color: rgb(77, 77, 77);
}

Loading

0 comments on commit 9ce3006

Please sign in to comment.