1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2025-12-22 16:57:57 +01:00

new :set and :prefs commands, tweaked :set output to use colors

This commit is contained in:
Doug Kearns
2007-10-10 02:54:44 +00:00
parent 0e576502d9
commit 21703d5b57
4 changed files with 220 additions and 163 deletions

View File

@@ -1042,11 +1042,35 @@ function Commands() //{{{
}
));
addDefaultCommand(new Command(["pref[erences]", "prefs"],
openPreferences,
function(args, special, count, modifiers)
{
if (!args)
{
// TODO: copy these snippets to more function which should work with :tab xxx
if (modifiers && modifiers.inTab)
{
vimperator.open(special ? "about:config" :
"chrome://browser/content/preferences/preferences.xul", vimperator.NEW_TAB);
}
else
{
if (special) // open firefox settings gui dialog
vimperator.open("about:config", vimperator.CURRENT_TAB);
else
openPreferences();
}
}
else
{
vimperator.echoerr("E488: Trailing characters");
}
},
{
usage: [":pref[erences][!]"],
short_help: "Show Browser Preferences",
help: "You can change the browser preferences from this dialog.<br/>Be aware that not all Firefox preferences work, because Vimperator overrides some keybindings and changes Firefox's GUI.<br/>" +
"Works like <code class=\"command\">:set!</code>, but opens the dialog in a new window instead of a new tab. Use this, if you experience problems/crashes when using <code class=\"command\">:set!</code>"
help: "You can change the browser preferences from this dialog. " +
"Be aware that not all Firefox preferences work, because Vimperator overrides some keybindings and changes Firefox's GUI.<br/>" +
"<code class=\"command\">:prefs!</code> opens about:config in the current tab where you can change advanced Firefox preferences."
}
));
addDefaultCommand(new Command(["qma[rk]"],
@@ -1154,22 +1178,21 @@ function Commands() //{{{
addDefaultCommand(new Command(["se[t]"],
function(args, special, count, modifiers)
{
if (special)
{
vimperator.echo("This WILL show all non-default about:config options");
return;
}
var only_non_default = false; //used for :set to print non-default options
if (!args)
{
// TODO: copy these snippets to more function which should work with :tab xxx
var where = vimperator.CURRENT_TAB;
if (arguments[3] && arguments[3].inTab)
where = vimperator.NEW_TAB;
if (special) // open firefox settings gui dialog
vimperator.open("chrome://browser/content/preferences/preferences.xul", where);
else
vimperator.open("about:config", where);
args = "all?"
only_non_default = true;
}
else
{
// 1 2 3 4 5 6
var matches = args.match(/^\s*(no|inv)?([a-z_]+)([?&!])?(([+-])?=(.*))?/);
var matches = args.match(/^\s*(no|inv)?([a-z]+)([?&!])?(([+-])?=(.*))?/);
if (!matches)
{
vimperator.echoerr("E518: Unknown option: " + args);
@@ -1230,7 +1253,7 @@ function Commands() //{{{
{
if (all)
{
vimperator.options.list();
vimperator.options.list(only_non_default);
}
else
{
@@ -1298,14 +1321,13 @@ function Commands() //{{{
else
vimperator.echoerr("E685: Internal error: option format `" + type + "' not supported");
}
}
},
{
usage: ["se[t][!]", "se[t] {option}?", "se[t] [no]{option}", "se[t] {option}[+-]={value}", "se[t] {option}! | inv{option}", "se[t] {option}&"],
short_help: "Set an option",
help: "Permanently change an option. In contrast to Vim options are stored throughout sessions.<br/>" +
"<code class=\"command\">:set</code> without an argument opens <code>about:config</code> in a new tab to change advanced Firefox options.<br/>" +
"<code class=\"command\">:set!</code> opens the GUI preference panel from Firefox in a new tab.<br/>" +
help: "Permanently change an option. In contrast to Vim options are currently stored throughout sessions.<br/>" +
"<code class=\"command\">:set</code> without an argument shows all Vimperator options which differ from their default values.<br/>" +
"<code class=\"command\">:set!</code> without an argument shows all about:config preferences which differ from their default values.<br/>" +
"There are three types of options: boolean, number and string. " +
"Boolean options must be set with <code class=\"command\">:set option</code> and <code class=\"command\">:set nooption</code>. " +
"Number and string option types must be set with <code class=\"command\">:set option={value}</code>.<br/>" +
@@ -1407,8 +1429,9 @@ function Commands() //{{{
{
usage: ["tab {cmd}"],
short_help: "Execute {cmd} and tell it to output in a new tab",
help: "Works only for commands that support it.<br/>" +
"Example: <code class=\"command\">:tab help tab</code> opens the help in a new tab.",
help: "Works only for commands that support it, currently:" +
"<ul><li>:tab help</li>" +
"<li>:tab prefs[!]</li></ul>",
completer: function(filter) { return vimperator.completion.get_command_completions(filter); }
}
));

View File

@@ -301,25 +301,39 @@ function Options() //{{{
storePreference('dom.popup_allowed_events', popup_allowed_events);
}
this.list = function()
this.list = function(only_non_default)
{
// TODO: columns like Vim?
var list = ":" + vimperator.util.escapeHTML(vimperator.commandline.getCommand()) + "<br/>" +
"<table><tr align=\"left\" class=\"hl-Title\"><th>--- Options ---</th></tr>";
var name, value;
var name, value, def;
for (var i = 0; i < options.length; i++)
{
name = options[i].name;
value = options[i].value;
def = options[i].default_value;
if (only_non_default && value == def)
continue;
if (options[i].type == "boolean")
{
name = value ? " " + name : "no" + name;
if (value != def)
name = "<span style=\"font-weight: bold\">" + name + "</span><span style=\"color: gray\"> (default: " + (def ? "" : "no") + options[i].name + ")</span>";
list += "<tr><td>" + name + "</td></tr>";
}
else
{
if (value != def)
{
name = "<span style=\"font-weight: bold\">" + name + "</span>";
value = vimperator.util.colorize(value, false) + "<span style=\"color: gray\"> (default: " + def + ")</span>";
}
else
value = vimperator.util.colorize(value, false);
list += "<tr><td>" + " " + name + "=" + value + "</td></tr>";
}
}

View File

@@ -32,6 +32,49 @@ vimperator.util = {
var e = window.content.document.createElement("div");
e.appendChild(window.content.document.createTextNode(str));
return e.innerHTML;
},
// TODO: use :highlight color groups
// if "process_strings" is true, any passed strings will be surrounded by " and
// any line breaks are displayed as \n
colorize: function(arg, process_strings)
{
var type = typeof(arg);
if (type == "number")
{
return "<span style=\"color: red;\">" + arg + "</span>";
}
else if (type == "string")
{
if (process_strings)
arg = '"' + vimperator.util.escapeHTML(arg.replace(/\n/, "\\n")) + '"';
return "<span style=\"color: green;\">" + arg + "</span>";
}
else if (type == "boolean")
{
return "<span style=\"color: blue;\">" + arg + "</span>";
}
else if (arg == null || arg == "undefined")
{
return "<span style=\"color: blue;\">" + arg + "</span>";
}
else if (type == "object" || type == "function")
{
// for java packages value.toString() would crash so badly
// that we cannot even try/catch it
if (/^\[JavaPackage.*\]$/.test(arg))
return "[JavaPackage]";
var str = arg.toString();
if (typeof str == "string") // can be "undefined"
return vimperator.util.escapeHTML(str);
else
return "undefined";
}
return arg;
}
}

View File

@@ -434,11 +434,13 @@ const vimperator = (function() //{{{
}
},
// TODO: move to vimp.util.? --mst
// if color = true it uses HTML markup to color certain items
objectToString: function(object, color)
{
if (object === null)
return "null";
if (typeof object != "object")
return false;
@@ -472,32 +474,7 @@ const vimperator = (function() //{{{
if (color)
{
// syntax highlighting for special items
if (typeof value === "number")
value = "<span style=\"color: red;\">" + value + "</span>";
else if (typeof value === "string")
{
value = value.replace(/\n/, "\\n").replace(/</, "&lt;");
value = "<span style=\"color: green;\">\"" + value + "\"</span>";
}
else if (typeof value === "boolean")
value = "<span style=\"color: blue;\">" + value + "</span>";
else if (value == null || value == "undefined")
value = "<span style=\"color: blue;\">" + value + "</span>";
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 = vimperator.util.escapeHTML(str);
}
}
value = vimperator.util.colorize(value, true);
string += "<span style=\"font-weight: bold;\">" + i + "</span>: " + value + "\n";
}
else