From 20327d8fb63bff8ee5998fb4bb8a81134470a30c Mon Sep 17 00:00:00 2001 From: Tom Robinson Date: Sun, 7 Mar 2010 16:17:25 -0800 Subject: [PATCH] Move CPLog css file inline, remove redundant ANSI control sequence stuff, automatically use command line tool name in CPLog title. --- Foundation/Resources/log.css | 72 ----------------- Objective-J/CPLog.js | 145 +++++++++++++---------------------- 2 files changed, 55 insertions(+), 162 deletions(-) delete mode 100644 Foundation/Resources/log.css diff --git a/Foundation/Resources/log.css b/Foundation/Resources/log.css deleted file mode 100644 index 8a4ed37bc..000000000 --- a/Foundation/Resources/log.css +++ /dev/null @@ -1,72 +0,0 @@ -body { - font: 10px Monaco, Courier, "Courier New", monospace, mono; - padding-top: 15px; -} - -div > .fatal, div > .error, div > .warn, div > .info, div > .debug, div > .trace { - display: none; - overflow: hidden; - white-space: pre; - padding: 0px 5px 0px 5px; - margin-top: 2px; - -moz-border-radius: 5px; - -webkit-border-radius: 5px; -} - -div[wrap="yes"] > div { - white-space: normal; -} - -.fatal { background-color: #ffb2b3; } -.error { background-color: #ffe2b2; } -.warn { background-color: #fdffb2; } -.info { background-color: #e4ffb2; } -.debug { background-color: #a0e5a0; } -.trace { background-color: #99b9ff; } - -.enfatal .fatal, .enerror .error, .enwarn .warn, .eninfo .info, .endebug .debug, .entrace .trace { display: block; } - -div#header { - background-color: rgba(240,240,240,0.82); - position: fixed; - top: 0px; - left: 0px; - width: 100%; - border-bottom: 1px solid rgba(0,0,0,0.33); - text-align: center; - /*opacity: 0.2;*/ -} -/* -div#header:hover { - opacity: 1.0; -} -*/ -ul#enablers { - display: inline-block; - margin: 1px 15px 0 15px; - padding: 2px 0 2px 0; -} - -ul#enablers li { - display: inline; - padding: 0px 5px 0px 5px; - margin-left: 4px; - -moz-border-radius: 5px; - -webkit-border-radius: 5px; -} - -[enabled="no"] { - opacity: 0.25; -} - -ul#options { - display: inline-block; - margin: 0 15px 0px 15px; - padding: 0 0px; -} - -ul#options li { - margin: 0 0 0 0; - padding: 0 0 0 0; - display: inline; -} \ No newline at end of file diff --git a/Objective-J/CPLog.js b/Objective-J/CPLog.js index af76a7991..a0f5765b5 100644 --- a/Objective-J/CPLog.js +++ b/Objective-J/CPLog.js @@ -114,81 +114,6 @@ var _CPFormatLogMessage = function(aString, aLevel, aTitle) // Loggers: -var ANSI_ESC = String.fromCharCode(0x1B); -var ANSI_CSI = ANSI_ESC + '['; -var ANSI_TEXT_PROP = 'm'; -var ANSI_RESET = '0'; -var ANSI_BOLD = '1'; -var ANSI_FAINT = '2'; // unsupported? -var ANSI_NORMAL = '22'; -var ANSI_ITALIC = '3'; // unsupported? -var ANSI_UNDER = '4'; -var ANSI_UNDER_DBL = '21'; // unsupported? -var ANSI_UNDER_OFF = '24'; -var ANSI_BLINK = '5'; -var ANSI_BLINK_FAST = '6'; // unsupported? -var ANSI_BLINK_OFF = '25'; -var ANSI_REVERSE = '7'; -var ANSI_POSITIVE = '27'; -var ANSI_CONCEAL = '8'; -var ANSI_REVEAL = '28'; -var ANSI_FG = '3'; -var ANSI_BG = '4'; -var ANSI_FG_INTENSE = '9'; -var ANSI_BG_INTENSE = '10'; -var ANSI_BLACK = '0'; -var ANSI_RED = '1'; -var ANSI_GREEN = '2'; -var ANSI_YELLOW = '3'; -var ANSI_BLUE = '4'; -var ANSI_MAGENTA = '5'; -var ANSI_CYAN = '6'; -var ANSI_WHITE = '7'; - -var colorCodeMap = { - "black" : ANSI_BLACK, - "red" : ANSI_RED, - "green" : ANSI_GREEN, - "yellow" : ANSI_YELLOW, - "blue" : ANSI_BLUE, - "magenta" : ANSI_MAGENTA, - "cyan" : ANSI_CYAN, - "white" : ANSI_WHITE -} - -function ANSIControlCode(code, parameters) -{ - if (parameters == undefined) - parameters = ""; - else if (typeof(parameters) == 'object' && (parameters instanceof Array)) - parameters = parameters.join(';'); - return ANSI_CSI + String(parameters) + String(code); -} - -// simple text helpers: - -function ANSITextApplyProperties(string, properties) -{ - return ANSIControlCode(ANSI_TEXT_PROP, properties) + String(string) + ANSIControlCode(ANSI_TEXT_PROP); -} - -GLOBAL(ANSITextColorize) = function(string, color) -{ - if (colorCodeMap[color] == undefined) - return string; - return ANSITextApplyProperties(string, ANSI_FG + colorCodeMap[color]); -} - -// CPLogPrint uses the print() functions present in many non-browser command line JavaScript interpreters -var levelColorMap = { - "fatal": "red", - "error": "red", - "warn" : "yellow", - "info" : "green", - "debug": "cyan", - "trace": "blue" -} - // CPLogConsole uses the built in "console" object GLOBAL(CPLogConsole) = function(aString, aLevel, aTitle) { @@ -213,18 +138,46 @@ GLOBAL(CPLogConsole) = function(aString, aLevel, aTitle) } #if COMMONJS + +var levelColorMap = { + "fatal": "red", + "error": "red", + "warn" : "yellow", + "info" : "green", + "debug": "cyan", + "trace": "blue" +} + +try { + var SYSTEM = require("system"); + var FILE = require("file"); + if (SYSTEM.args[0]) + CPLogDefaultTitle = FILE.basename(SYSTEM.args[0]); +} catch (e) { +} + +var stream; + GLOBAL(CPLogPrint) = function(aString, aLevel, aTitle) { - if (typeof print != "undefined") - { - if (aLevel == "fatal" || aLevel == "error" || aLevel == "warn") - var message = ANSITextColorize(_CPFormatLogMessage(aString, aLevel, aTitle), levelColorMap[aLevel]); - else - var message = _CPFormatLogMessage(aString, ANSITextColorize(aLevel, levelColorMap[aLevel]), aTitle); + if (stream === undefined) { + try { + stream = require("term").stream; + } catch (e) { + stream = null; + } + } - require("system").stderr.print(message); + if (stream) { + if (aLevel == "fatal" || aLevel == "error" || aLevel == "warn") + stream.print("\0"+levelColorMap[aLevel]+"(" + _CPFormatLogMessage(aString, aLevel, aTitle) + "\0)"); + else + stream.print(_CPFormatLogMessage(aString, "\0"+levelColorMap[aLevel]+"(" + aLevel + "\0)", aTitle)); + } else if (typeof print != "undefined") { + print(_CPFormatLogMessage(aString, aLevel, aTitle)) } } + #else // CPLogAlert uses basic browser alert() functions @@ -276,12 +229,31 @@ GLOBAL(CPLogPopup) = function(aString, aLevel, aTitle) } } +var CPLogPopupStyle =''; + function _CPLogInitPopup(logWindow) { var doc = logWindow.document; // HACK so that head is available below: - doc.writeln(""); + doc.writeln(""+CPLogPopupStyle+""); doc.title = CPLogDefaultTitle + " Run Log"; @@ -291,13 +263,6 @@ function _CPLogInitPopup(logWindow) var base = window.location.protocol + "//" + window.location.host + window.location.pathname; base = base.substring(0,base.lastIndexOf("/")+1); - var link = doc.createElement("link"); - link.setAttribute("type", "text/css"); - link.setAttribute("rel", "stylesheet"); - link.setAttribute("href", base+"Frameworks/Foundation/Resources/log.css"); - link.setAttribute("media", "screen"); - head.appendChild(link); - var div = doc.createElement("div"); div.setAttribute("id", "header"); body.appendChild(div);