diff --git a/chrome/content/vimperator/commands.js b/chrome/content/vimperator/commands.js
index c449ef33..404b30a8 100644
--- a/chrome/content/vimperator/commands.js
+++ b/chrome/content/vimperator/commands.js
@@ -483,15 +483,53 @@ function Commands() //{{{
"Here, downloads can be paused, canceled and resumed."
}
));
- addDefaultCommand(new Command(["ec[ho]"],
- function(args) { vimperator.echo(args); } ,
+
+ function argToString(arg, color)
+ {
+ try
{
+ // TODO: move to vimperator.eval()?
+ arg = eval(arg);
+ }
+ catch (e)
+ {
+ vimperator.echoerr(e.toString());
+ return null;
+ }
+
+ if (typeof arg === "object")
+ arg = vimperator.objectToString(arg, color);
+ else if (typeof arg === "function")
+ arg = arg.toString().replace(//, ">");
+ else if (typeof arg === "number" || typeof arg === "boolean")
+ arg = "" + arg;
+ else if (typeof arg === "undefined")
+ arg = "undefined";
+
+ return arg;
+ }
+ addDefaultCommand(new Command(["ec[ho]"],
+ function(args)
+ {
+ var res = argToString(args, true);
+ if (res != null)
+ vimperator.echo(res);
+ },
+ {
+ usage: ["ec[ho] {arg}"],
short_help: "Display a string at the bottom of the window",
- help: "Echo all arguments of this command. Useful for showing informational messages.
Multiple lines can be separated by \\n."
+ help: "Useful for showing informational messages.Multiple lines can be separated by \\n.
" +
+ " can either be a quoted string, or any expression which can be fed to eval() like 4+5. " +
+ "You can also view the source code of objects and functions if the return value of {arg} is an object or function."
}
));
addDefaultCommand(new Command(["echoe[rr]"],
- function(args) { vimperator.echoerr(args); } ,
+ function(args)
+ {
+ var res = argToString(args, false);
+ if (res != null)
+ vimperator.echoerr(res);
+ },
{
short_help: "Display an error string at the bottom of the window",
help: "Echo all arguments of this command highlighted in red. Useful for showing important messages."
@@ -1565,7 +1603,7 @@ function Commands() //{{{
// TODO: if special, run the last command
var output = vimperator.system(args)
if (typeof output === "string")
- vimperator.echo("" + output + "
");
+ vimperator.echo(output);
else
vimperator.echoerr("Invalid system command: " + args);
},
diff --git a/chrome/content/vimperator/ui.js b/chrome/content/vimperator/ui.js
index 2f314915..9e9039af 100644
--- a/chrome/content/vimperator/ui.js
+++ b/chrome/content/vimperator/ui.js
@@ -185,9 +185,7 @@ function CommandLine() //{{{
multiline_input_widget.collapsed = true;
- var output = str.replace(/\n|\\n/g, "
");
- //output = ":" + command_widget.value + "
" + output;
- output += "
"
+ var output = "" + str + "
";
output += 'Press ENTER or type command to continue';
output += '';
output += "-- More --";
@@ -289,7 +287,7 @@ function CommandLine() //{{{
str = "";
setNormalStyle();
- if (flags || str.indexOf("\n") > -1 || str.indexOf("\\n") > -1 || str.indexOf("
") > -1 || str.indexOf("
") > -1)
+ if (flags || str.indexOf("\n") > -1 || str.indexOf("
") > -1 || str.indexOf("
") > -1)
{
setMultiline(str);
}
diff --git a/chrome/content/vimperator/vimperator.js b/chrome/content/vimperator/vimperator.js
index 4ba3e94d..920f10d2 100644
--- a/chrome/content/vimperator/vimperator.js
+++ b/chrome/content/vimperator/vimperator.js
@@ -346,39 +346,89 @@ const vimperator = (function() //{{{
}
},
- // logs a message to the javascript error console
- log: function(msg, level)
+ // if color = true it uses HTML markup to color certain items
+ objectToString: function(object, color)
{
- // if (Options.getPref("verbose") >= level) // FIXME: hangs vimperator, probably timing issue --mst
- console_service.logStringMessage('vimperator: ' + msg);
- },
-
- // log an object to the javascript error console and print all
- // properties of the object
- logObject: function(object, level)
- {
- if (typeof object != 'object')
+ if (object === null)
+ return "null";
+ if (typeof object != "object")
return false;
- var string = object + '::\n';
+ var string = "";
+ var obj = "";
+ try { // for window.JSON
+ obj = object.toString();
+ } catch (e) {
+ obj = "<Object>";
+ }
+
+ if (color)
+ string += "" + obj + "::\n";
+ else
+ string += obj + "::\n";
+
for (var i in object)
{
var value;
try
{
- var value = object[i];
+ if (i == "JSON") // without this ugly hack, ":echo window" does not work
+ value = "[object JSON]";
+ else
+ value = object[i];
}
catch (e)
{
value = "";
}
- string += i + ": " + value + "\n";
+ if (color)
+ {
+ // syntax highlighting for special items
+ if (typeof value === "number")
+ value = "" + value + "";
+ else if (typeof value === "string")
+ {
+ value = value.replace(/\n/, "\\n").replace(/, "<");
+ value = "\"" + value + "\"";
+ }
+ else if (typeof value === "boolean")
+ value = "" + value + "";
+ else if (value == null || value == "undefined")
+ value = "" + value + "";
+ else if (typeof value === "object" || typeof value === "function")
+ {
+ // for java packages value.toString() would crash so badly
+ // that we cannot even try/catch it
+ if (/^\[JavaPackage.*\]$/.test(value))
+ value = "[JavaPackage]";
+ else
+ {
+ var str = value.toString();
+ if (typeof str == "string") // can be "undefined"
+ value = str.replace(//g, ">");
+ }
+ }
+
+ string += "" + i + ": " + value + "\n";
+ }
+ else
+ string += i + ": " + value + "\n";
}
- vimperator.log(string, level);
return string;
},
+ // logs a message to the javascript error console
+ // if msg is an object, it is beautified
+ log: function(msg, level)
+ {
+ //if (Options.getPref("verbose") >= level) // FIXME: hangs vimperator, probably timing issue --mst
+ if (typeof msg == "object")
+ msg = this.objectToString(msg, false);
+
+ console_service.logStringMessage('vimperator: ' + msg);
+ },
+
// open one or more URLs
//
// @param urls: either a string or an array of urls