X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=common%2Fmodules%2Foptions.jsm;h=1440e23cd6e7b0ad6d5dc4abc944db69fed729ce;hb=8b6fcae7eaa413bc62d645d2d0c99835c47265e6;hp=512e304f789b800506c8fe4be6fa6e13f6d6f223;hpb=9044153cb63835e39b9de8ec4ade237c03e3888a;p=dactyl.git diff --git a/common/modules/options.jsm b/common/modules/options.jsm index 512e304..1440e23 100644 --- a/common/modules/options.jsm +++ b/common/modules/options.jsm @@ -4,17 +4,22 @@ // // This work is licensed for reuse under an MIT license. Details are // given in the LICENSE.txt file included with this file. -/* use strict */ +"use strict"; try { -Components.utils.import("resource://dactyl/bootstrap.jsm"); defineModule("options", { exports: ["Option", "Options", "ValueError", "options"], require: ["contexts", "messages", "storage"] -}, this); +}); -this.lazyRequire("config", ["config"]); +lazyRequire("cache", ["cache"]); +lazyRequire("config", ["config"]); +lazyRequire("commands", ["Commands"]); +lazyRequire("completion", ["CompletionContext"]); +lazyRequire("prefs", ["prefs"]); +lazyRequire("styles", ["Styles"]); +lazyRequire("template", ["template"]); /** @scope modules */ @@ -339,7 +344,9 @@ var Option = Class("Option", { if (isArray(defaultValue)) defaultValue = defaultValue.map(Option.quote).join(","); else if (isObject(defaultValue)) - defaultValue = iter(defaultValue).map(function (val) val.map(Option.quote).join(":")).join(","); + defaultValue = iter(defaultValue).map(function (val) val.map(function (v) Option.quote(v, /:/)) + .join(":")) + .join(","); if (isArray(defaultValue)) defaultValue = defaultValue.map(Option.quote).join(","); @@ -446,16 +453,16 @@ var Option = Class("Option", { }, unparseRegexp: function unparseRegexp(re, quoted) re.bang + Option.quote(util.regexp.getSource(re), /^!|:/) + - (typeof re.result === "boolean" ? "" : ":" + (quoted ? re.result : Option.quote(re.result))), + (typeof re.result === "boolean" ? "" : ":" + (quoted ? re.result : Option.quote(re.result, /:/))), parseSite: function parseSite(pattern, result, rest) { if (isArray(rest)) // Called by Array.map result = undefined; let [, bang, filter] = /^(!?)(.*)/.exec(pattern); - filter = Option.dequote(filter); + filter = Option.dequote(filter).trim(); - let quote = this.keepQuotes ? util.identity : Option.quote; + let quote = this.keepQuotes ? util.identity : function (v) Option.quote(v, /:/); return update(Styles.matchFilter(filter), { bang: bang, @@ -491,7 +498,7 @@ var Option = Class("Option", { stringlist: function (vals) vals.map(Option.quote).join(","), - stringmap: function (vals) [Option.quote(k, /:/) + ":" + Option.quote(v) for ([k, v] in Iterator(vals))].join(","), + stringmap: function (vals) [Option.quote(k, /:/) + ":" + Option.quote(v, /:/) for ([k, v] in Iterator(vals))].join(","), regexplist: function (vals) vals.join(","), get regexpmap() this.regexplist, @@ -847,35 +854,38 @@ var Options = Module("options", { function opts(opt) { for (let opt in Iterator(this)) { + if (filter && !filter(opt)) + continue; + if (!(opt.scope & scope)) + continue; + let option = { __proto__: opt, isDefault: opt.isDefault, default: opt.stringDefaultValue, pre: "\u00a0\u00a0", // Unicode nonbreaking space. - value: <> + value: [] }; - if (filter && !filter(opt)) - continue; - if (!(opt.scope & scope)) - continue; - if (opt.type == "boolean") { if (!opt.value) option.pre = "no"; option.default = (opt.defaultValue ? "" : "no") + opt.name; } else if (isArray(opt.value) && opt.type != "charlist") - option.value = <>={template.map(opt.value, - function (v) template.highlight(String(v)), - <>, )}; + option.value = ["", "=", + template.map(opt.value, + function (v) template.highlight(String(v)), + ["", ",", + ["span", { style: "width: 0; display: inline-block" }, " "]])]; else - option.value = <>={template.highlight(opt.stringValue)}; + option.value = ["", "=", template.highlight(opt.stringValue)]; yield option; } }; - modules.commandline.commandOutput(template.options("Options", opts.call(this), this["verbose"] > 0)); + modules.commandline.commandOutput( + template.options("Options", opts.call(this), this["verbose"] > 0)); }, cleanup: function cleanup() { @@ -1061,36 +1071,19 @@ var Options = Module("options", { commands: function initCommands(dactyl, modules, window) { const { commands, contexts, options } = modules; - let args = { - getMode: function (args) findMode(args["-mode"]), - iterate: function (args) { - for (let map in mappings.iterate(this.getMode(args))) - for (let name in values(map.names)) - yield { name: name, __proto__: map }; - }, - format: { - description: function (map) (XML.ignoreWhitespace = false, XML.prettyPrinting = false, <> - {options.get("passkeys").has(map.name) - ? ({ - tempate.linkifyHelp(_("option.passkeys.passedBy")) - }) - : <>} - {template.linkifyHelp(map.description)} - ) - } - }; - dactyl.addUsageCommand({ name: ["listo[ptions]", "lo"], description: "List all options along with their short descriptions", index: "option", iterate: function (args) options, format: { - description: function (opt) (XML.ignoreWhitespace = false, XML.prettyPrinting = false, <> - {opt.scope == Option.SCOPE_LOCAL - ? ({_("option.bufferLocal")}) : ""} - {template.linkifyHelp(opt.description)} - ), + description: function (opt) [ + opt.scope == Option.SCOPE_LOCAL + ? ["span", { highlight: "URLExtra" }, + "(" + _("option.bufferLocal") + ")"] + : "", + template.linkifyHelp(opt.description) + ], help: function (opt) "'" + opt.name + "'" } }); @@ -1302,24 +1295,7 @@ var Options = Module("options", { function fmt(value) (typeof value == "number" ? "#" : typeof value == "function" ? "*" : " ") + value; - if (!args || args == "g:") { - let str = - - { - template.map(globalVariables, function ([i, value]) { - return - - - ; - }) - } -
{i}{fmt(value)}
; - if (str.text().length() == str.*.length()) - dactyl.echomsg(_("variable.none")); - else - dactyl.echo(str, modules.commandline.FORCE_MULTILINE); - return; - } + util.assert(!(!args || args == "g:")); let matches = args.match(/^([a-z]:)?([\w]+)(?:\s*([-+.])?=\s*(.*)?)?$/); if (matches) {